| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('', {}, function(){})")); | 153 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('', {}, function(){})")); |
| 154 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET({toString: false}, {}, fun
ction(){})")); | 154 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET({toString: false}, {}, fun
ction(){})")); |
| 155 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', nul
l, function(){})")); | 155 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', nul
l, function(){})")); |
| 156 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {},
null)")); | 156 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {},
null)")); |
| 157 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {},
function(){}, 0)")); | 157 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {},
function(){}, 0)")); |
| 158 } | 158 } |
| 159 | 159 |
| 160 TEST_F(MockWebRequestTest, SuccessfulRequest) | 160 TEST_F(MockWebRequestTest, SuccessfulRequest) |
| 161 { | 161 { |
| 162 auto& jsEngine = GetJsEngine(); | 162 auto& jsEngine = GetJsEngine(); |
| 163 jsEngine.Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function(r
esult) {foo = result;} )"); | 163 jsEngine.Evaluate("let foo; _webRequest.GET('http://example.com/', {X: 'Y'}, f
unction(result) {foo = result;} )"); |
| 164 ASSERT_TRUE(jsEngine.Evaluate("this.foo").IsUndefined()); | 164 ASSERT_TRUE(jsEngine.Evaluate("foo").IsUndefined()); |
| 165 ProcessPendingWebRequests(); | 165 ProcessPendingWebRequests(); |
| 166 ASSERT_EQ(IWebRequest::NS_OK, jsEngine.Evaluate("foo.status").AsInt()); | 166 ASSERT_EQ(IWebRequest::NS_OK, jsEngine.Evaluate("foo.status").AsInt()); |
| 167 ASSERT_EQ(123, jsEngine.Evaluate("foo.responseStatus").AsInt()); | 167 ASSERT_EQ(123, jsEngine.Evaluate("foo.responseStatus").AsInt()); |
| 168 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText").A
sString()); | 168 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText").A
sString()); |
| 169 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH
eaders)").AsString()); | 169 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH
eaders)").AsString()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 #if defined(HAVE_CURL) || defined(_WIN32) | 172 #if defined(HAVE_CURL) || defined(_WIN32) |
| 173 TEST_F(DefaultWebRequestTest, RealWebRequest) | 173 TEST_F(DefaultWebRequestTest, RealWebRequest) |
| 174 { | 174 { |
| 175 auto& jsEngine = GetJsEngine(); | 175 auto& jsEngine = GetJsEngine(); |
| 176 // This URL should redirect to easylist-downloads.adblockplus.org and we | 176 // This URL should redirect to easylist-downloads.adblockplus.org and we |
| 177 // should get the actual filter list back. | 177 // should get the actual filter list back. |
| 178 jsEngine.Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.org
/easylist.txt', {}, function(result) {foo = result;} )"); | 178 jsEngine.Evaluate("let foo; _webRequest.GET('https://easylist-downloads.adbloc
kplus.org/easylist.txt', {}, function(result) {foo = result;} )"); |
| 179 WaitForVariable("this.foo", jsEngine); | 179 WaitForVariable("foo", jsEngine); |
| 180 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type']
.substr(0, 10)").AsString()); | 180 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type']
.substr(0, 10)").AsString()); |
| 181 ASSERT_EQ(IWebRequest::NS_OK, jsEngine.Evaluate("foo.status").AsInt()); | 181 ASSERT_EQ(IWebRequest::NS_OK, jsEngine.Evaluate("foo.status").AsInt()); |
| 182 ASSERT_EQ(200, jsEngine.Evaluate("foo.responseStatus").AsInt()); | 182 ASSERT_EQ(200, jsEngine.Evaluate("foo.responseStatus").AsInt()); |
| 183 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)"
).AsString()); | 183 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)"
).AsString()); |
| 184 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type']
.substr(0, 10)").AsString()); | 184 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type']
.substr(0, 10)").AsString()); |
| 185 #if defined(HAVE_CURL) | 185 #if defined(HAVE_CURL) |
| 186 ASSERT_EQ("gzip", jsEngine.Evaluate("foo.responseHeaders['content-encoding'].s
ubstr(0, 4)").AsString()); | 186 ASSERT_EQ("gzip", jsEngine.Evaluate("foo.responseHeaders['content-encoding'].s
ubstr(0, 4)").AsString()); |
| 187 #endif | 187 #endif |
| 188 ASSERT_TRUE(jsEngine.Evaluate("foo.responseHeaders['location']").IsUndefined()
); | 188 ASSERT_TRUE(jsEngine.Evaluate("foo.responseHeaders['location']").IsUndefined()
); |
| 189 } | 189 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 205 ASSERT_EQ("text/plain", jsEngine.Evaluate("request.getResponseHeader('Content-
Type').substr(0, 10)").AsString()); | 205 ASSERT_EQ("text/plain", jsEngine.Evaluate("request.getResponseHeader('Content-
Type').substr(0, 10)").AsString()); |
| 206 #if defined(HAVE_CURL) | 206 #if defined(HAVE_CURL) |
| 207 ASSERT_EQ("gzip", jsEngine.Evaluate("request.getResponseHeader('Content-Encodi
ng').substr(0, 4)").AsString()); | 207 ASSERT_EQ("gzip", jsEngine.Evaluate("request.getResponseHeader('Content-Encodi
ng').substr(0, 4)").AsString()); |
| 208 #endif | 208 #endif |
| 209 ASSERT_TRUE(jsEngine.Evaluate("request.getResponseHeader('Location')").IsNull(
)); | 209 ASSERT_TRUE(jsEngine.Evaluate("request.getResponseHeader('Location')").IsNull(
)); |
| 210 } | 210 } |
| 211 #else | 211 #else |
| 212 TEST_F(DefaultWebRequestTest, DummyWebRequest) | 212 TEST_F(DefaultWebRequestTest, DummyWebRequest) |
| 213 { | 213 { |
| 214 auto& jsEngine = GetJsEngine(); | 214 auto& jsEngine = GetJsEngine(); |
| 215 jsEngine.Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.org
/easylist.txt', {}, function(result) {foo = result;} )"); | 215 jsEngine.Evaluate("let foo; _webRequest.GET('https://easylist-downloads.adbloc
kplus.org/easylist.txt', {}, function(result) {foo = result;} )"); |
| 216 WaitForVariable("this.foo", jsEngine); | 216 WaitForVariable("foo", jsEngine); |
| 217 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("foo.status").AsInt
()); | 217 ASSERT_EQ(IWebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("foo.status").AsInt
()); |
| 218 ASSERT_EQ(0, jsEngine.Evaluate("foo.responseStatus").AsInt()); | 218 ASSERT_EQ(0, jsEngine.Evaluate("foo.responseStatus").AsInt()); |
| 219 ASSERT_EQ("", jsEngine.Evaluate("foo.responseText").AsString()); | 219 ASSERT_EQ("", jsEngine.Evaluate("foo.responseText").AsString()); |
| 220 ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)").AsStr
ing()); | 220 ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)").AsStr
ing()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(DefaultWebRequestTest, XMLHttpRequest) | 223 TEST_F(DefaultWebRequestTest, XMLHttpRequest) |
| 224 { | 224 { |
| 225 auto& jsEngine = GetJsEngine(); | 225 auto& jsEngine = GetJsEngine(); |
| 226 auto filterEngine = CreateFilterEngine(*fileSystem, *platform); | 226 auto filterEngine = CreateFilterEngine(*fileSystem, *platform); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve
l); | 371 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve
l); |
| 372 EXPECT_EQ("", catchLogSystem->lastMessage); | 372 EXPECT_EQ("", catchLogSystem->lastMessage); |
| 373 ProcessPendingWebRequests(); | 373 ProcessPendingWebRequests(); |
| 374 { | 374 { |
| 375 auto headersRequest = GetHeadersForRequest(url); | 375 auto headersRequest = GetHeadersForRequest(url); |
| 376 EXPECT_TRUE(headersRequest.first); | 376 EXPECT_TRUE(headersRequest.first); |
| 377 const auto& headers = headersRequest.second; | 377 const auto& headers = headersRequest.second; |
| 378 EXPECT_FALSE(headers.cend() == headers.find("Security")); | 378 EXPECT_FALSE(headers.cend() == headers.find("Security")); |
| 379 } | 379 } |
| 380 } | 380 } |
| OLD | NEW |