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

Delta Between Two Patch Sets: test/WebRequest.cpp

Issue 10214006: Added JS-based XMLHttpRequest implementation (Closed)
Left Patch Set: Created April 15, 2013, 11:36 a.m.
Right Patch Set: Unbitrotted patch Created April 16, 2013, 3:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/compat.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist. txt', {}, function(result) {foo = result;} )"); 66 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist. txt', {}, function(result) {foo = result;} )");
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( ));
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 ']"));
72 } 93 }
73 94
74 TEST(WebRequestTest, XMLHttpRequest) 95 TEST(WebRequestTest, XMLHttpRequest)
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 AdblockPlus::FilterEngine filterEngine(jsEngine); 99 AdblockPlus::FilterEngine filterEngine(jsEngine);
79 100
80 jsEngine.Evaluate("\ 101 jsEngine.Evaluate("\
81 var result;\ 102 var result;\
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 do 151 do
131 { 152 {
132 AdblockPlus::Sleep(200); 153 AdblockPlus::Sleep(200);
133 } while (jsEngine.Evaluate("result")->IsUndefined()); 154 } while (jsEngine.Evaluate("result")->IsUndefined());
134 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("reques t.channel.status")->AsInt()); 155 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("reques t.channel.status")->AsInt());
135 ASSERT_EQ(0, jsEngine.Evaluate("request.status")->AsInt()); 156 ASSERT_EQ(0, jsEngine.Evaluate("request.status")->AsInt());
136 ASSERT_EQ("error", jsEngine.Evaluate("result")->AsString()); 157 ASSERT_EQ("error", jsEngine.Evaluate("result")->AsString());
137 ASSERT_TRUE(jsEngine.Evaluate("request.getResponseHeader('Content-Type')")->Is Null()); 158 ASSERT_TRUE(jsEngine.Evaluate("request.getResponseHeader('Content-Type')")->Is Null());
138 } 159 }
139 #endif 160 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld