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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.libadblockplus.tests; | 18 package org.adblockplus.libadblockplus.tests; |
19 | 19 |
20 import org.adblockplus.android.AndroidWebRequest; | 20 import org.adblockplus.android.AndroidWebRequest; |
| 21 import org.adblockplus.libadblockplus.FilterEngine; |
21 import org.adblockplus.libadblockplus.JsValue; | 22 import org.adblockplus.libadblockplus.JsValue; |
22 import org.adblockplus.libadblockplus.ServerResponse; | 23 import org.adblockplus.libadblockplus.ServerResponse; |
23 | 24 |
24 import org.junit.Test; | 25 import org.junit.Test; |
25 | 26 |
26 public class AndroidWebRequestTest extends BaseJsTest | 27 public class AndroidWebRequestTest extends BaseJsTest |
27 { | 28 { |
28 @Override | 29 @Override |
29 protected void setUp() throws Exception | 30 protected void setUp() throws Exception |
30 { | 31 { |
(...skipping 30 matching lines...) Expand all Loading... |
61 assertEquals( | 62 assertEquals( |
62 "[Adblock Plus ", | 63 "[Adblock Plus ", |
63 jsEngine.evaluate("foo.responseText.substr(0, 14)").asString()); | 64 jsEngine.evaluate("foo.responseText.substr(0, 14)").asString()); |
64 JsValue jsHeaders = jsEngine.evaluate("foo.responseHeaders"); | 65 JsValue jsHeaders = jsEngine.evaluate("foo.responseHeaders"); |
65 assertNotNull(jsHeaders); | 66 assertNotNull(jsHeaders); |
66 assertFalse(jsHeaders.isUndefined()); | 67 assertFalse(jsHeaders.isUndefined()); |
67 assertFalse(jsHeaders.isNull()); | 68 assertFalse(jsHeaders.isNull()); |
68 assertTrue(jsHeaders.isObject()); | 69 assertTrue(jsHeaders.isObject()); |
69 assertEquals( | 70 assertEquals( |
70 "text/plain", | 71 "text/plain", |
71 jsEngine.evaluate("foo.responseHeaders['Content-Type'].substr(0,10)"
).asString()); | 72 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0,10)"
).asString()); |
72 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefi
ned()); | 73 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefi
ned()); |
73 } | 74 } |
74 | 75 |
75 @Test | 76 @Test |
76 public void testXMLHttpRequest() | 77 public void testXMLHttpRequest() |
77 { | 78 { |
| 79 // creating not used anywhere FilterEngine object is not as useless as i
t seems: |
| 80 // it loads compat.js JsEngine to add XMLHttpRequest class support |
| 81 new FilterEngine(jsEngine); |
| 82 |
78 jsEngine.evaluate( | 83 jsEngine.evaluate( |
79 "var result;\n" + | 84 "var result;\n" + |
80 "var request = new XMLHttpRequest();\n" + | 85 "var request = new XMLHttpRequest();\n" + |
81 "request.open('GET', 'https://easylist-downloads.adblockplus.org/eas
ylist.txt');\n" + | 86 "request.open('GET', 'https://easylist-downloads.adblockplus.org/eas
ylist.txt');\n" + |
82 "request.setRequestHeader('X', 'Y');\n" + | 87 "request.setRequestHeader('X', 'Y');\n" + |
83 "request.setRequestHeader('X2', 'Y2');\n" + | 88 "request.setRequestHeader('X2', 'Y2');\n" + |
84 "request.overrideMimeType('text/plain');\n" + | 89 "request.overrideMimeType('text/plain');\n" + |
85 "request.addEventListener('load',function() {result=request.response
Text;}, false);\n" + | 90 "request.addEventListener('load',function() {result=request.response
Text;}, false);\n" + |
86 "request.addEventListener('error',function() {result='error';}, fals
e);\n" + | 91 "request.addEventListener('error',function() {result='error';}, fals
e);\n" + |
87 "request.send(null);"); | 92 "request.send(null);"); |
(...skipping 14 matching lines...) Expand all Loading... |
102 jsEngine.evaluate("request.channel.status").asLong()); | 107 jsEngine.evaluate("request.channel.status").asLong()); |
103 | 108 |
104 assertEquals(200l, jsEngine.evaluate("request.status").asLong()); | 109 assertEquals(200l, jsEngine.evaluate("request.status").asLong()); |
105 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)")
.asString()); | 110 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)")
.asString()); |
106 assertEquals( | 111 assertEquals( |
107 "text/plain", | 112 "text/plain", |
108 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(
0,10)").asString()); | 113 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(
0,10)").asString()); |
109 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").is
Null()); | 114 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").is
Null()); |
110 } | 115 } |
111 } | 116 } |
OLD | NEW |