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

Delta Between Two Patch Sets: test/WebRequest.cpp

Issue 10259001: XMLHttpRequest API (Closed)
Left Patch Set: Created April 10, 2013, 3:19 p.m.
Right Patch Set: Addressed review comments Created April 11, 2013, 4:30 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 | « test/JsEngine.cpp ('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 <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <gtest/gtest.h> 2 #include <gtest/gtest.h>
3 3
4 #include "../src/Thread.h" 4 #include "../src/Thread.h"
5 5
6 class TestWebRequest : public AdblockPlus::WebRequest 6 class TestWebRequest : public AdblockPlus::WebRequest
7 { 7 {
8 public: 8 public:
9 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea dersList& requestHeaders) const 9 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const
10 { 10 {
11 AdblockPlus::Sleep(50); 11 AdblockPlus::Sleep(50);
12 12
13 AdblockPlus::ServerResponse result; 13 AdblockPlus::ServerResponse result;
14 result.responseStatus = 123; 14 result.responseStatus = 123;
15 result.responseHeaders.push_back(std::pair<std::string, std::string>("Foo", "Bar")); 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; 16 result.responseText = url + "\n" + requestHeaders[0].first + "\n" + requestH eaders[0].second;
17 return result; 17 return result;
18 } 18 }
19 }; 19 };
20 20
21 TEST(WebRequestTest, BadCall) 21 TEST(WebRequestTest, BadCall)
22 { 22 {
23 AdblockPlus::JsEngine jsEngine(0, 0, 0); 23 AdblockPlus::JsEngine jsEngine(0, 0, 0);
24 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET()")); 24 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET()"));
25 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('', {}, function(){})")); 25 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('', {}, function(){})"));
26 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET({toString: false}, {}, functi on(){})")); 26 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET({toString: false}, {}, fun ction(){})"));
27 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', null, function(){})")); 27 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', nul l, function(){})"));
28 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', {}, nu ll)")); 28 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, null)"));
29 ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', {}, fu nction(){}, 0)")); 29 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, function(){}, 0)"));
30 } 30 }
31 31
32 TEST(WebRequestTest, UrlLoad) 32 TEST(WebRequestTest, UrlLoad)
33 { 33 {
34 TestWebRequest webRequest; 34 TestWebRequest webRequest;
35 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); 35 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
36 jsEngine.Evaluate("_request.GET('http://example.com/', {X: 'Y'}, function(resu lt) {foo = result;} )"); 36 jsEngine.Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function(r esult) {foo = result;} )");
37 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); 37 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo"));
38 AdblockPlus::Sleep(200); 38 AdblockPlus::Sleep(200);
39 ASSERT_EQ("123", jsEngine.Evaluate("foo.responseStatus")); 39 ASSERT_EQ("123", jsEngine.Evaluate("foo.responseStatus"));
40 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText")); 40 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText"));
41 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH eaders)")); 41 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH eaders)"));
42 } 42 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld