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

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

Issue 29678581: Issue 6000 - Rename "libadblockplus-android" (Closed)
Patch Set: addressed comments Created Jan. 29, 2018, 11:04 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/IsAllowedConnectionCallbackTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java
deleted file mode 100644
index 49af1316e0f7a9b73d612212a7f8a831d00fc0fb..0000000000000000000000000000000000000000
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackTest.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-present eyeo GmbH
- *
- * Adblock Plus is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * Adblock Plus is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * 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 android.os.SystemClock;
-
-import org.adblockplus.libadblockplus.HeaderEntry;
-import org.adblockplus.libadblockplus.IsAllowedConnectionCallback;
-import org.adblockplus.libadblockplus.Platform;
-import org.adblockplus.libadblockplus.ServerResponse;
-import org.adblockplus.libadblockplus.Subscription;
-import org.adblockplus.libadblockplus.WebRequest;
-import org.adblockplus.libadblockplus.android.AndroidWebRequest;
-import org.junit.Test;
-
-import java.util.LinkedList;
-import java.util.List;
-
-public class IsAllowedConnectionCallbackTest extends BaseFilterEngineTest
-{
- private static final int UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS = 5 * 1000; // 5s
-
- private static final class TestRequest extends AndroidWebRequest
- {
- private List<String> urls = new LinkedList<String>();
-
- public List<String> getUrls()
- {
- return urls;
- }
-
- @Override
- public ServerResponse httpGET(String url, List<HeaderEntry> headers)
- {
- urls.add(url);
- return super.httpGET(url, headers);
- }
- }
-
- private static final class TestCallback implements IsAllowedConnectionCallback
- {
- private boolean result;
- private boolean invoked;
- private String connectionType;
-
- public boolean isResult()
- {
- return result;
- }
-
- public void setResult(boolean result)
- {
- this.result = result;
- }
-
- public String getConnectionType()
- {
- return connectionType;
- }
-
- public boolean isInvoked()
- {
- return invoked;
- }
-
- @Override
- public boolean isConnectionAllowed(String connectionType)
- {
- this.invoked = true;
- this.connectionType = connectionType;
-
- return result;
- }
- }
-
- private TestRequest request;
- private TestCallback callback;
-
- @Override
- protected void setUp() throws Exception
- {
- platform = new Platform(createLogSystem(), createWebRequest(),
- getContext().getFilesDir().getAbsolutePath());
- callback = new TestCallback();
- platform.setUpFilterEngine(callback);
- filterEngine = platform.getFilterEngine();
- }
-
- @Override
- protected WebRequest createWebRequest()
- {
- return request = new TestRequest();
- }
-
- private void updateSubscriptions()
- {
- for (final Subscription s : this.filterEngine.getListedSubscriptions())
- {
- try
- {
- s.updateFilters();
- }
- finally
- {
- s.dispose();
- }
- }
- }
-
- @Test
- public void testAllow()
- {
- final String allowedConnectionType = "wifi1";
- filterEngine.setAllowedConnectionType(allowedConnectionType);
- callback.setResult(true);
-
- assertEquals(0, request.getUrls().size());
- assertFalse(callback.isInvoked());
-
- updateSubscriptions();
- SystemClock.sleep(UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS);
-
- assertTrue(callback.isInvoked());
- assertNotNull(callback.getConnectionType());
- assertEquals(allowedConnectionType, callback.getConnectionType());
-
- assertTrue(request.getUrls().size() > 0);
- }
-
- @Test
- public void testDeny()
- {
- final String allowedConnectionType = "wifi2";
- filterEngine.setAllowedConnectionType(allowedConnectionType);
-
- callback.setResult(false);
- assertEquals(0, request.getUrls().size());
-
- updateSubscriptions();
- SystemClock.sleep(UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS);
-
- assertTrue(callback.isInvoked());
- assertNotNull(callback.getConnectionType());
- assertEquals(allowedConnectionType, callback.getConnectionType());
-
- assertEquals(0, request.getUrls().size());
- }
-}

Powered by Google App Engine
This is Rietveld