| 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 |
| 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.libadblockplus.JsEngine; |
| 20 import org.adblockplus.libadblockplus.WebRequest; | 21 import org.adblockplus.libadblockplus.WebRequest; |
| 21 import org.adblockplus.libadblockplus.android.AndroidWebRequest; | 22 import org.adblockplus.libadblockplus.android.AndroidWebRequest; |
| 22 import org.adblockplus.libadblockplus.FilterEngine; | 23 import org.adblockplus.libadblockplus.FilterEngine; |
| 23 import org.adblockplus.libadblockplus.JsValue; | 24 import org.adblockplus.libadblockplus.JsValue; |
| 24 import org.adblockplus.libadblockplus.ServerResponse; | 25 import org.adblockplus.libadblockplus.ServerResponse; |
| 25 | 26 |
| 26 import org.junit.Test; | 27 import org.junit.Test; |
| 27 | 28 |
| 28 import java.net.MalformedURLException; | 29 import java.net.MalformedURLException; |
| 29 import java.util.List; | 30 import java.util.List; |
| 30 | 31 |
| 31 // creating not used anywhere FilterEngine object is not as useless as it seems: | 32 // creating not used anywhere FilterEngine object is not as useless as it seems: |
| 32 // it loads compat.js JsEngine to add XMLHttpRequest class support | 33 // it loads compat.js JsEngine to add XMLHttpRequest class support |
| 33 public class AndroidWebRequestTest extends BaseFilterEngineTest | 34 public class AndroidWebRequestTest extends BaseFilterEngineTest |
| 34 { | 35 { |
| 35 @Override | 36 @Override |
| 36 protected WebRequest createWebRequest() | 37 protected WebRequest createWebRequest() |
| 37 { | 38 { |
| 38 return new AndroidWebRequest(true, true); | 39 return new AndroidWebRequest(true, true); |
| 39 } | 40 } |
| 40 | 41 |
| 41 @Test | 42 @Test |
| 42 public void testRealWebRequest() | 43 public void testRealWebRequest() |
| 43 { | 44 { |
| 45 JsEngine jsEngine = platform.getJsEngine(); |
| 44 // This URL should redirect to easylist-downloads.adblockplus.org and we | 46 // This URL should redirect to easylist-downloads.adblockplus.org and we |
| 45 // should get the actual filter list back. | 47 // should get the actual filter list back. |
| 46 jsEngine.evaluate( | 48 jsEngine.evaluate( |
| 47 "let foo; _webRequest.GET('https://easylist-downloads.adblockplus.org/easy
list.txt', {}, " + | 49 "let foo; _webRequest.GET('https://easylist-downloads.adblockplus.org/easy
list.txt', {}, " + |
| 48 "function(result) {foo = result;} )"); | 50 "function(result) {foo = result;} )"); |
| 49 do | 51 do |
| 50 { | 52 { |
| 51 try | 53 try |
| 52 { | 54 { |
| 53 Thread.sleep(200); | 55 Thread.sleep(200); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 assertTrue(jsHeaders.isObject()); | 76 assertTrue(jsHeaders.isObject()); |
| 75 assertEquals( | 77 assertEquals( |
| 76 "text/plain", | 78 "text/plain", |
| 77 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS
tring()); | 79 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS
tring()); |
| 78 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined(
)); | 80 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined(
)); |
| 79 } | 81 } |
| 80 | 82 |
| 81 @Test | 83 @Test |
| 82 public void testXMLHttpRequest() | 84 public void testXMLHttpRequest() |
| 83 { | 85 { |
| 86 JsEngine jsEngine = platform.getJsEngine(); |
| 84 jsEngine.evaluate( | 87 jsEngine.evaluate( |
| 85 "var result;\n" + | 88 "var result;\n" + |
| 86 "var request = new XMLHttpRequest();\n" + | 89 "var request = new XMLHttpRequest();\n" + |
| 87 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.
txt');\n" + | 90 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.
txt');\n" + |
| 88 "request.setRequestHeader('X', 'Y');\n" + | 91 "request.setRequestHeader('X', 'Y');\n" + |
| 89 "request.setRequestHeader('X2', 'Y2');\n" + | 92 "request.setRequestHeader('X2', 'Y2');\n" + |
| 90 "request.overrideMimeType('text/plain');\n" + | 93 "request.overrideMimeType('text/plain');\n" + |
| 91 "request.addEventListener('load',function() {result=request.responseText;}
, false);\n" + | 94 "request.addEventListener('load',function() {result=request.responseText;}
, false);\n" + |
| 92 "request.addEventListener('error',function() {result='error';}, false);\n"
+ | 95 "request.addEventListener('error',function() {result='error';}, false);\n"
+ |
| 93 "request.send(null);"); | 96 "request.send(null);"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 assertFalse(isDocumentWhitelisted); | 130 assertFalse(isDocumentWhitelisted); |
| 128 | 131 |
| 129 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null
); | 132 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null
); |
| 130 assertFalse(isElemhideWhitelisted); | 133 assertFalse(isElemhideWhitelisted); |
| 131 | 134 |
| 132 List<String> selectors = filterEngine.getElementHidingSelectors(url); | 135 List<String> selectors = filterEngine.getElementHidingSelectors(url); |
| 133 assertNotNull(selectors); | 136 assertNotNull(selectors); |
| 134 assertTrue(selectors.size() > 0); | 137 assertTrue(selectors.size() > 0); |
| 135 } | 138 } |
| 136 } | 139 } |
| OLD | NEW |