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

Side by Side Diff: test/WebRequest.cpp

Issue 29377064: Issue 4944 - Make creation of FilterEngine asynchronous. (Closed)
Patch Set: rebase and address comments Created March 16, 2017, 3:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 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-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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ")->AsString()); 122 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ")->AsString());
123 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString()); 123 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString());
124 #if defined(HAVE_CURL) 124 #if defined(HAVE_CURL)
125 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)")->AsString()); 125 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)")->AsString());
126 #endif 126 #endif
127 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']")->IsUndefined ()); 127 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']")->IsUndefined ());
128 } 128 }
129 129
130 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 130 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
131 { 131 {
132 AdblockPlus::FilterEngine filterEngine(jsEngine); 132 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
133 133
134 ResetTestXHR(jsEngine); 134 ResetTestXHR(jsEngine);
135 jsEngine->Evaluate("\ 135 jsEngine->Evaluate("\
136 request.setRequestHeader('X', 'Y');\ 136 request.setRequestHeader('X', 'Y');\
137 request.setRequestHeader('X2', 'Y2');\ 137 request.setRequestHeader('X2', 'Y2');\
138 request.send(null);"); 138 request.send(null);");
139 WaitForVariable("result", jsEngine); 139 WaitForVariable("result", jsEngine);
140 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("request.channel. status")->AsInt()); 140 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("request.channel. status")->AsInt());
141 ASSERT_EQ(200, jsEngine->Evaluate("request.status")->AsInt()); 141 ASSERT_EQ(200, jsEngine->Evaluate("request.status")->AsInt());
142 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)")->AsStri ng()); 142 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)")->AsStri ng());
143 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)")->AsString()); 143 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)")->AsString());
144 #if defined(HAVE_CURL) 144 #if defined(HAVE_CURL)
145 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)")->AsString()); 145 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)")->AsString());
146 #endif 146 #endif
147 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')")->IsNul l()); 147 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')")->IsNul l());
148 } 148 }
149 #else 149 #else
150 TEST_F(DefaultWebRequestTest, DummyWebRequest) 150 TEST_F(DefaultWebRequestTest, DummyWebRequest)
151 { 151 {
152 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )"); 152 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
153 WaitForVariable("this.foo", jsEngine); 153 WaitForVariable("this.foo", jsEngine);
154 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.s tatus")->AsInt()); 154 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.s tatus")->AsInt());
155 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 155 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus")->AsInt());
156 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText")->AsString()); 156 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText")->AsString());
157 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)")->AsS tring()); 157 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)")->AsS tring());
158 } 158 }
159 159
160 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 160 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
161 { 161 {
162 AdblockPlus::FilterEngine filterEngine(jsEngine); 162 auto filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
163 163
164 ResetTestXHR(jsEngine); 164 ResetTestXHR(jsEngine);
165 jsEngine->Evaluate("\ 165 jsEngine->Evaluate("\
166 request.setRequestHeader('X', 'Y');\ 166 request.setRequestHeader('X', 'Y');\
167 request.send(null);"); 167 request.send(null);");
168 WaitForVariable("result", jsEngine); 168 WaitForVariable("result", jsEngine);
169 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt()); 169 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt());
170 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt()); 170 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt());
171 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString()); 171 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString());
172 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull()); 172 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull());
(...skipping 30 matching lines...) Expand all
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 auto filterEngine = AdblockPlus::FilterEngine::Create(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
221 // The test will check that console.warn has been called when the 221 // The test will check that console.warn has been called when the
222 // header is rejected. While this is an implementation detail, we 222 // header is rejected. While this is an implementation detail, we
223 // have no other way to check this 223 // have no other way to check this
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « test/UpdateCheck.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld