OLD | NEW |
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 auto filterEngine = AdblockPlus::FilterEngine::Create(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-downloads.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);\ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |