Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 } |
LEFT | RIGHT |