Left: | ||
Right: |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 10 matching lines...) Expand all Loading... | |
21 import org.adblockplus.libadblockplus.android.AndroidWebRequest; | 21 import org.adblockplus.libadblockplus.android.AndroidWebRequest; |
22 import org.adblockplus.libadblockplus.FilterEngine; | 22 import org.adblockplus.libadblockplus.FilterEngine; |
23 import org.adblockplus.libadblockplus.JsValue; | 23 import org.adblockplus.libadblockplus.JsValue; |
24 import org.adblockplus.libadblockplus.ServerResponse; | 24 import org.adblockplus.libadblockplus.ServerResponse; |
25 | 25 |
26 import org.junit.Test; | 26 import org.junit.Test; |
27 | 27 |
28 import java.net.MalformedURLException; | 28 import java.net.MalformedURLException; |
29 import java.util.List; | 29 import java.util.List; |
30 | 30 |
31 public class AndroidWebRequestTest extends BaseJsTest | 31 // It inherits the fixture instantiating FilterEngine which is not explicitly |
32 // used in the test bodies in order to provide with JS XMLHttpRequest class | |
33 // which is defined in compat.js, but the latter is properly loaded by | |
34 // FilterEngine. | |
sergei
2017/09/07 12:55:54
As discussed in IRC, it's not removed, it's change
anton
2017/09/07 12:57:48
LGTM
| |
35 public class AndroidWebRequestTest extends BaseFilterEngineTest | |
32 { | 36 { |
33 @Override | 37 @Override |
34 protected WebRequest createWebRequest() | 38 protected WebRequest createWebRequest() |
35 { | 39 { |
36 return new AndroidWebRequest(true, true); | 40 return new AndroidWebRequest(true, true); |
37 } | 41 } |
38 | 42 |
39 @Test | 43 @Test |
40 public void testRealWebRequest() | 44 public void testRealWebRequest() |
41 { | 45 { |
(...skipping 30 matching lines...) Expand all Loading... | |
72 assertTrue(jsHeaders.isObject()); | 76 assertTrue(jsHeaders.isObject()); |
73 assertEquals( | 77 assertEquals( |
74 "text/plain", | 78 "text/plain", |
75 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS tring()); | 79 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS tring()); |
76 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined( )); | 80 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined( )); |
77 } | 81 } |
78 | 82 |
79 @Test | 83 @Test |
80 public void testXMLHttpRequest() | 84 public void testXMLHttpRequest() |
81 { | 85 { |
82 // creating not used anywhere FilterEngine object is not as useless as it se ems: | |
83 // it loads compat.js JsEngine to add XMLHttpRequest class support | |
84 new FilterEngine(jsEngine); | |
85 | |
86 jsEngine.evaluate( | 86 jsEngine.evaluate( |
87 "var result;\n" + | 87 "var result;\n" + |
88 "var request = new XMLHttpRequest();\n" + | 88 "var request = new XMLHttpRequest();\n" + |
89 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" + | 89 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" + |
90 "request.setRequestHeader('X', 'Y');\n" + | 90 "request.setRequestHeader('X', 'Y');\n" + |
91 "request.setRequestHeader('X2', 'Y2');\n" + | 91 "request.setRequestHeader('X2', 'Y2');\n" + |
92 "request.overrideMimeType('text/plain');\n" + | 92 "request.overrideMimeType('text/plain');\n" + |
93 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" + | 93 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" + |
94 "request.addEventListener('error',function() {result='error';}, false);\n" + | 94 "request.addEventListener('error',function() {result='error';}, false);\n" + |
95 "request.send(null);"); | 95 "request.send(null);"); |
(...skipping 18 matching lines...) Expand all Loading... | |
114 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)").asS tring()); | 114 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)").asS tring()); |
115 assertEquals( | 115 assertEquals( |
116 "text/plain", | 116 "text/plain", |
117 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(0, 10) ").asString()); | 117 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(0, 10) ").asString()); |
118 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").isNull ()); | 118 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").isNull ()); |
119 } | 119 } |
120 | 120 |
121 @Test | 121 @Test |
122 public void testGetElemhideElements() throws MalformedURLException, Interrupte dException | 122 public void testGetElemhideElements() throws MalformedURLException, Interrupte dException |
123 { | 123 { |
124 FilterEngine filterEngine = new FilterEngine(jsEngine); | |
125 | |
126 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded | 124 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded |
127 | 125 |
128 final String url = "www.mobile01.com/somepage.html"; | 126 final String url = "www.mobile01.com/somepage.html"; |
129 | 127 |
130 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null ); | 128 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null ); |
131 assertFalse(isDocumentWhitelisted); | 129 assertFalse(isDocumentWhitelisted); |
132 | 130 |
133 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null ); | 131 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null ); |
134 assertFalse(isElemhideWhitelisted); | 132 assertFalse(isElemhideWhitelisted); |
135 | 133 |
136 List<String> selectors = filterEngine.getElementHidingSelectors(url); | 134 List<String> selectors = filterEngine.getElementHidingSelectors(url); |
137 assertNotNull(selectors); | 135 assertNotNull(selectors); |
138 assertTrue(selectors.size() > 0); | 136 assertTrue(selectors.size() > 0); |
139 } | 137 } |
140 } | 138 } |
OLD | NEW |