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

Delta Between Two Patch Sets: test/WebRequest.cpp

Issue 29408721: Issue 5002 - Fix potential concurrency issues in WebRequest tests. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Avoid casting the webRequest pointer. Created April 19, 2017, 2:40 p.m.
Right Patch Set: Fixed the last nits. Created April 19, 2017, 2:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 mutable std::map<std::string, std::set<std::string>> requestHeaderNames; 76 mutable std::map<std::string, std::set<std::string>> requestHeaderNames;
77 }; 77 };
78 78
79 template<class T> 79 template<class T>
80 class WebRequestTest : public BaseJsTest 80 class WebRequestTest : public BaseJsTest
81 { 81 {
82 protected: 82 protected:
83 void SetUp() 83 void SetUp()
84 { 84 {
85 BaseJsTest::SetUp(); 85 BaseJsTest::SetUp();
86 webRequest = std::shared_ptr<T>(new T()); 86 webRequest = std::make_shared<T>();
sergei 2017/04/19 14:44:47 std::make_shared are usually preferable, though he
hub 2017/04/19 14:55:06 let's make it right.
87 jsEngine->SetWebRequest(webRequest); 87 jsEngine->SetWebRequest(webRequest);
88 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); 88 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem()));
89 } 89 }
90 90
91 std::shared_ptr<T> webRequest; 91 std::shared_ptr<T> webRequest;
92 }; 92 };
93 93
94 typedef WebRequestTest<MockWebRequest> MockWebRequestTest; 94 typedef WebRequestTest<MockWebRequest> MockWebRequestTest;
95 typedef WebRequestTest<AdblockPlus::DefaultWebRequest> DefaultWebRequestTest; 95 typedef WebRequestTest<AdblockPlus::DefaultWebRequest> DefaultWebRequestTest;
96 typedef WebRequestTest<MockWebRequest> XMLHttpRequestTest; 96 typedef WebRequestTest<MockWebRequest> XMLHttpRequestTest;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr; 244 typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr;
245 } 245 }
246 246
247 TEST_F(XMLHttpRequestTest, RequestHeaderValidation) 247 TEST_F(XMLHttpRequestTest, RequestHeaderValidation)
248 { 248 {
249 auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem()); 249 auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem());
250 jsEngine->SetLogSystem(catchLogSystem); 250 jsEngine->SetLogSystem(catchLogSystem);
251 251
252 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); 252 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
253 253
254 ASSERT_TRUE(webRequest);
sergei 2017/04/19 14:44:47 I'm not sure whether we need it.
hub 2017/04/19 14:55:06 I'm probably being paranoid. Even before I'm sure
255
256 const std::string msg = "Attempt to set a forbidden header was denied: "; 254 const std::string msg = "Attempt to set a forbidden header was denied: ";
257 255
258 // The test will check that console.warn has been called when the 256 // The test will check that console.warn has been called when the
259 // header is rejected. While this is an implementation detail, we 257 // header is rejected. While this is an implementation detail, we
260 // have no other way to check this 258 // have no other way to check this
261 259
262 // test 'Accept-Encoding' is rejected 260 // test 'Accept-Encoding' is rejected
263 catchLogSystem->clear(); 261 catchLogSystem->clear();
264 std::string url = ResetTestXHR(jsEngine); 262 std::string url = ResetTestXHR(jsEngine);
265 jsEngine->Evaluate("\ 263 jsEngine->Evaluate("\
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l); 340 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l);
343 EXPECT_EQ("", catchLogSystem->lastMessage); 341 EXPECT_EQ("", catchLogSystem->lastMessage);
344 WaitForVariable("result", jsEngine); 342 WaitForVariable("result", jsEngine);
345 { 343 {
346 auto headersRequest = webRequest->headersForRequest(url); 344 auto headersRequest = webRequest->headersForRequest(url);
347 EXPECT_TRUE(headersRequest.first); 345 EXPECT_TRUE(headersRequest.first);
348 const auto& headers = headersRequest.second; 346 const auto& headers = headersRequest.second;
349 EXPECT_FALSE(headers.cend() == headers.find("Security")); 347 EXPECT_FALSE(headers.cend() == headers.find("Security"));
350 } 348 }
351 } 349 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld