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

Delta Between Two Patch Sets: test/WebRequest.cpp

Issue 10252013: Implemented curl support for web requests (Closed)
Left Patch Set: Unbitrotted the patch Created April 11, 2013, 4:33 p.m.
Right Patch Set: Addressed review comments Created April 12, 2013, 1:37 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
« include/AdblockPlus/WebRequest.h ('K') | « src/DefaultWebRequestDummy.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 <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 class TestWebRequest : public AdblockPlus::WebRequest 7 class TestWebRequest : public AdblockPlus::WebRequest
8 { 8 {
9 public: 9 public:
10 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const 10 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const
(...skipping 27 matching lines...) Expand all
38 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, function(){}, 0)")); 38 ASSERT_ANY_THROW(jsEngine.Evaluate("_webRequest.GET('http://example.com/', {}, function(){}, 0)"));
39 } 39 }
40 40
41 TEST(WebRequestTest, TestWebRequest) 41 TEST(WebRequestTest, TestWebRequest)
42 { 42 {
43 TestWebRequest webRequest; 43 TestWebRequest webRequest;
44 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); 44 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
45 jsEngine.Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function(r esult) {foo = result;} )"); 45 jsEngine.Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function(r esult) {foo = result;} )");
46 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); 46 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo"));
47 AdblockPlus::Sleep(200); 47 AdblockPlus::Sleep(200);
48 ASSERT_EQ(ToString(NS_OK), jsEngine.Evaluate("foo.status")); 48 ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_OK), jsEngine.Evaluate("foo.sta tus"));
49 ASSERT_EQ("123", jsEngine.Evaluate("foo.responseStatus")); 49 ASSERT_EQ("123", jsEngine.Evaluate("foo.responseStatus"));
50 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText")); 50 ASSERT_EQ("http://example.com/\nX\nY", jsEngine.Evaluate("foo.responseText"));
51 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH eaders)")); 51 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine.Evaluate("JSON.stringify(foo.responseH eaders)"));
52 } 52 }
53 53
54 #if defined(HAVE_CURL) 54 #if defined(HAVE_CURL)
55 TEST(WebRequestTest, RealWebRequest) 55 TEST(WebRequestTest, RealWebRequest)
56 { 56 {
57 AdblockPlus::DefaultWebRequest webRequest; 57 AdblockPlus::DefaultWebRequest webRequest;
58 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); 58 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
59 59
60 // This URL should redirect to easylist-downloads.adblockplus.org and we 60 // This URL should redirect to easylist-downloads.adblockplus.org and we
61 // should get the actual filter list back. 61 // should get the actual filter list back.
62 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist. txt', {}, function(result) {foo = result;} )"); 62 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist. txt', {}, function(result) {foo = result;} )");
63 do 63 do
64 { 64 {
65 AdblockPlus::Sleep(200); 65 AdblockPlus::Sleep(200);
66 } while (jsEngine.Evaluate("typeof foo") == "undefined"); 66 } while (jsEngine.Evaluate("typeof foo") == "undefined");
67 ASSERT_EQ(ToString(NS_OK), jsEngine.Evaluate("foo.status")); 67 ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_OK), jsEngine.Evaluate("foo.sta tus"));
68 ASSERT_EQ("200", jsEngine.Evaluate("foo.responseStatus")); 68 ASSERT_EQ("200", jsEngine.Evaluate("foo.responseStatus"));
69 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)" )); 69 ASSERT_EQ("[Adblock Plus ", jsEngine.Evaluate("foo.responseText.substr(0, 14)" ));
70 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type'] .substr(0, 10)")); 70 ASSERT_EQ("text/plain", jsEngine.Evaluate("foo.responseHeaders['content-type'] .substr(0, 10)"));
Oleksandr 2013/04/16 12:02:01 Do we care if the header is "content-type" or "Con
Felix Dahlke 2013/04/16 12:21:09 HTTP headers are case insensitive, so we can easil
Wladimir Palant 2013/04/16 13:30:32 I don't think that curl lowercases header names -
Felix Dahlke 2013/04/16 14:51:37 Hm, seems I missed that then.
Wladimir Palant 2013/04/17 06:56:20 I don't quite get this suggestion, WebRequestJsObj
71 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo.responseHeaders['location ']")); 71 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo.responseHeaders['location ']"));
72 } 72 }
73 #else 73 #else
74 TEST(WebRequestTest, DummyWebRequest) 74 TEST(WebRequestTest, DummyWebRequest)
75 { 75 {
76 AdblockPlus::DefaultWebRequest webRequest; 76 AdblockPlus::DefaultWebRequest webRequest;
77 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0); 77 AdblockPlus::JsEngine jsEngine(0, &webRequest, 0);
78 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist. txt', {}, function(result) {foo = result;} )"); 78 jsEngine.Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist. txt', {}, function(result) {foo = result;} )");
79 do 79 do
80 { 80 {
81 AdblockPlus::Sleep(200); 81 AdblockPlus::Sleep(200);
82 } while (jsEngine.Evaluate("typeof foo") == "undefined"); 82 } while (jsEngine.Evaluate("typeof foo") == "undefined");
83 ASSERT_EQ(ToString(NS_ERROR_FAILURE), jsEngine.Evaluate("foo.status")); 83 ASSERT_EQ(ToString(AdblockPlus::WebRequest::NS_ERROR_FAILURE), jsEngine.Evalua te("foo.status"));
84 ASSERT_EQ("0", jsEngine.Evaluate("foo.responseStatus")); 84 ASSERT_EQ("0", jsEngine.Evaluate("foo.responseStatus"));
85 ASSERT_EQ("", jsEngine.Evaluate("foo.responseText")); 85 ASSERT_EQ("", jsEngine.Evaluate("foo.responseText"));
86 ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)")); 86 ASSERT_EQ("{}", jsEngine.Evaluate("JSON.stringify(foo.responseHeaders)"));
87 } 87 }
88 #endif 88 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld