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

Side by Side Diff: test/WebRequest.cpp

Issue 10259001: XMLHttpRequest API (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 derList& 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("_webRequest.GET()"));
25 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('', {}, function(){})"));
26 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET({toString: false}, {}, fun ction(){})"));
27 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', nul l, function(){})"));
28 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, null)"));
29 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, function(){}, 0)"));
30 }
31
32 TEST(WebRequestTest, UrlLoad)
33 {
34 TestWebRequest webRequest;
35 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
36 jsEngine.Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function(r esult) {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 }
OLDNEW
« no previous file with comments | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld