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

Unified Diff: test/WebRequest.cpp

Issue 10259001: XMLHttpRequest API (Closed)
Patch Set: Created April 10, 2013, 3:19 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/WebRequestJsObject.cpp ('K') | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/WebRequest.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/WebRequest.cpp
@@ -0,0 +1,42 @@
+#include <AdblockPlus.h>
+#include <gtest/gtest.h>
+
+#include "../src/Thread.h"
+
+class TestWebRequest : public AdblockPlus::WebRequest
+{
+public:
+ AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeadersList& requestHeaders) const
+ {
+ AdblockPlus::Sleep(50);
+
+ AdblockPlus::ServerResponse result;
+ result.responseStatus = 123;
+ result.responseHeaders.push_back(std::pair<std::string, std::string>("Foo", "Bar"));
+ result.responseText = url + "\n" + requestHeaders[0].first + "\n" + requestHeaders[0].second;
+ return result;
+ }
+};
+
+TEST(WebRequestTest, BadCall)
+{
+ AdblockPlus::JsEngine jsEngine(0, 0, 0);
+ ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET()"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('', {}, function(){})"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET({toString: false}, {}, function(){})"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', null, function(){})"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', {}, null)"));
+ ASSERT_ANY_THROW(jsEngine.Evaluate("_request.GET('http://example.com/', {}, function(){}, 0)"));
+}
+
+TEST(WebRequestTest, UrlLoad)
+{
+ TestWebRequest webRequest;
+ AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
+ jsEngine.Evaluate("_request.GET('http://example.com/', {X: 'Y'}, function(result) {foo = result;} )");
+ ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo"));
+ AdblockPlus::Sleep(200);
+ ASSERT_EQ("123", jsEngine.Evaluate("foo.responseStatus"));
+ ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText"));
+ ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)"));
+}
« src/WebRequestJsObject.cpp ('K') | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld