| 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 // 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 public class AndroidWebRequestTest extends BaseFilterEngineTest | |
| 32 { | 34 { |
| 33 @Override | 35 @Override |
| 34 protected WebRequest createWebRequest() | 36 protected WebRequest createWebRequest() |
| 35 { | 37 { |
| 36 return new AndroidWebRequest(true, true); | 38 return new AndroidWebRequest(true, true); |
| 37 } | 39 } |
| 38 | 40 |
| 39 @Test | 41 @Test |
| 40 public void testRealWebRequest() | 42 public void testRealWebRequest() |
| 41 { | 43 { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 72 assertTrue(jsHeaders.isObject()); | 74 assertTrue(jsHeaders.isObject()); |
| 73 assertEquals( | 75 assertEquals( |
| 74 "text/plain", | 76 "text/plain", |
| 75 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS tring()); | 77 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS tring()); |
| 76 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined( )); | 78 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined( )); |
| 77 } | 79 } |
| 78 | 80 |
| 79 @Test | 81 @Test |
| 80 public void testXMLHttpRequest() | 82 public void testXMLHttpRequest() |
| 81 { | 83 { |
| 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( | 84 jsEngine.evaluate( |
|
anton
2017/09/06 06:33:47
is creating FilterEngine instance not required any
sergei
2017/09/07 10:33:31
The creation of FilterEngine is still required and
anton
2017/09/07 11:51:13
Got it. Then we just don't need the comment before
| |
| 87 "var result;\n" + | 85 "var result;\n" + |
| 88 "var request = new XMLHttpRequest();\n" + | 86 "var request = new XMLHttpRequest();\n" + |
| 89 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" + | 87 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" + |
| 90 "request.setRequestHeader('X', 'Y');\n" + | 88 "request.setRequestHeader('X', 'Y');\n" + |
| 91 "request.setRequestHeader('X2', 'Y2');\n" + | 89 "request.setRequestHeader('X2', 'Y2');\n" + |
| 92 "request.overrideMimeType('text/plain');\n" + | 90 "request.overrideMimeType('text/plain');\n" + |
| 93 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" + | 91 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" + |
| 94 "request.addEventListener('error',function() {result='error';}, false);\n" + | 92 "request.addEventListener('error',function() {result='error';}, false);\n" + |
| 95 "request.send(null);"); | 93 "request.send(null);"); |
| 96 | 94 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 114 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)").asS tring()); | 112 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)").asS tring()); |
| 115 assertEquals( | 113 assertEquals( |
| 116 "text/plain", | 114 "text/plain", |
| 117 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(0, 10) ").asString()); | 115 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(0, 10) ").asString()); |
| 118 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").isNull ()); | 116 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").isNull ()); |
| 119 } | 117 } |
| 120 | 118 |
| 121 @Test | 119 @Test |
| 122 public void testGetElemhideElements() throws MalformedURLException, Interrupte dException | 120 public void testGetElemhideElements() throws MalformedURLException, Interrupte dException |
| 123 { | 121 { |
| 124 FilterEngine filterEngine = new FilterEngine(jsEngine); | |
| 125 | |
| 126 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded | 122 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded |
|
anton
2017/09/06 06:33:47
is creating FilterEngine instance not required any
| |
| 127 | 123 |
| 128 final String url = "www.mobile01.com/somepage.html"; | 124 final String url = "www.mobile01.com/somepage.html"; |
| 129 | 125 |
| 130 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null ); | 126 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null ); |
| 131 assertFalse(isDocumentWhitelisted); | 127 assertFalse(isDocumentWhitelisted); |
| 132 | 128 |
| 133 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null ); | 129 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null ); |
| 134 assertFalse(isElemhideWhitelisted); | 130 assertFalse(isElemhideWhitelisted); |
| 135 | 131 |
| 136 List<String> selectors = filterEngine.getElementHidingSelectors(url); | 132 List<String> selectors = filterEngine.getElementHidingSelectors(url); |
| 137 assertNotNull(selectors); | 133 assertNotNull(selectors); |
| 138 assertTrue(selectors.size() > 0); | 134 assertTrue(selectors.size() > 0); |
| 139 } | 135 } |
| 140 } | 136 } |
| OLD | NEW |