Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java

Issue 29435584: Issue 4181 - Fix FilterEngineTest tests (Closed)
Patch Set: Created May 10, 2017, 10:56 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 544fcb741ad70fafab905f8f2b04a6de673ecda8..56c1431e8c6341b319dafe6c23d3f36cb958a5db 100644
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java
@@ -18,16 +18,26 @@
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.content.Context;
import android.test.InstrumentationTestCase;
+import java.io.File;
+
public abstract class BaseJsTest extends InstrumentationTestCase
{
protected JsEngine jsEngine;
+ protected File tmpFileSystemPath;
+
+ protected File buildTmpFileSystemPath()
+ {
+ File tmpFileSystemPath = FileSystemUtils.generateUniqueFile(null, ".fs", getContext().getCacheDir());
+ tmpFileSystemPath.mkdirs();
+ return tmpFileSystemPath;
+ }
@Override
protected void setUp() throws Exception
@@ -36,10 +46,30 @@ public abstract class BaseJsTest extends InstrumentationTestCase
jsEngine = new JsEngine(AppInfo.builder().build());
jsEngine.setDefaultLogSystem();
- jsEngine.setDefaultFileSystem(getContext().getFilesDir().getAbsolutePath());
+
+ // 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);
+ tmpFileSystemPath = null;
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ cleanupFileSystem();
+ super.tearDown();
+ }
+
protected Context getContext()
{
return getInstrumentation().getTargetContext();

Powered by Google App Engine
This is Rietveld