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

Unified Diff: test/WebRequest.cpp

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Unbitrotted patch Created April 16, 2013, 3:30 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
« no previous file with comments | « test/JsValue.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
===================================================================
--- a/test/WebRequest.cpp
+++ b/test/WebRequest.cpp
@@ -42,42 +42,42 @@ TEST(WebRequestTest, BadCall)
ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, function(){}, 0)"));
}
TEST(WebRequestTest, TestWebRequest)
{
TestWebRequest webRequest;
AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
jsEngine.Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function(result) {foo = result;} )");
- ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo"));
+ ASSERT_TRUE(jsEngine.Evaluate("this.foo")->IsUndefined());
AdblockPlus::Sleep(200);
- ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_OK), jsEngine.Evaluate("foo.status"));
- 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)"));
+ ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine.Evaluate("foo.status")->AsInt());
+ ASSERT_EQ(123, jsEngine.Evaluate("foo.responseStatus")->AsInt());
+ ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText")->AsString());
+ ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)")->AsString());
}
#if defined(HAVE_CURL)
TEST(WebRequestTest, RealWebRequest)
{
AdblockPlus::DefaultWebRequest webRequest;
AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
// This URL should redirect to easylist-downloads.adblockplus.org and we
// should get the actual filter list back.
jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist.txt', {}, function(result) {foo = result;} )");
do
{
AdblockPlus::Sleep(200);
- } while (jsEngine.Evaluate("typeof foo") == "undefined");
- ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_OK), jsEngine.Evaluate("foo.status"));
- ASSERT_EQ("200", jsEngine.Evaluate("foo.responseStatus"));
- ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)"));
- ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type'].substr(0, 10)"));
- ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo.responseHeaders['location']"));
+ } while (jsEngine.Evaluate("this.foo")->IsUndefined());
+ ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine.Evaluate("foo.status")->AsInt());
+ ASSERT_EQ(200, jsEngine.Evaluate("foo.responseStatus")->AsInt());
+ ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)")->AsString());
+ ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type'].substr(0, 10)")->AsString());
+ ASSERT_TRUE(jsEngine.Evaluate("foo.responseHeaders['location']")->IsUndefined());
}
#elif defined(HAVE_WININET)
TEST(WebRequestTest, RealWebRequest)
{
AdblockPlus::WebRequestWinInet webRequest;
AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist.txt', {}, function(result) {foo = result;} )");
do
@@ -95,15 +95,15 @@ TEST(WebRequestTest, RealWebRequest)
TEST(WebRequestTest, DummyWebRequest)
{
AdblockPlus::DefaultWebRequest webRequest;
AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist.txt', {}, function(result) {foo = result;} )");
do
{
AdblockPlus::Sleep(200);
- } while (jsEngine.Evaluate("typeof foo") == "undefined");
- ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_ERROR_FAILURE), jsEngine.Evaluate("foo.status"));
- ASSERT_EQ("0", jsEngine.Evaluate("foo.responseStatus"));
- ASSERT_EQ("", jsEngine.Evaluate("foo.responseText"));
- ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)"));
+ } while (jsEngine.Evaluate("this.foo")->IsUndefined());
+ ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine.Evaluate("foo.status")->AsInt());
+ ASSERT_EQ(0, jsEngine.Evaluate("foo.responseStatus")->AsInt());
+ ASSERT_EQ("", jsEngine.Evaluate("foo.responseText")->AsString());
+ ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)")->AsString());
}
#endif
« no previous file with comments | « test/JsValue.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld