Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java

Issue 29361445: Issue 4399 - Add WebView inheritor with ad blocking (Closed)
Patch Set: fixed 2 more members in AdblockEngine Created Dec. 16, 2016, 8:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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.libadblockplus.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
27 import java.net.MalformedURLException;
28 import java.util.List;
29
26 public class AndroidWebRequestTest extends BaseJsTest 30 public class AndroidWebRequestTest extends BaseJsTest
27 { 31 {
28 @Override 32 @Override
29 protected void setUp() throws Exception 33 protected void setUp() throws Exception
30 { 34 {
31 super.setUp(); 35 super.setUp();
32 36
33 jsEngine.setWebRequest(new AndroidWebRequest()); 37 jsEngine.setWebRequest(new AndroidWebRequest(true));
34 } 38 }
35 39
36 @Test 40 @Test
37 public void testRealWebRequest() 41 public void testRealWebRequest()
38 { 42 {
39 // This URL should redirect to easylist-downloads.adblockplus.org and we 43 // This URL should redirect to easylist-downloads.adblockplus.org and we
40 // should get the actual filter list back. 44 // should get the actual filter list back.
41 jsEngine.evaluate( 45 jsEngine.evaluate(
42 "_webRequest.GET('https://easylist-downloads.adblockplus.org/easylis t.txt', {}, " + 46 "_webRequest.GET('https://easylist-downloads.adblockplus.org/easylis t.txt', {}, " +
43 "function(result) {foo = result;} )"); 47 "function(result) {foo = result;} )");
44 do 48 do
45 { 49 {
46 try 50 try
47 { 51 {
48 Thread.sleep(200); 52 Thread.sleep(200);
49 } catch (InterruptedException e) 53 } catch (InterruptedException e)
50 { 54 {
51 throw new RuntimeException(e); 55 throw new RuntimeException(e);
52 } 56 }
53 } while (jsEngine.evaluate("this.foo").isUndefined()); 57 } while (jsEngine.evaluate("this.foo").isUndefined());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ServerResponse.NsStatus.OK.getStatusCode(), 105 ServerResponse.NsStatus.OK.getStatusCode(),
102 jsEngine.evaluate("request.channel.status").asLong()); 106 jsEngine.evaluate("request.channel.status").asLong());
103 107
104 assertEquals(200l, jsEngine.evaluate("request.status").asLong()); 108 assertEquals(200l, jsEngine.evaluate("request.status").asLong());
105 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)") .asString()); 109 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)") .asString());
106 assertEquals( 110 assertEquals(
107 "text/plain", 111 "text/plain",
108 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr( 0,10)").asString()); 112 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr( 0,10)").asString());
109 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").is Null()); 113 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").is Null());
110 } 114 }
115
116 @Test
117 public void testGetElemhideElements() throws MalformedURLException, Interrup tedException {
118 FilterEngine filterEngine = new FilterEngine(jsEngine);
119
120 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded
121
122 final String url = "www.mobile01.com/somepage.html";
123
124 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null);
125 assertFalse(isDocumentWhitelisted);
126
127 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null);
128 assertFalse(isElemhideWhitelisted);
129
130 List<String> selectors = filterEngine.getElementHidingSelectors(url);
131 assertNotNull(selectors);
132 assertTrue(selectors.size() > 0);
133 }
111 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld