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

Side by Side Diff: test/WebRequest.cpp

Issue 10234088: Use GYP to generate MSVS project files (Closed)
Patch Set: Moved project files to build/ Created April 24, 2013, 1:57 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
OLDNEW
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 6
7 // TODO: Use a fixture here 7 // TODO: Use a fixture here
8 8
9 namespace 9 namespace
10 { 10 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new TestWebRequest())); 49 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new TestWebRequest()));
50 jsEngine->Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function( result) {foo = result;} )"); 50 jsEngine->Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function( result) {foo = result;} )");
51 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 51 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined());
52 AdblockPlus::Sleep(200); 52 AdblockPlus::Sleep(200);
53 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int()); 53 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int());
54 ASSERT_EQ(123, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 54 ASSERT_EQ(123, jsEngine->Evaluate("foo.responseStatus")->AsInt());
55 ASSERT_EQ("http://example.com/\nX\nY", jsEngine->Evaluate("foo.responseText")- >AsString()); 55 ASSERT_EQ("http://example.com/\nX\nY", jsEngine->Evaluate("foo.responseText")- >AsString());
56 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine->Evaluate("JSON.stringify(foo.response Headers)")->AsString()); 56 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine->Evaluate("JSON.stringify(foo.response Headers)")->AsString());
57 } 57 }
58 58
59 #if defined(HAVE_CURL) || defined(HAVE_WININET) 59 #if defined(HAVE_CURL) || defined(_WIN32)
60 TEST(WebRequestTest, RealWebRequest) 60 TEST(WebRequestTest, RealWebRequest)
61 { 61 {
62 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 62 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
63 63
64 // This URL should redirect to easylist-downloads.adblockplus.org and we 64 // This URL should redirect to easylist-downloads.adblockplus.org and we
65 // should get the actual filter list back. 65 // should get the actual filter list back.
66 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;} )");
67 do 67 do
68 { 68 {
69 AdblockPlus::Sleep(200); 69 AdblockPlus::Sleep(200);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 AdblockPlus::Sleep(200); 134 AdblockPlus::Sleep(200);
135 } while (jsEngine->Evaluate("result")->IsUndefined()); 135 } while (jsEngine->Evaluate("result")->IsUndefined());
136 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt()); 136 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt());
137 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt()); 137 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt());
138 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString()); 138 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString());
139 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull()); 139 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull());
140 } 140 }
141 141
142 #endif 142 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld