| OLD | NEW | 
|---|
| 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 13 matching lines...) Expand all  Loading... | 
| 24 using namespace AdblockPlus; | 24 using namespace AdblockPlus; | 
| 25 | 25 | 
| 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.timer.reset(new NoopTimer()); | 35       jsEngineParams.timer.reset(new NoopTimer()); | 
| 35       jsEngineParams.fileSystem.reset(new LazyFileSystem()); | 36       jsEngineParams.fileSystem.reset(new LazyFileSystem()); | 
| 36       jsEngineParams.webRequest = CreateWebRequest(); | 37       jsEngineParams.webRequest = CreateWebRequest(); | 
| 37       jsEngine = CreateJsEngine(std::move(jsEngineParams)); | 38       jsEngine = CreateJsEngine(std::move(jsEngineParams)); | 
| 38     } | 39     } | 
| 39 | 40 | 
| 40     virtual WebRequestPtr CreateWebRequest() | 41     virtual WebRequestPtr CreateWebRequest() | 
| 41     { | 42     { | 
| 42       return CreateDefaultWebRequest(); | 43       return CreateDefaultWebRequest(); | 
| 43     } | 44     } | 
| 44 | 45 | 
|  | 46     virtual LogSystemPtr CreateLogSystem() | 
|  | 47     { | 
|  | 48       return LogSystemPtr(new ThrowingLogSystem()); | 
|  | 49     } | 
|  | 50 | 
| 45     JsEnginePtr jsEngine; | 51     JsEnginePtr jsEngine; | 
| 46   }; | 52   }; | 
| 47 | 53 | 
| 48   class MockWebRequestTest : public DefaultWebRequestTest | 54   class MockWebRequestTest : public DefaultWebRequestTest | 
| 49   { | 55   { | 
| 50     virtual WebRequestPtr CreateWebRequest() override | 56     virtual WebRequestPtr CreateWebRequest() override | 
| 51     { | 57     { | 
| 52       return DelayedWebRequest::New(webRequestTasks); | 58       return DelayedWebRequest::New(webRequestTasks); | 
| 53     } | 59     } | 
| 54 | 60 | 
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 238       lastMessage = message; | 244       lastMessage = message; | 
| 239     } | 245     } | 
| 240 | 246 | 
| 241     void clear() | 247     void clear() | 
| 242     { | 248     { | 
| 243       lastLogLevel = AdblockPlus::LogSystem::LOG_LEVEL_TRACE; | 249       lastLogLevel = AdblockPlus::LogSystem::LOG_LEVEL_TRACE; | 
| 244       lastMessage.clear(); | 250       lastMessage.clear(); | 
| 245     } | 251     } | 
| 246   }; | 252   }; | 
| 247 | 253 | 
| 248   typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr; | 254   class MockWebRequestAndLogSystemTest : public MockWebRequestTest | 
|  | 255   { | 
|  | 256     LogSystemPtr CreateLogSystem() override | 
|  | 257     { | 
|  | 258       return LogSystemPtr(catchLogSystem = new CatchLogSystem()); | 
|  | 259     } | 
|  | 260   protected: | 
|  | 261     CatchLogSystem* catchLogSystem; | 
|  | 262   }; | 
| 249 } | 263 } | 
| 250 | 264 | 
| 251 TEST_F(MockWebRequestTest, RequestHeaderValidation) | 265 TEST_F(MockWebRequestAndLogSystemTest, RequestHeaderValidation) | 
| 252 { | 266 { | 
| 253   auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem()); |  | 
| 254   jsEngine->SetLogSystem(catchLogSystem); |  | 
| 255 |  | 
| 256   auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 267   auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 
| 257 | 268 | 
| 258   const std::string msg = "Attempt to set a forbidden header was denied: "; | 269   const std::string msg = "Attempt to set a forbidden header was denied: "; | 
| 259 | 270 | 
| 260   // The test will check that console.warn has been called when the | 271   // The test will check that console.warn has been called when the | 
| 261   // header is rejected. While this is an implementation detail, we | 272   // header is rejected. While this is an implementation detail, we | 
| 262   // have no other way to check this | 273   // have no other way to check this | 
| 263 | 274 | 
| 264   // test 'Accept-Encoding' is rejected | 275   // test 'Accept-Encoding' is rejected | 
| 265   catchLogSystem->clear(); | 276   catchLogSystem->clear(); | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 344   EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve
     l); | 355   EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve
     l); | 
| 345   EXPECT_EQ("", catchLogSystem->lastMessage); | 356   EXPECT_EQ("", catchLogSystem->lastMessage); | 
| 346   ProcessPendingWebRequests(); | 357   ProcessPendingWebRequests(); | 
| 347   { | 358   { | 
| 348     auto headersRequest = GetHeadersForRequest(url); | 359     auto headersRequest = GetHeadersForRequest(url); | 
| 349     EXPECT_TRUE(headersRequest.first); | 360     EXPECT_TRUE(headersRequest.first); | 
| 350     const auto& headers = headersRequest.second; | 361     const auto& headers = headersRequest.second; | 
| 351     EXPECT_FALSE(headers.cend() == headers.find("Security")); | 362     EXPECT_FALSE(headers.cend() == headers.find("Security")); | 
| 352   } | 363   } | 
| 353 } | 364 } | 
| OLD | NEW | 
|---|