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

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

Issue 29819555: Fix libadblockplus-android tests
Patch Set: Added missing files, removed a whitespace Created Aug. 16, 2018, 12:27 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: adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
diff --git a/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java b/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
index c5523b02a8dfd46c5321865688f09b1c71fe9a13..17efed16c9de6d8e073188a0ff161188d226b680 100644
--- a/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
+++ b/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
@@ -17,6 +17,9 @@
package org.adblockplus.libadblockplus.tests;
+import android.util.Log;
+
+import org.adblockplus.libadblockplus.BaseFilterEngineTest;
import org.adblockplus.libadblockplus.Filter;
import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.MockFilterChangeCallback;
@@ -28,6 +31,8 @@ import java.util.List;
public class FilterEngineTest extends BaseFilterEngineTest
{
+ private static final String TAG = FilterEngineTest.class.getSimpleName();
+
@Test
public void testFilterCreation()
{
@@ -48,7 +53,12 @@ public class FilterEngineTest extends BaseFilterEngineTest
{
while (filterEngine.getListedFilters().size() > 0)
{
+ int prev = filterEngine.getListedFilters().size();
anton 2018/08/24 12:25:04 Can you please explain what's happening here? Is i
René Jeschke 2018/08/27 20:02:15 There was a change in the way subscriptions work i
filterEngine.getListedFilters().get(0).removeFromList();
+ if (prev == filterEngine.getListedFilters().size())
+ {
+ Log.e(TAG, "Failed to clear listed filters.");
+ }
}
assertEquals(0, filterEngine.getListedFilters().size());
@@ -76,11 +86,53 @@ public class FilterEngineTest extends BaseFilterEngineTest
}
@Test
+ public void testAddedSubscriptionIsEnabled()
+ {
+ Subscription subscription = filterEngine.getSubscription("foo");
+ assertFalse(subscription.isDisabled());
+ }
+
+ @Test
+ public void testDisablingSubscriptionDisablesItAndFiresEvent()
+ {
+ Subscription subscription = filterEngine.getSubscription("foo");
+ MockFilterChangeCallback callback = new MockFilterChangeCallback("subscription.disabled", "url","foo");
+ filterEngine.setFilterChangeCallback(callback);
+ assertFalse(subscription.isDisabled());
+ subscription.setDisabled(true);
+ assertEquals(1, callback.getTimesCalled());
+ assertTrue(subscription.isDisabled());
+ filterEngine.removeFilterChangeCallback();
+ }
+
+ @Test
+ public void testEnablingSubscriptionEnablesItAndFiresEvent()
+ {
+ Subscription subscription = filterEngine.getSubscription("foo");
+ assertFalse(subscription.isDisabled());
+ subscription.setDisabled(true);
+ assertTrue(subscription.isDisabled());
+
+ MockFilterChangeCallback callback = new MockFilterChangeCallback("subscription.disabled", "url", "foo");
+ filterEngine.setFilterChangeCallback(callback);
+ subscription.setDisabled(false);
+ assertEquals(1, callback.getTimesCalled());
+ assertFalse(subscription.isDisabled());
+ filterEngine.removeFilterChangeCallback();
+ }
+
+ @Test
public void testAddRemoveSubscriptions()
{
while (filterEngine.getListedSubscriptions().size() > 0)
anton 2018/08/24 12:25:04 copy-paste from above. Can you create separate fun
René Jeschke 2018/08/27 20:02:15 Done.
{
+ int prev = filterEngine.getListedSubscriptions().size();
filterEngine.getListedSubscriptions().get(0).removeFromList();
+ if (prev == filterEngine.getListedSubscriptions().size())
+ {
+ Log.e(TAG, "Failed to clear listed subscriptions.");
+ break;
+ }
}
assertEquals(0, filterEngine.getListedSubscriptions().size());
@@ -324,23 +376,21 @@ public class FilterEngineTest extends BaseFilterEngineTest
}
@Test
- public void testFirstRunFlag()
- {
- assertFalse(filterEngine.isFirstRun());
- }
-
- @Test
public void testSetRemoveFilterChangeCallback()
{
- MockFilterChangeCallback mockFilterChangeCallback = new MockFilterChangeCallback(0);
+ MockFilterChangeCallback callback = new MockFilterChangeCallback("subscription.added", "defaults", "blocking");
- filterEngine.setFilterChangeCallback(mockFilterChangeCallback);
- filterEngine.getFilter("foo").addToList();
- assertEquals(1, mockFilterChangeCallback.getTimesCalled());
+ filterEngine.setFilterChangeCallback(callback);
+ Filter filter = filterEngine.getFilter("foo");
+ assertFalse(filter.isListed());
+ filter.addToList();
+ assertEquals(1, callback.getTimesCalled());
filterEngine.removeFilterChangeCallback();
- filterEngine.getFilter("foo").removeFromList();
- assertEquals(1, mockFilterChangeCallback.getTimesCalled());
+ callback.clearCheckValues();
+ filter.removeFromList();
+ assertFalse(filter.isListed());
+ assertEquals(1, callback.getTimesCalled());
}
@Test

Powered by Google App Engine
This is Rietveld