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

Side by Side Diff: adblock-android-tests/src/org/adblockplus/libadblockplus/tests/UpdateCheckTest.java

Issue 29908555: Issue 7035 - Update libadblockplus dependency (Closed) Base URL: git@github.com:adblockplus/libadblockplus-android.git@d150f08d5d72de8938c7ebbdccd9b0c4e06b4070
Patch Set: Issue 7035 - Update libadblockplus dependency Created Oct. 15, 2018, 9:53 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 13 matching lines...) Expand all
24 import org.adblockplus.libadblockplus.LazyLogSystem; 24 import org.adblockplus.libadblockplus.LazyLogSystem;
25 import org.adblockplus.libadblockplus.LazyWebRequest; 25 import org.adblockplus.libadblockplus.LazyWebRequest;
26 import org.adblockplus.libadblockplus.Platform; 26 import org.adblockplus.libadblockplus.Platform;
27 import org.adblockplus.libadblockplus.ServerResponse; 27 import org.adblockplus.libadblockplus.ServerResponse;
28 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; 28 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback;
29 29
30 import org.junit.Test; 30 import org.junit.Test;
31 31
32 import java.util.List; 32 import java.util.List;
33 33
34 public class UpdateCheckTest extends BaseFilterEngineTest 34 public class UpdateCheckTest extends BaseUpdaterTest
35 { 35 {
36 protected String previousRequestUrl; 36 protected String previousRequestUrl;
37 37
38 public class TestWebRequest extends LazyWebRequest 38 public class TestWebRequest extends LazyWebRequest
39 { 39 {
40 public ServerResponse response = new ServerResponse(); 40 public ServerResponse response = new ServerResponse();
41 41
42 @Override 42 @Override
43 public ServerResponse httpGET(String url, List<HeaderEntry> headers) 43 public ServerResponse httpGET(String url, List<HeaderEntry> headers)
44 { 44 {
(...skipping 30 matching lines...) Expand all
75 @Override 75 @Override
76 public void updateCheckDoneCallback(String error) 76 public void updateCheckDoneCallback(String error)
77 { 77 {
78 updateCallbackCalled = true; 78 updateCallbackCalled = true;
79 updateError = error; 79 updateError = error;
80 } 80 }
81 }; 81 };
82 82
83 public void reset() throws InterruptedException 83 public void reset() throws InterruptedException
84 { 84 {
85 disposeFilterEngine(); 85 disposeUpdater();
86 if (platform != null) 86 if (platform != null)
87 { 87 {
88 platform.dispose(); 88 platform.dispose();
89 } 89 }
90 platform = new Platform(new LazyLogSystem(), webRequest, 90 platform = new Platform(new LazyLogSystem(), webRequest,
91 getContext().getFilesDir().getAbsolutePath()); 91 getContext().getFilesDir().getAbsolutePath());
92 platform.setUpJsEngine(appInfo); 92 platform.setUpJsEngine(appInfo);
93 platform.getJsEngine().setEventCallback("updateAvailable", eventCallback); 93 platform.getJsEngine().setEventCallback("updateAvailable", eventCallback);
94 filterEngine = platform.getFilterEngine(); 94 updater = platform.getUpdater();
95 } 95 }
96 96
97 @Override 97 @Override
98 protected void setUp() throws Exception 98 protected void setUp() throws Exception
99 { 99 {
100 appInfo = AppInfo.builder().build(); 100 appInfo = AppInfo.builder().build();
101 webRequest = new TestWebRequest(); 101 webRequest = new TestWebRequest();
102 eventCallbackCalled = false; 102 eventCallbackCalled = false;
103 updateCallbackCalled = false; 103 updateCallbackCalled = false;
104 reset(); 104 reset();
105 } 105 }
106 106
107 public void forceUpdateCheck() 107 public void forceUpdateCheck()
108 { 108 {
109 filterEngine.forceUpdateCheck(updateCallback); 109 updater.forceUpdateCheck(updateCallback);
110 } 110 }
111 111
112 @Test 112 @Test
113 public void testRequestFailure() throws InterruptedException 113 public void testRequestFailure() throws InterruptedException
114 { 114 {
115 webRequest.response.setStatus(ServerResponse.NsStatus.ERROR_FAILURE); 115 webRequest.response.setStatus(ServerResponse.NsStatus.ERROR_FAILURE);
116 116
117 appInfo = AppInfo 117 appInfo = AppInfo
118 .builder() 118 .builder()
119 .setName("1") 119 .setName("1")
120 .setVersion("3") 120 .setVersion("3")
121 .setApplication("4") 121 .setApplication("4")
122 .setApplicationVersion("2") 122 .setApplicationVersion("2")
123 .setDevelopmentBuild(false) 123 .setDevelopmentBuild(false)
124 .build(); 124 .build();
125 125
126 reset(); 126 reset();
127 forceUpdateCheck(); 127 forceUpdateCheck();
128 128
129 Thread.sleep(100); 129 Thread.sleep(100);
130 130
131 assertFalse(eventCallbackCalled); 131 assertFalse(eventCallbackCalled);
132 assertTrue(updateCallbackCalled); 132 assertTrue(updateCallbackCalled);
133 assertNotNull(updateError); 133 assertNotNull(updateError);
134 134
135 String expectedUrl = filterEngine.getPref("update_url_release").asString(); 135 String expectedUrl = updater.getPref("update_url_release").asString();
136 String platform = "libadblockplus"; 136 String platform = "libadblockplus";
137 String platformVersion = "1.0"; 137 String platformVersion = "1.0";
138 138
139 expectedUrl = expectedUrl 139 expectedUrl = expectedUrl
140 .replaceAll("%NAME%", appInfo.name) 140 .replaceAll("%NAME%", appInfo.name)
141 .replaceAll("%TYPE%", "1"); // manual update 141 .replaceAll("%TYPE%", "1"); // manual update
142 142
143 expectedUrl += 143 expectedUrl +=
144 "&addonName=" + appInfo.name + 144 "&addonName=" + appInfo.name +
145 "&addonVersion=" + appInfo.version + 145 "&addonVersion=" + appInfo.version +
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 reset(); 256 reset();
257 forceUpdateCheck(); 257 forceUpdateCheck();
258 258
259 Thread.sleep(1000); 259 Thread.sleep(1000);
260 260
261 assertFalse(eventCallbackCalled); 261 assertFalse(eventCallbackCalled);
262 assertTrue(updateCallbackCalled); 262 assertTrue(updateCallbackCalled);
263 assertTrue(updateError.length() > 0); 263 assertTrue(updateError.length() > 0);
264 } 264 }
265 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld