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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 mutable std::set<std::string> lastRequestHeaders; | 50 mutable std::set<std::string> lastRequestHeaders; |
51 }; | 51 }; |
52 | 52 |
53 template<class T> | 53 template<class T> |
54 class WebRequestTest : public BaseJsTest | 54 class WebRequestTest : public BaseJsTest |
55 { | 55 { |
56 protected: | 56 protected: |
57 void SetUp() | 57 void SetUp() |
58 { | 58 { |
59 BaseJsTest::SetUp(); | 59 BaseJsTest::SetUp(); |
60 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new T)); | 60 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new T())); |
61 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); | 61 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); |
62 } | 62 } |
63 }; | 63 }; |
64 | 64 |
65 typedef WebRequestTest<MockWebRequest> MockWebRequestTest; | 65 typedef WebRequestTest<MockWebRequest> MockWebRequestTest; |
66 typedef WebRequestTest<AdblockPlus::DefaultWebRequest> DefaultWebRequestTest; | 66 typedef WebRequestTest<AdblockPlus::DefaultWebRequest> DefaultWebRequestTest; |
67 typedef WebRequestTest<MockWebRequest> XMLHttpRequestTest; | 67 typedef WebRequestTest<MockWebRequest> XMLHttpRequestTest; |
68 | 68 |
69 void ResetTestXHR(const AdblockPlus::JsEnginePtr& jsEngine) | 69 void ResetTestXHR(const AdblockPlus::JsEnginePtr& jsEngine) |
70 { | 70 { |
71 jsEngine->Evaluate("\ | 71 jsEngine->Evaluate("\ |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 lastLogLevel = AdblockPlus::LogSystem::LOG_LEVEL_TRACE; | 200 lastLogLevel = AdblockPlus::LogSystem::LOG_LEVEL_TRACE; |
201 lastMessage.clear(); | 201 lastMessage.clear(); |
202 } | 202 } |
203 }; | 203 }; |
204 | 204 |
205 typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr; | 205 typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr; |
206 } | 206 } |
207 | 207 |
208 TEST_F(XMLHttpRequestTest, RequestHeaderValidation) | 208 TEST_F(XMLHttpRequestTest, RequestHeaderValidation) |
209 { | 209 { |
210 auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem); | 210 auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem()); |
211 jsEngine->SetLogSystem(catchLogSystem); | 211 jsEngine->SetLogSystem(catchLogSystem); |
212 | 212 |
213 AdblockPlus::FilterEngine filterEngine(jsEngine); | 213 AdblockPlus::FilterEngine filterEngine(jsEngine); |
214 auto webRequest = | 214 auto webRequest = |
215 std::static_pointer_cast<MockWebRequest>(jsEngine->GetWebRequest()); | 215 std::static_pointer_cast<MockWebRequest>(jsEngine->GetWebRequest()); |
216 | 216 |
217 ASSERT_TRUE(webRequest); | 217 ASSERT_TRUE(webRequest); |
218 | 218 |
219 const std::string msg = "Attempt to set a forbidden header was denied: "; | 219 const std::string msg = "Attempt to set a forbidden header was denied: "; |
220 | 220 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 catchLogSystem->clear(); | 281 catchLogSystem->clear(); |
282 ResetTestXHR(jsEngine); | 282 ResetTestXHR(jsEngine); |
283 jsEngine->Evaluate("\ | 283 jsEngine->Evaluate("\ |
284 request.setRequestHeader('Security', 'theater');\nrequest.send();"); | 284 request.setRequestHeader('Security', 'theater');\nrequest.send();"); |
285 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve
l); | 285 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve
l); |
286 EXPECT_EQ("", catchLogSystem->lastMessage); | 286 EXPECT_EQ("", catchLogSystem->lastMessage); |
287 WaitForVariable("result", jsEngine); | 287 WaitForVariable("result", jsEngine); |
288 EXPECT_FALSE(webRequest->lastRequestHeaders.cend() == | 288 EXPECT_FALSE(webRequest->lastRequestHeaders.cend() == |
289 webRequest->lastRequestHeaders.find("Security")); | 289 webRequest->lastRequestHeaders.find("Security")); |
290 } | 290 } |
OLD | NEW |