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 29351744: Issue 4399 - Add WebView inheritor with ad blocking (Closed)
Patch Set: added enabled/disabled property Created Oct. 10, 2016, 2:04 p.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.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.net.URL;
29 import java.util.List;
30
26 public class AndroidWebRequestTest extends BaseJsTest 31 public class AndroidWebRequestTest extends BaseJsTest
27 { 32 {
28 @Override 33 @Override
29 protected void setUp() throws Exception 34 protected void setUp() throws Exception
30 { 35 {
31 super.setUp(); 36 super.setUp();
32 37
33 jsEngine.setWebRequest(new AndroidWebRequest()); 38 jsEngine.setWebRequest(new AndroidWebRequest(true));
34 } 39 }
35 40
36 @Test 41 @Test
37 public void testRealWebRequest() 42 public void testRealWebRequest()
38 { 43 {
39 // This URL should redirect to easylist-downloads.adblockplus.org and we 44 // This URL should redirect to easylist-downloads.adblockplus.org and we
40 // should get the actual filter list back. 45 // should get the actual filter list back.
41 jsEngine.evaluate( 46 jsEngine.evaluate(
42 "_webRequest.GET('https://easylist-downloads.adblockplus.org/easylis t.txt', {}, " + 47 "_webRequest.GET('https://easylist-downloads.adblockplus.org/easylis t.txt', {}, " +
43 "function(result) {foo = result;} )"); 48 "function(result) {foo = result;} )");
44 do 49 do
45 { 50 {
46 try 51 try
47 { 52 {
48 Thread.sleep(200); 53 Thread.sleep(200);
49 } catch (InterruptedException e) 54 } catch (InterruptedException e)
50 { 55 {
51 throw new RuntimeException(e); 56 throw new RuntimeException(e);
52 } 57 }
53 } while (jsEngine.evaluate("this.foo").isUndefined()); 58 } while (jsEngine.evaluate("this.foo").isUndefined());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ServerResponse.NsStatus.OK.getStatusCode(), 106 ServerResponse.NsStatus.OK.getStatusCode(),
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 }
116
117 @Test
118 public void testGetElemhideElements() throws MalformedURLException, Interrup tedException {
119 FilterEngine filterEngine = new FilterEngine(jsEngine);
120
121 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded
122
123 final String url = "www.mobile01.com/somepage.html";
124
125 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null);
126 assertFalse(isDocumentWhitelisted);
127
128 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null);
129 assertFalse(isElemhideWhitelisted);
130
131 List<String> selectors = filterEngine.getElementHidingSelectors(url);
132 assertNotNull(selectors);
133 assertTrue(selectors.size() > 0);
134 }
111 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld