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

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

Issue 29347192: Issue 4181 - Fix FilterEngineTest tests (Closed)
Patch Set: Created July 1, 2016, 1:41 p.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
===================================================================
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/BaseJsTest.java
@@ -13,29 +13,62 @@
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.adblockplus.libadblockplus.tests;
import org.adblockplus.libadblockplus.AppInfo;
+import org.adblockplus.libadblockplus.FileSystemHelper;
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 File tmpFileSystemPath;
+ protected FileSystemHelper fileSystemHelper = new FileSystemHelper();
+
+ protected File buildTmpFileSystemPath() throws IOException
+ {
+ File tmpFileSystemPath = fileSystemHelper
+ .generateUniqueFileName(null, ".fs", getContext().getCacheDir());
+ tmpFileSystemPath.mkdirs();
+ return tmpFileSystemPath;
+ }
@Override
protected void setUp() throws Exception
{
super.setUp();
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())
+ {
+ fileSystemHelper.delete(tmpFileSystemPath, true);
+ tmpFileSystemPath = null;
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ cleanupFileSystem();
+ super.tearDown();
+ }
}

Powered by Google App Engine
This is Rietveld