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

Side by Side Diff: test/UpdateCheck.cpp

Issue 29428650: Issue 5180 - introduce asynchronous web request (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 3, 2017, 2:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/Notification.cpp ('k') | test/WebRequest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void UpdateCallback(const std::string& error) 94 void UpdateCallback(const std::string& error)
95 { 95 {
96 updateCallbackCalled = true; 96 updateCallbackCalled = true;
97 updateError = error; 97 updateError = error;
98 } 98 }
99 }; 99 };
100 } 100 }
101 101
102 TEST_F(UpdateCheckTest, RequestFailure) 102 TEST_F(UpdateCheckTest, RequestFailure)
103 { 103 {
104 webRequest->response.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; 104 webRequest->response.status = IWebRequest::NS_ERROR_FAILURE;
105 105
106 appInfo.name = "1"; 106 appInfo.name = "1";
107 appInfo.version = "3"; 107 appInfo.version = "3";
108 appInfo.application = "4"; 108 appInfo.application = "4";
109 appInfo.applicationVersion = "2"; 109 appInfo.applicationVersion = "2";
110 appInfo.developmentBuild = false; 110 appInfo.developmentBuild = false;
111 111
112 Reset(); 112 Reset();
113 ForceUpdateCheck(); 113 ForceUpdateCheck();
114 114
(...skipping 14 matching lines...) Expand all
129 "&application=" + appInfo.application + 129 "&application=" + appInfo.application +
130 "&applicationVersion=" + appInfo.applicationVersion + 130 "&applicationVersion=" + appInfo.applicationVersion +
131 "&platform=" + platform + 131 "&platform=" + platform +
132 "&platformVersion=" + platformVersion + 132 "&platformVersion=" + platformVersion +
133 "&lastVersion=0&downloadCount=0"; 133 "&lastVersion=0&downloadCount=0";
134 ASSERT_EQ(expectedUrl, previousRequestUrl); 134 ASSERT_EQ(expectedUrl, previousRequestUrl);
135 } 135 }
136 136
137 TEST_F(UpdateCheckTest, UpdateAvailable) 137 TEST_F(UpdateCheckTest, UpdateAvailable)
138 { 138 {
139 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; 139 webRequest->response.status = IWebRequest::NS_OK;
140 webRequest->response.responseStatus = 200; 140 webRequest->response.responseStatus = 200;
141 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht tps://foo.bar/\"}}"; 141 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht tps://foo.bar/\"}}";
142 142
143 appInfo.name = "1"; 143 appInfo.name = "1";
144 appInfo.version = "3"; 144 appInfo.version = "3";
145 appInfo.application = "4"; 145 appInfo.application = "4";
146 appInfo.applicationVersion = "2"; 146 appInfo.applicationVersion = "2";
147 appInfo.developmentBuild = true; 147 appInfo.developmentBuild = true;
148 148
149 Reset(); 149 Reset();
(...skipping 18 matching lines...) Expand all
168 "&application=" + appInfo.application + 168 "&application=" + appInfo.application +
169 "&applicationVersion=" + appInfo.applicationVersion + 169 "&applicationVersion=" + appInfo.applicationVersion +
170 "&platform=" + platform + 170 "&platform=" + platform +
171 "&platformVersion=" + platformVersion + 171 "&platformVersion=" + platformVersion +
172 "&lastVersion=0&downloadCount=0"; 172 "&lastVersion=0&downloadCount=0";
173 ASSERT_EQ(expectedUrl, previousRequestUrl); 173 ASSERT_EQ(expectedUrl, previousRequestUrl);
174 } 174 }
175 175
176 TEST_F(UpdateCheckTest, ApplicationUpdateAvailable) 176 TEST_F(UpdateCheckTest, ApplicationUpdateAvailable)
177 { 177 {
178 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; 178 webRequest->response.status = IWebRequest::NS_OK;
179 webRequest->response.responseStatus = 200; 179 webRequest->response.responseStatus = 200;
180 webRequest->response.responseText = "{\"1/4\": {\"version\":\"3.1\",\"url\":\" https://foo.bar/\"}}"; 180 webRequest->response.responseText = "{\"1/4\": {\"version\":\"3.1\",\"url\":\" https://foo.bar/\"}}";
181 181
182 appInfo.name = "1"; 182 appInfo.name = "1";
183 appInfo.version = "3"; 183 appInfo.version = "3";
184 appInfo.application = "4"; 184 appInfo.application = "4";
185 appInfo.applicationVersion = "2"; 185 appInfo.applicationVersion = "2";
186 appInfo.developmentBuild = true; 186 appInfo.developmentBuild = true;
187 187
188 Reset(); 188 Reset();
189 ForceUpdateCheck(); 189 ForceUpdateCheck();
190 190
191 AdblockPlus::Sleep(100); 191 AdblockPlus::Sleep(100);
192 192
193 ASSERT_TRUE(eventCallbackCalled); 193 ASSERT_TRUE(eventCallbackCalled);
194 ASSERT_EQ(1u, eventCallbackParams.size()); 194 ASSERT_EQ(1u, eventCallbackParams.size());
195 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); 195 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString());
196 ASSERT_TRUE(updateCallbackCalled); 196 ASSERT_TRUE(updateCallbackCalled);
197 ASSERT_TRUE(updateError.empty()); 197 ASSERT_TRUE(updateError.empty());
198 } 198 }
199 199
200 TEST_F(UpdateCheckTest, WrongApplication) 200 TEST_F(UpdateCheckTest, WrongApplication)
201 { 201 {
202 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; 202 webRequest->response.status = IWebRequest::NS_OK;
203 webRequest->response.responseStatus = 200; 203 webRequest->response.responseStatus = 200;
204 webRequest->response.responseText = "{\"1/3\": {\"version\":\"3.1\",\"url\":\" https://foo.bar/\"}}"; 204 webRequest->response.responseText = "{\"1/3\": {\"version\":\"3.1\",\"url\":\" https://foo.bar/\"}}";
205 205
206 appInfo.name = "1"; 206 appInfo.name = "1";
207 appInfo.version = "3"; 207 appInfo.version = "3";
208 appInfo.application = "4"; 208 appInfo.application = "4";
209 appInfo.applicationVersion = "2"; 209 appInfo.applicationVersion = "2";
210 appInfo.developmentBuild = true; 210 appInfo.developmentBuild = true;
211 211
212 Reset(); 212 Reset();
213 ForceUpdateCheck(); 213 ForceUpdateCheck();
214 214
215 AdblockPlus::Sleep(100); 215 AdblockPlus::Sleep(100);
216 216
217 ASSERT_FALSE(eventCallbackCalled); 217 ASSERT_FALSE(eventCallbackCalled);
218 ASSERT_TRUE(updateCallbackCalled); 218 ASSERT_TRUE(updateCallbackCalled);
219 ASSERT_TRUE(updateError.empty()); 219 ASSERT_TRUE(updateError.empty());
220 } 220 }
221 221
222 TEST_F(UpdateCheckTest, WrongVersion) 222 TEST_F(UpdateCheckTest, WrongVersion)
223 { 223 {
224 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; 224 webRequest->response.status = IWebRequest::NS_OK;
225 webRequest->response.responseStatus = 200; 225 webRequest->response.responseStatus = 200;
226 webRequest->response.responseText = "{\"1\": {\"version\":\"3\",\"url\":\"http s://foo.bar/\"}}"; 226 webRequest->response.responseText = "{\"1\": {\"version\":\"3\",\"url\":\"http s://foo.bar/\"}}";
227 227
228 appInfo.name = "1"; 228 appInfo.name = "1";
229 appInfo.version = "3"; 229 appInfo.version = "3";
230 appInfo.application = "4"; 230 appInfo.application = "4";
231 appInfo.applicationVersion = "2"; 231 appInfo.applicationVersion = "2";
232 appInfo.developmentBuild = true; 232 appInfo.developmentBuild = true;
233 233
234 Reset(); 234 Reset();
235 ForceUpdateCheck(); 235 ForceUpdateCheck();
236 236
237 AdblockPlus::Sleep(100); 237 AdblockPlus::Sleep(100);
238 238
239 ASSERT_FALSE(eventCallbackCalled); 239 ASSERT_FALSE(eventCallbackCalled);
240 ASSERT_TRUE(updateCallbackCalled); 240 ASSERT_TRUE(updateCallbackCalled);
241 ASSERT_TRUE(updateError.empty()); 241 ASSERT_TRUE(updateError.empty());
242 } 242 }
243 243
244 TEST_F(UpdateCheckTest, WrongURL) 244 TEST_F(UpdateCheckTest, WrongURL)
245 { 245 {
246 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; 246 webRequest->response.status = IWebRequest::NS_OK;
247 webRequest->response.responseStatus = 200; 247 webRequest->response.responseStatus = 200;
248 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht tp://insecure/\"}}"; 248 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht tp://insecure/\"}}";
249 249
250 appInfo.name = "1"; 250 appInfo.name = "1";
251 appInfo.version = "3"; 251 appInfo.version = "3";
252 appInfo.application = "4"; 252 appInfo.application = "4";
253 appInfo.applicationVersion = "2"; 253 appInfo.applicationVersion = "2";
254 appInfo.developmentBuild = true; 254 appInfo.developmentBuild = true;
255 255
256 Reset(); 256 Reset();
257 ForceUpdateCheck(); 257 ForceUpdateCheck();
258 258
259 AdblockPlus::Sleep(100); 259 AdblockPlus::Sleep(100);
260 260
261 ASSERT_FALSE(eventCallbackCalled); 261 ASSERT_FALSE(eventCallbackCalled);
262 ASSERT_TRUE(updateCallbackCalled); 262 ASSERT_TRUE(updateCallbackCalled);
263 ASSERT_FALSE(updateError.empty()); 263 ASSERT_FALSE(updateError.empty());
264 } 264 }
OLDNEW
« no previous file with comments | « test/Notification.cpp ('k') | test/WebRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld