| Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
| diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
| index 85e983996ce91431cebf2ce8ab78270c298c485a..130759b7cc299e1739a3c03a9d94c460172f93a3 100644 |
| --- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
| +++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java |
| @@ -18,24 +18,56 @@ |
| package org.adblockplus.libadblockplus.tests; |
| import org.adblockplus.libadblockplus.AppInfo; |
| +import org.adblockplus.libadblockplus.FileSystemUtils; |
| import org.adblockplus.libadblockplus.JsEngine; |
| -import org.adblockplus.libadblockplus.LazyLogSystem; |
| import org.adblockplus.libadblockplus.ThrowingWebRequest; |
| import android.test.AndroidTestCase; |
| +import java.io.File; |
| +import java.io.IOException; |
| + |
| public abstract class BaseJsTest extends AndroidTestCase |
| { |
| - protected JsEngine jsEngine; |
| + protected JsEngine jsEngine; |
| + protected File tmpFileSystemPath; |
| + |
| + protected File buildTmpFileSystemPath() throws IOException |
| + { |
| + File tmpFileSystemPath = FileSystemUtils |
| + .generateUniqueFile(null, ".fs", getContext().getCacheDir()); |
| + tmpFileSystemPath.mkdirs(); |
| + return tmpFileSystemPath; |
| + } |
| - @Override |
| - protected void setUp() throws Exception |
| - { |
| - super.setUp(); |
| + @Override |
| + protected void setUp() throws Exception |
| + { |
| + super.setUp(); |
| + |
| + jsEngine = new JsEngine(AppInfo.builder().build()); |
| + jsEngine.setDefaultLogSystem(); |
| - jsEngine = new JsEngine(AppInfo.builder().build()); |
| - jsEngine.setDefaultLogSystem(); |
| - jsEngine.setDefaultFileSystem(getContext().getFilesDir().getAbsolutePath()); |
| - jsEngine.setWebRequest(new ThrowingWebRequest()); |
| + // we need to generate new file system path in order |
| + // not to have JsEngine state from the previous test |
| + tmpFileSystemPath = buildTmpFileSystemPath(); |
| + jsEngine.setDefaultFileSystem(tmpFileSystemPath.getAbsolutePath()); |
| + jsEngine.setWebRequest(new ThrowingWebRequest()); |
| + } |
| + |
| + protected void cleanupFileSystem() |
| + { |
| + if (tmpFileSystemPath != null && tmpFileSystemPath.exists()) |
| + { |
| + FileSystemUtils.delete(tmpFileSystemPath, true); |
| + tmpFileSystemPath = null; |
| } |
| + } |
| + |
| + @Override |
| + protected void tearDown() throws Exception |
| + { |
| + cleanupFileSystem(); |
| + super.tearDown(); |
| + } |
| } |