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

Side by Side Diff: test/WebRequest.cpp

Issue 29508555: Issue 5450 - move FilterEngine into Platform (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: fix typos Created Aug. 7, 2017, 1:03 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/UpdateCheck.cpp ('k') | no next file » | 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ").AsString()); 183 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ").AsString());
184 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)").AsString()); 184 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)").AsString());
185 #if defined(HAVE_CURL) 185 #if defined(HAVE_CURL)
186 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)").AsString()); 186 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)").AsString());
187 #endif 187 #endif
188 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']").IsUndefined( )); 188 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']").IsUndefined( ));
189 } 189 }
190 190
191 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 191 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
192 { 192 {
193 auto filterEngine = CreateFilterEngine(*fileSystem, jsEngine); 193 auto filterEngine = CreateFilterEngine(*fileSystem, *platform);
194 194
195 ResetTestXHR(jsEngine, "https://easylist-downloads.adblockplus.org/easylist.tx t"); 195 ResetTestXHR(jsEngine, "https://easylist-downloads.adblockplus.org/easylist.tx t");
196 jsEngine->Evaluate("\ 196 jsEngine->Evaluate("\
197 request.setRequestHeader('X', 'Y');\ 197 request.setRequestHeader('X', 'Y');\
198 request.setRequestHeader('X2', 'Y2');\ 198 request.setRequestHeader('X2', 'Y2');\
199 request.send(null);"); 199 request.send(null);");
200 WaitForVariable("result", jsEngine); 200 WaitForVariable("result", jsEngine);
201 ASSERT_EQ(IWebRequest::NS_OK, jsEngine->Evaluate("request.channel.status").AsI nt()); 201 ASSERT_EQ(IWebRequest::NS_OK, jsEngine->Evaluate("request.channel.status").AsI nt());
202 ASSERT_EQ(200, jsEngine->Evaluate("request.status").AsInt()); 202 ASSERT_EQ(200, jsEngine->Evaluate("request.status").AsInt());
203 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)").AsStrin g()); 203 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)").AsStrin g());
204 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)").AsString()); 204 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)").AsString());
205 #if defined(HAVE_CURL) 205 #if defined(HAVE_CURL)
206 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)").AsString()); 206 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)").AsString());
207 #endif 207 #endif
208 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')").IsNull ()); 208 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')").IsNull ());
209 } 209 }
210 #else 210 #else
211 TEST_F(DefaultWebRequestTest, DummyWebRequest) 211 TEST_F(DefaultWebRequestTest, DummyWebRequest)
212 { 212 {
213 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )"); 213 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
214 WaitForVariable("this.foo", jsEngine); 214 WaitForVariable("this.foo", jsEngine);
215 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.status").AsIn t()); 215 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.status").AsIn t());
216 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus").AsInt()); 216 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus").AsInt());
217 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText").AsString()); 217 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText").AsString());
218 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)").AsSt ring()); 218 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)").AsSt ring());
219 } 219 }
220 220
221 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 221 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
222 { 222 {
223 auto filterEngine = CreateFilterEngine(*fileSystem, jsEngine); 223 auto filterEngine = CreateFilterEngine(*fileSystem, *platform);
224 224
225 ResetTestXHR(jsEngine); 225 ResetTestXHR(jsEngine);
226 jsEngine->Evaluate("\ 226 jsEngine->Evaluate("\
227 request.setRequestHeader('X', 'Y');\ 227 request.setRequestHeader('X', 'Y');\
228 request.send(null);"); 228 request.send(null);");
229 WaitForVariable("result", jsEngine); 229 WaitForVariable("result", jsEngine);
230 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("request.channel.s tatus").AsInt()); 230 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("request.channel.s tatus").AsInt());
231 ASSERT_EQ(0, jsEngine->Evaluate("request.status").AsInt()); 231 ASSERT_EQ(0, jsEngine->Evaluate("request.status").AsInt());
232 ASSERT_EQ("error", jsEngine->Evaluate("result").AsString()); 232 ASSERT_EQ("error", jsEngine->Evaluate("result").AsString());
233 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')").Is Null()); 233 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')").Is Null());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 { 269 {
270 return LogSystemPtr(catchLogSystem = new CatchLogSystem()); 270 return LogSystemPtr(catchLogSystem = new CatchLogSystem());
271 } 271 }
272 protected: 272 protected:
273 CatchLogSystem* catchLogSystem; 273 CatchLogSystem* catchLogSystem;
274 }; 274 };
275 } 275 }
276 276
277 TEST_F(MockWebRequestAndLogSystemTest, RequestHeaderValidation) 277 TEST_F(MockWebRequestAndLogSystemTest, RequestHeaderValidation)
278 { 278 {
279 auto filterEngine = CreateFilterEngine(*fileSystem, jsEngine); 279 auto filterEngine = CreateFilterEngine(*fileSystem, *platform);
280 280
281 const std::string msg = "Attempt to set a forbidden header was denied: "; 281 const std::string msg = "Attempt to set a forbidden header was denied: ";
282 282
283 // The test will check that console.warn has been called when the 283 // The test will check that console.warn has been called when the
284 // header is rejected. While this is an implementation detail, we 284 // header is rejected. While this is an implementation detail, we
285 // have no other way to check this 285 // have no other way to check this
286 286
287 // test 'Accept-Encoding' is rejected 287 // test 'Accept-Encoding' is rejected
288 catchLogSystem->clear(); 288 catchLogSystem->clear();
289 std::string url = ResetTestXHR(jsEngine); 289 std::string url = ResetTestXHR(jsEngine);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l); 367 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l);
368 EXPECT_EQ("", catchLogSystem->lastMessage); 368 EXPECT_EQ("", catchLogSystem->lastMessage);
369 ProcessPendingWebRequests(); 369 ProcessPendingWebRequests();
370 { 370 {
371 auto headersRequest = GetHeadersForRequest(url); 371 auto headersRequest = GetHeadersForRequest(url);
372 EXPECT_TRUE(headersRequest.first); 372 EXPECT_TRUE(headersRequest.first);
373 const auto& headers = headersRequest.second; 373 const auto& headers = headersRequest.second;
374 EXPECT_FALSE(headers.cend() == headers.find("Security")); 374 EXPECT_FALSE(headers.cend() == headers.find("Security"));
375 } 375 }
376 } 376 }
OLDNEW
« no previous file with comments | « test/UpdateCheck.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld