LEFT | RIGHT |
1 #include <sstream> | 1 #include <sstream> |
2 #include <AdblockPlus.h> | 2 #include <AdblockPlus.h> |
3 #include <gtest/gtest.h> | 3 #include <gtest/gtest.h> |
4 | 4 |
5 #include "../src/Thread.h" | 5 #include "../src/Thread.h" |
| 6 |
| 7 #ifdef HAVE_WININET |
| 8 #include "../src/WebRequestWinInet.h" |
| 9 #endif |
6 | 10 |
7 class TestWebRequest : public AdblockPlus::WebRequest | 11 class TestWebRequest : public AdblockPlus::WebRequest |
8 { | 12 { |
9 public: | 13 public: |
10 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const | 14 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const |
11 { | 15 { |
12 AdblockPlus::Sleep(50); | 16 AdblockPlus::Sleep(50); |
13 | 17 |
14 AdblockPlus::ServerResponse result; | 18 AdblockPlus::ServerResponse result; |
15 result.status = NS_OK; | 19 result.status = NS_OK; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 do | 67 do |
64 { | 68 { |
65 AdblockPlus::Sleep(200); | 69 AdblockPlus::Sleep(200); |
66 } while (jsEngine.Evaluate("this.foo")->IsUndefined()); | 70 } while (jsEngine.Evaluate("this.foo")->IsUndefined()); |
67 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine.Evaluate("foo.status")->AsI
nt()); | 71 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine.Evaluate("foo.status")->AsI
nt()); |
68 ASSERT_EQ(200, jsEngine.Evaluate("foo.responseStatus")->AsInt()); | 72 ASSERT_EQ(200, jsEngine.Evaluate("foo.responseStatus")->AsInt()); |
69 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)"
)->AsString()); | 73 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)"
)->AsString()); |
70 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type']
.substr(0, 10)")->AsString()); | 74 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type']
.substr(0, 10)")->AsString()); |
71 ASSERT_TRUE(jsEngine.Evaluate("foo.responseHeaders['location']")->IsUndefined(
)); | 75 ASSERT_TRUE(jsEngine.Evaluate("foo.responseHeaders['location']")->IsUndefined(
)); |
72 } | 76 } |
| 77 #elif defined(HAVE_WININET) |
| 78 TEST(WebRequestTest, RealWebRequest) |
| 79 { |
| 80 AdblockPlus::WebRequestWinInet webRequest; |
| 81 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); |
| 82 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist.
txt', {}, function(result) {foo = result;} )"); |
| 83 do |
| 84 { |
| 85 AdblockPlus::Sleep(200); |
| 86 } while (jsEngine.Evaluate("typeof foo") == "undefined"); |
| 87 ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_OK), jsEngine.Evaluate("foo.sta
tus")); |
| 88 ASSERT_EQ("200", jsEngine.Evaluate("foo.responseStatus")); |
| 89 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)"
)); |
| 90 //TODO: Shall we be strict with letter casing here? Content-Type vs content-ty
pe |
| 91 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['Content-Type']
.substr(0, 10)")); |
| 92 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo.responseHeaders['location
']")); |
| 93 } |
73 #else | 94 #else |
74 TEST(WebRequestTest, DummyWebRequest) | 95 TEST(WebRequestTest, DummyWebRequest) |
75 { | 96 { |
76 AdblockPlus::DefaultWebRequest webRequest; | 97 AdblockPlus::DefaultWebRequest webRequest; |
77 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); | 98 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); |
78 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist.
txt', {}, function(result) {foo = result;} )"); | 99 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist.
txt', {}, function(result) {foo = result;} )"); |
79 do | 100 do |
80 { | 101 { |
81 AdblockPlus::Sleep(200); | 102 AdblockPlus::Sleep(200); |
82 } while (jsEngine.Evaluate("this.foo")->IsUndefined()); | 103 } while (jsEngine.Evaluate("this.foo")->IsUndefined()); |
83 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("foo.st
atus")->AsInt()); | 104 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("foo.st
atus")->AsInt()); |
84 ASSERT_EQ(0, jsEngine.Evaluate("foo.responseStatus")->AsInt()); | 105 ASSERT_EQ(0, jsEngine.Evaluate("foo.responseStatus")->AsInt()); |
85 ASSERT_EQ("", jsEngine.Evaluate("foo.responseText")->AsString()); | 106 ASSERT_EQ("", jsEngine.Evaluate("foo.responseText")->AsString()); |
86 ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)")->AsSt
ring()); | 107 ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)")->AsSt
ring()); |
87 } | 108 } |
88 #endif | 109 #endif |
LEFT | RIGHT |