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

Unified Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.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/UpdateCheckTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java
deleted file mode 100644
index 2aa5c139002e268952c385f8fbd9cac51cb0ed2a..0000000000000000000000000000000000000000
--- a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java
+++ /dev/null
@@ -1,265 +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 org.adblockplus.libadblockplus.AppInfo;
-import org.adblockplus.libadblockplus.EventCallback;
-import org.adblockplus.libadblockplus.HeaderEntry;
-import org.adblockplus.libadblockplus.JsValue;
-import org.adblockplus.libadblockplus.LazyLogSystem;
-import org.adblockplus.libadblockplus.LazyWebRequest;
-import org.adblockplus.libadblockplus.Platform;
-import org.adblockplus.libadblockplus.ServerResponse;
-import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
-
-import org.junit.Test;
-
-import java.util.List;
-
-public class UpdateCheckTest extends BaseFilterEngineTest
-{
- protected String previousRequestUrl;
-
- public class TestWebRequest extends LazyWebRequest
- {
- public ServerResponse response = new ServerResponse();
-
- @Override
- public ServerResponse httpGET(String url, List<HeaderEntry> headers)
- {
- if (url.indexOf("easylist") >= 0)
- {
- return super.httpGET(url, headers);
- }
-
- previousRequestUrl = url;
- return response;
- }
- }
-
- protected AppInfo appInfo;
- protected TestWebRequest webRequest;
-
- protected boolean eventCallbackCalled;
- protected List<JsValue> eventCallbackParams;
- protected boolean updateCallbackCalled;
- protected String updateError;
-
- private EventCallback eventCallback = new EventCallback()
- {
- @Override
- public void eventCallback(List<JsValue> params)
- {
- eventCallbackCalled = true;
- eventCallbackParams = params;
- }
- };
-
- private UpdateCheckDoneCallback updateCallback = new UpdateCheckDoneCallback()
- {
- @Override
- public void updateCheckDoneCallback(String error)
- {
- updateCallbackCalled = true;
- updateError = error;
- }
- };
-
- public void reset() throws InterruptedException
- {
- disposeFilterEngine();
- if (platform != null)
- {
- platform.dispose();
- }
- platform = new Platform(new LazyLogSystem(), webRequest,
- getContext().getFilesDir().getAbsolutePath());
- platform.setUpJsEngine(appInfo);
- platform.getJsEngine().setEventCallback("updateAvailable", eventCallback);
- filterEngine = platform.getFilterEngine();
- }
-
- @Override
- protected void setUp() throws Exception
- {
- appInfo = AppInfo.builder().build();
- webRequest = new TestWebRequest();
- eventCallbackCalled = false;
- updateCallbackCalled = false;
- reset();
- }
-
- public void forceUpdateCheck()
- {
- filterEngine.forceUpdateCheck(updateCallback);
- }
-
- @Test
- public void testRequestFailure() throws InterruptedException
- {
- webRequest.response.setStatus(ServerResponse.NsStatus.ERROR_FAILURE);
-
- appInfo = AppInfo
- .builder()
- .setName("1")
- .setVersion("3")
- .setApplication("4")
- .setApplicationVersion("2")
- .setDevelopmentBuild(false)
- .build();
-
- reset();
- forceUpdateCheck();
-
- Thread.sleep(100);
-
- assertFalse(eventCallbackCalled);
- assertTrue(updateCallbackCalled);
- assertNotNull(updateError);
-
- String expectedUrl = filterEngine.getPref("update_url_release").asString();
- String platform = "libadblockplus";
- String platformVersion = "1.0";
-
- expectedUrl = expectedUrl
- .replaceAll("%NAME%", appInfo.name)
- .replaceAll("%TYPE%", "1"); // manual update
-
- expectedUrl +=
- "&addonName=" + appInfo.name +
- "&addonVersion=" + appInfo.version +
- "&application=" + appInfo.application +
- "&applicationVersion=" + appInfo.applicationVersion +
- "&platform=" + platform +
- "&platformVersion=" + platformVersion +
- "&lastVersion=0&downloadCount=0";
-
- assertEquals(expectedUrl, previousRequestUrl);
- }
-
- @Test
- public void testApplicationUpdateAvailable() throws InterruptedException
- {
- webRequest.response.setStatus(ServerResponse.NsStatus.OK);
- webRequest.response.setResponseStatus(200);
- webRequest.response.setResponse(
- "{\"1/4\": {\"version\":\"3.1\",\"url\":\"https://foo.bar/\"}}");
-
- appInfo = AppInfo
- .builder()
- .setName("1")
- .setVersion("3")
- .setApplication("4")
- .setApplicationVersion("2")
- .setDevelopmentBuild(true)
- .build();
-
- reset();
- forceUpdateCheck();
-
- Thread.sleep(1000);
-
- assertTrue(eventCallbackCalled);
- assertNotNull(eventCallbackParams);
- assertEquals(1l, eventCallbackParams.size());
- assertEquals("https://foo.bar/", eventCallbackParams.get(0).asString());
- assertTrue(updateCallbackCalled);
- assertEquals("", updateError);
- }
-
- @Test
- public void testWrongApplication() throws InterruptedException
- {
- webRequest.response.setStatus(ServerResponse.NsStatus.OK);
- webRequest.response.setResponseStatus(200);
- webRequest.response.setResponse(
- "{\"1/3\": {\"version\":\"3.1\",\"url\":\"https://foo.bar/\"}}");
-
- appInfo = AppInfo
- .builder()
- .setName("1")
- .setVersion("3")
- .setApplication("4")
- .setApplicationVersion("2")
- .setDevelopmentBuild(true)
- .build();
-
- reset();
- forceUpdateCheck();
-
- Thread.sleep(1000);
-
- assertFalse(eventCallbackCalled);
- assertTrue(updateCallbackCalled);
- assertEquals("", updateError);
- }
-
- @Test
- public void testWrongVersion() throws InterruptedException
- {
- webRequest.response.setStatus(ServerResponse.NsStatus.OK);
- webRequest.response.setResponseStatus(200);
- webRequest.response.setResponse(
- "{\"1\": {\"version\":\"3\",\"url\":\"https://foo.bar/\"}}");
-
- appInfo = AppInfo
- .builder()
- .setName("1")
- .setVersion("3")
- .setApplication("4")
- .setApplicationVersion("2")
- .setDevelopmentBuild(true)
- .build();
-
- reset();
- forceUpdateCheck();
-
- Thread.sleep(1000);
-
- assertFalse(eventCallbackCalled);
- assertTrue(updateCallbackCalled);
- assertEquals("", updateError);
- }
-
- @Test
- public void testWrongURL() throws InterruptedException
- {
- webRequest.response.setStatus(ServerResponse.NsStatus.OK);
- webRequest.response.setResponseStatus(200);
- webRequest.response.setResponse(
- "{\"1\": {\"version\":\"3.1\",\"url\":\"http://insecure/\"}}");
-
- appInfo = AppInfo
- .builder()
- .setName("1")
- .setVersion("3")
- .setApplication("4")
- .setApplicationVersion("2")
- .setDevelopmentBuild(true)
- .build();
-
- reset();
- forceUpdateCheck();
-
- Thread.sleep(1000);
-
- assertFalse(eventCallbackCalled);
- assertTrue(updateCallbackCalled);
- assertTrue(updateError.length() > 0);
- }
-}

Powered by Google App Engine
This is Rietveld