OLD | NEW |
(Empty) | |
| 1 #include <AdblockPlus.h> |
| 2 #include <gtest/gtest.h> |
| 3 |
| 4 #include "../src/Thread.h" |
| 5 |
| 6 class TestWebRequest : public AdblockPlus::WebRequest |
| 7 { |
| 8 public: |
| 9 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
dersList& requestHeaders) const |
| 10 { |
| 11 AdblockPlus::Sleep(50); |
| 12 |
| 13 AdblockPlus::ServerResponse result; |
| 14 result.responseStatus = 123; |
| 15 result.responseHeaders.push_back(std::pair<std::string, std::string>("Foo",
"Bar")); |
| 16 result.responseText = url + "\n" + requestHeaders[0].first + "\n" + requestH
eaders[0].second; |
| 17 return result; |
| 18 } |
| 19 }; |
| 20 |
| 21 TEST(WebRequestTest, BadCall) |
| 22 { |
| 23 AdblockPlus::JsEngine jsEngine(0, 0, 0); |
| 24 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET()")); |
| 25 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('', {}, function(){})")); |
| 26 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET({toString: false}, {}, functi
on(){})")); |
| 27 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', null,
function(){})")); |
| 28 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', {}, nu
ll)")); |
| 29 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', {}, fu
nction(){}, 0)")); |
| 30 } |
| 31 |
| 32 TEST(WebRequestTest, UrlLoad) |
| 33 { |
| 34 TestWebRequest webRequest; |
| 35 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); |
| 36 jsEngine.Evaluate("_request.GET('http://example.com/', {X: 'Y'}, function(resu
lt) {foo = result;} )"); |
| 37 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); |
| 38 AdblockPlus::Sleep(200); |
| 39 ASSERT_EQ("123", jsEngine.Evaluate("foo.responseStatus")); |
| 40 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText")); |
| 41 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH
eaders)")); |
| 42 } |
OLD | NEW |