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

Side by Side Diff: test/WebRequest.cpp

Issue 29499583: Issue 4938 - fix race conditions related to LazyFileSystem (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 27, 2017, 8: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
« test/FilterEngine.cpp ('K') | « 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 15 matching lines...) Expand all
26 namespace 26 namespace
27 { 27 {
28 class DefaultWebRequestTest : public ::testing::Test 28 class DefaultWebRequestTest : public ::testing::Test
29 { 29 {
30 protected: 30 protected:
31 void SetUp() 31 void SetUp()
32 { 32 {
33 JsEngineCreationParameters jsEngineParams; 33 JsEngineCreationParameters jsEngineParams;
34 jsEngineParams.logSystem = CreateLogSystem(); 34 jsEngineParams.logSystem = CreateLogSystem();
35 jsEngineParams.timer.reset(new NoopTimer()); 35 jsEngineParams.timer.reset(new NoopTimer());
36 jsEngineParams.fileSystem.reset(new LazyFileSystem()); 36 jsEngineParams.fileSystem.reset(fileSystem = new LazyFileSystem());
37 jsEngineParams.webRequest = CreateWebRequest(); 37 jsEngineParams.webRequest = CreateWebRequest();
38 jsEngine = CreateJsEngine(std::move(jsEngineParams)); 38 jsEngine = CreateJsEngine(std::move(jsEngineParams));
39 } 39 }
40 40
41 virtual WebRequestPtr CreateWebRequest() 41 virtual WebRequestPtr CreateWebRequest()
42 { 42 {
43 return CreateDefaultWebRequest(); 43 return CreateDefaultWebRequest();
44 } 44 }
45 45
46 virtual LogSystemPtr CreateLogSystem() 46 virtual LogSystemPtr CreateLogSystem()
47 { 47 {
48 return LogSystemPtr(new ThrowingLogSystem()); 48 return LogSystemPtr(new ThrowingLogSystem());
49 } 49 }
50 50
51 JsEnginePtr jsEngine; 51 JsEnginePtr jsEngine;
52 LazyFileSystem* fileSystem;
52 }; 53 };
53 54
54 class MockWebRequestTest : public DefaultWebRequestTest 55 class MockWebRequestTest : public DefaultWebRequestTest
55 { 56 {
56 virtual WebRequestPtr CreateWebRequest() override 57 virtual WebRequestPtr CreateWebRequest() override
57 { 58 {
58 return DelayedWebRequest::New(webRequestTasks); 59 return DelayedWebRequest::New(webRequestTasks);
59 } 60 }
60 61
61 protected: 62 protected:
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ").AsString()); 172 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ").AsString());
172 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)").AsString()); 173 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)").AsString());
173 #if defined(HAVE_CURL) 174 #if defined(HAVE_CURL)
174 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)").AsString()); 175 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)").AsString());
175 #endif 176 #endif
176 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']").IsUndefined( )); 177 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']").IsUndefined( ));
177 } 178 }
178 179
179 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 180 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
180 { 181 {
181 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); 182 auto filterEngine = CreateFilterEngine(*fileSystem, jsEngine);
182 183
183 ResetTestXHR(jsEngine, "https://easylist-downloads.adblockplus.org/easylist.tx t"); 184 ResetTestXHR(jsEngine, "https://easylist-downloads.adblockplus.org/easylist.tx t");
184 jsEngine->Evaluate("\ 185 jsEngine->Evaluate("\
185 request.setRequestHeader('X', 'Y');\ 186 request.setRequestHeader('X', 'Y');\
186 request.setRequestHeader('X2', 'Y2');\ 187 request.setRequestHeader('X2', 'Y2');\
187 request.send(null);"); 188 request.send(null);");
188 WaitForVariable("result", jsEngine); 189 WaitForVariable("result", jsEngine);
189 ASSERT_EQ(IWebRequest::NS_OK, jsEngine->Evaluate("request.channel.status").AsI nt()); 190 ASSERT_EQ(IWebRequest::NS_OK, jsEngine->Evaluate("request.channel.status").AsI nt());
190 ASSERT_EQ(200, jsEngine->Evaluate("request.status").AsInt()); 191 ASSERT_EQ(200, jsEngine->Evaluate("request.status").AsInt());
191 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)").AsStrin g()); 192 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)").AsStrin g());
192 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)").AsString()); 193 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)").AsString());
193 #if defined(HAVE_CURL) 194 #if defined(HAVE_CURL)
194 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)").AsString()); 195 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)").AsString());
195 #endif 196 #endif
196 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')").IsNull ()); 197 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')").IsNull ());
197 } 198 }
198 #else 199 #else
199 TEST_F(DefaultWebRequestTest, DummyWebRequest) 200 TEST_F(DefaultWebRequestTest, DummyWebRequest)
200 { 201 {
201 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )"); 202 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
202 WaitForVariable("this.foo", jsEngine); 203 WaitForVariable("this.foo", jsEngine);
203 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.status").AsIn t()); 204 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.status").AsIn t());
204 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus").AsInt()); 205 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus").AsInt());
205 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText").AsString()); 206 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText").AsString());
206 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)").AsSt ring()); 207 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)").AsSt ring());
207 } 208 }
208 209
209 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 210 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
210 { 211 {
211 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); 212 auto filterEngine = CreateFilterEngine(*fileSystem, jsEngine);
212 213
213 ResetTestXHR(jsEngine); 214 ResetTestXHR(jsEngine);
214 jsEngine->Evaluate("\ 215 jsEngine->Evaluate("\
215 request.setRequestHeader('X', 'Y');\ 216 request.setRequestHeader('X', 'Y');\
216 request.send(null);"); 217 request.send(null);");
217 WaitForVariable("result", jsEngine); 218 WaitForVariable("result", jsEngine);
218 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("request.channel.s tatus").AsInt()); 219 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("request.channel.s tatus").AsInt());
219 ASSERT_EQ(0, jsEngine->Evaluate("request.status").AsInt()); 220 ASSERT_EQ(0, jsEngine->Evaluate("request.status").AsInt());
220 ASSERT_EQ("error", jsEngine->Evaluate("result").AsString()); 221 ASSERT_EQ("error", jsEngine->Evaluate("result").AsString());
221 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')").Is Null()); 222 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')").Is Null());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 { 258 {
258 return LogSystemPtr(catchLogSystem = new CatchLogSystem()); 259 return LogSystemPtr(catchLogSystem = new CatchLogSystem());
259 } 260 }
260 protected: 261 protected:
261 CatchLogSystem* catchLogSystem; 262 CatchLogSystem* catchLogSystem;
262 }; 263 };
263 } 264 }
264 265
265 TEST_F(MockWebRequestAndLogSystemTest, RequestHeaderValidation) 266 TEST_F(MockWebRequestAndLogSystemTest, RequestHeaderValidation)
266 { 267 {
267 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); 268 auto filterEngine = CreateFilterEngine(*fileSystem, jsEngine);
268 269
269 const std::string msg = "Attempt to set a forbidden header was denied: "; 270 const std::string msg = "Attempt to set a forbidden header was denied: ";
270 271
271 // The test will check that console.warn has been called when the 272 // The test will check that console.warn has been called when the
272 // header is rejected. While this is an implementation detail, we 273 // header is rejected. While this is an implementation detail, we
273 // have no other way to check this 274 // have no other way to check this
274 275
275 // test 'Accept-Encoding' is rejected 276 // test 'Accept-Encoding' is rejected
276 catchLogSystem->clear(); 277 catchLogSystem->clear();
277 std::string url = ResetTestXHR(jsEngine); 278 std::string url = ResetTestXHR(jsEngine);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l); 356 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l);
356 EXPECT_EQ("", catchLogSystem->lastMessage); 357 EXPECT_EQ("", catchLogSystem->lastMessage);
357 ProcessPendingWebRequests(); 358 ProcessPendingWebRequests();
358 { 359 {
359 auto headersRequest = GetHeadersForRequest(url); 360 auto headersRequest = GetHeadersForRequest(url);
360 EXPECT_TRUE(headersRequest.first); 361 EXPECT_TRUE(headersRequest.first);
361 const auto& headers = headersRequest.second; 362 const auto& headers = headersRequest.second;
362 EXPECT_FALSE(headers.cend() == headers.find("Security")); 363 EXPECT_FALSE(headers.cend() == headers.find("Security"));
363 } 364 }
364 } 365 }
OLDNEW
« test/FilterEngine.cpp ('K') | « test/UpdateCheck.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld