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

Side by Side Diff: test/WebRequest.cpp

Issue 29341000: No issue - fix tests since easylist moved (Closed)
Patch Set: Created May 3, 2016, 11:17 a.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 | « no previous file | 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
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ASSERT_EQ(123, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 72 ASSERT_EQ(123, jsEngine->Evaluate("foo.responseStatus")->AsInt());
73 ASSERT_EQ("http://example.com/\nX\nY", jsEngine->Evaluate("foo.responseText")- >AsString()); 73 ASSERT_EQ("http://example.com/\nX\nY", jsEngine->Evaluate("foo.responseText")- >AsString());
74 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine->Evaluate("JSON.stringify(foo.response Headers)")->AsString()); 74 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine->Evaluate("JSON.stringify(foo.response Headers)")->AsString());
75 } 75 }
76 76
77 #if defined(HAVE_CURL) || defined(_WIN32) 77 #if defined(HAVE_CURL) || defined(_WIN32)
78 TEST_F(DefaultWebRequestTest, RealWebRequest) 78 TEST_F(DefaultWebRequestTest, RealWebRequest)
79 { 79 {
80 // This URL should redirect to easylist-downloads.adblockplus.org and we 80 // This URL should redirect to easylist-downloads.adblockplus.org and we
81 // should get the actual filter list back. 81 // should get the actual filter list back.
82 jsEngine->Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist .txt', {}, function(result) {foo = result;} )"); 82 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
83 do 83 do
84 { 84 {
85 AdblockPlus::Sleep(200); 85 AdblockPlus::Sleep(200);
86 } while (jsEngine->Evaluate("this.foo")->IsUndefined()); 86 } while (jsEngine->Evaluate("this.foo")->IsUndefined());
87 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString()); 87 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString());
88 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int()); 88 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int());
89 ASSERT_EQ(200, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 89 ASSERT_EQ(200, jsEngine->Evaluate("foo.responseStatus")->AsInt());
90 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ")->AsString()); 90 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ")->AsString());
91 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString()); 91 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString());
92 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']")->IsUndefined ()); 92 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']")->IsUndefined ());
93 } 93 }
94 94
95 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 95 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
96 { 96 {
97 AdblockPlus::FilterEngine filterEngine(jsEngine); 97 AdblockPlus::FilterEngine filterEngine(jsEngine);
98 98
99 jsEngine->Evaluate("\ 99 jsEngine->Evaluate("\
100 var result;\ 100 var result;\
101 var request = new XMLHttpRequest();\ 101 var request = new XMLHttpRequest();\
102 request.open('GET', 'https://easylist.adblockplus.org/easylist.txt');\ 102 request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.txt ');\
103 request.setRequestHeader('X', 'Y');\ 103 request.setRequestHeader('X', 'Y');\
104 request.setRequestHeader('X2', 'Y2');\ 104 request.setRequestHeader('X2', 'Y2');\
105 request.overrideMimeType('text/plain');\ 105 request.overrideMimeType('text/plain');\
106 request.addEventListener('load', function() {result = request.responseText;} , false);\ 106 request.addEventListener('load', function() {result = request.responseText;} , false);\
107 request.addEventListener('error', function() {result = 'error';}, false);\ 107 request.addEventListener('error', function() {result = 'error';}, false);\
108 request.send(null);"); 108 request.send(null);");
109 do 109 do
110 { 110 {
111 AdblockPlus::Sleep(200); 111 AdblockPlus::Sleep(200);
112 } while (jsEngine->Evaluate("result")->IsUndefined()); 112 } while (jsEngine->Evaluate("result")->IsUndefined());
113 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("request.channel. status")->AsInt()); 113 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("request.channel. status")->AsInt());
114 ASSERT_EQ(200, jsEngine->Evaluate("request.status")->AsInt()); 114 ASSERT_EQ(200, jsEngine->Evaluate("request.status")->AsInt());
115 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)")->AsStri ng()); 115 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)")->AsStri ng());
116 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)")->AsString()); 116 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)")->AsString());
117 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')")->IsNul l()); 117 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')")->IsNul l());
118 } 118 }
119 #else 119 #else
120 TEST_F(DefaultWebRequestTest, DummyWebRequest) 120 TEST_F(DefaultWebRequestTest, DummyWebRequest)
121 { 121 {
122 jsEngine->Evaluate("_webRequest.GET('https://easylist.adblockplus.org/easylist .txt', {}, function(result) {foo = result;} )"); 122 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
123 do 123 do
124 { 124 {
125 AdblockPlus::Sleep(200); 125 AdblockPlus::Sleep(200);
126 } while (jsEngine->Evaluate("this.foo")->IsUndefined()); 126 } while (jsEngine->Evaluate("this.foo")->IsUndefined());
127 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.s tatus")->AsInt()); 127 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.s tatus")->AsInt());
128 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 128 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus")->AsInt());
129 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText")->AsString()); 129 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText")->AsString());
130 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)")->AsS tring()); 130 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)")->AsS tring());
131 } 131 }
132 132
133 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 133 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
134 { 134 {
135 AdblockPlus::FilterEngine filterEngine(jsEngine); 135 AdblockPlus::FilterEngine filterEngine(jsEngine);
136 136
137 jsEngine->Evaluate("\ 137 jsEngine->Evaluate("\
138 var result;\ 138 var result;\
139 var request = new XMLHttpRequest();\ 139 var request = new XMLHttpRequest();\
140 request.open('GET', 'https://easylist.adblockplus.org/easylist.txt');\ 140 request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.txt ');\
141 request.setRequestHeader('X', 'Y');\ 141 request.setRequestHeader('X', 'Y');\
142 request.overrideMimeType('text/plain');\ 142 request.overrideMimeType('text/plain');\
143 request.addEventListener('load', function() {result = request.responseText;} , false);\ 143 request.addEventListener('load', function() {result = request.responseText;} , false);\
144 request.addEventListener('error', function() {result = 'error';}, false);\ 144 request.addEventListener('error', function() {result = 'error';}, false);\
145 request.send(null);"); 145 request.send(null);");
146 do 146 do
147 { 147 {
148 AdblockPlus::Sleep(200); 148 AdblockPlus::Sleep(200);
149 } while (jsEngine->Evaluate("result")->IsUndefined()); 149 } while (jsEngine->Evaluate("result")->IsUndefined());
150 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt()); 150 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt());
151 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt()); 151 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt());
152 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString()); 152 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString());
153 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull()); 153 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull());
154 } 154 }
155 155
156 #endif 156 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld