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 29536629: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: address comment Created Sept. 8, 2017, 12:20 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-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 // It inherits the fixture instantiating FilterEngine which is not explicitly 32 // 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 // 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 // which is defined in compat.js, but the latter is properly loaded by
34 // FilterEngine. 35 // FilterEngine.
35 public class AndroidWebRequestTest extends BaseFilterEngineTest 36 public class AndroidWebRequestTest extends BaseFilterEngineTest
36 { 37 {
37 @Override 38 @Override
38 protected WebRequest createWebRequest() 39 protected WebRequest createWebRequest()
39 { 40 {
40 return new AndroidWebRequest(true, true); 41 return new AndroidWebRequest(true, true);
41 } 42 }
42 43
43 @Test 44 @Test
44 public void testRealWebRequest() 45 public void testRealWebRequest()
45 { 46 {
47 JsEngine jsEngine = platform.getJsEngine();
46 // This URL should redirect to easylist-downloads.adblockplus.org and we 48 // This URL should redirect to easylist-downloads.adblockplus.org and we
47 // should get the actual filter list back. 49 // should get the actual filter list back.
48 jsEngine.evaluate( 50 jsEngine.evaluate(
49 "let foo; _webRequest.GET('https://easylist-downloads.adblockplus.org/easy list.txt', {}, " + 51 "let foo; _webRequest.GET('https://easylist-downloads.adblockplus.org/easy list.txt', {}, " +
50 "function(result) {foo = result;} )"); 52 "function(result) {foo = result;} )");
51 do 53 do
52 { 54 {
53 try 55 try
54 { 56 {
55 Thread.sleep(200); 57 Thread.sleep(200);
(...skipping 20 matching lines...) Expand all
76 assertTrue(jsHeaders.isObject()); 78 assertTrue(jsHeaders.isObject());
77 assertEquals( 79 assertEquals(
78 "text/plain", 80 "text/plain",
79 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS tring()); 81 jsEngine.evaluate("foo.responseHeaders['content-type'].substr(0, 10)").asS tring());
80 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined( )); 82 assertTrue(jsEngine.evaluate("foo.responseHeaders['location']").isUndefined( ));
81 } 83 }
82 84
83 @Test 85 @Test
84 public void testXMLHttpRequest() 86 public void testXMLHttpRequest()
85 { 87 {
88 JsEngine jsEngine = platform.getJsEngine();
86 jsEngine.evaluate( 89 jsEngine.evaluate(
87 "var result;\n" + 90 "var result;\n" +
88 "var request = new XMLHttpRequest();\n" + 91 "var request = new XMLHttpRequest();\n" +
89 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" + 92 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" +
90 "request.setRequestHeader('X', 'Y');\n" + 93 "request.setRequestHeader('X', 'Y');\n" +
91 "request.setRequestHeader('X2', 'Y2');\n" + 94 "request.setRequestHeader('X2', 'Y2');\n" +
92 "request.overrideMimeType('text/plain');\n" + 95 "request.overrideMimeType('text/plain');\n" +
93 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" + 96 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" +
94 "request.addEventListener('error',function() {result='error';}, false);\n" + 97 "request.addEventListener('error',function() {result='error';}, false);\n" +
95 "request.send(null);"); 98 "request.send(null);");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 assertFalse(isDocumentWhitelisted); 132 assertFalse(isDocumentWhitelisted);
130 133
131 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null ); 134 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null );
132 assertFalse(isElemhideWhitelisted); 135 assertFalse(isElemhideWhitelisted);
133 136
134 List<String> selectors = filterEngine.getElementHidingSelectors(url); 137 List<String> selectors = filterEngine.getElementHidingSelectors(url);
135 assertNotNull(selectors); 138 assertNotNull(selectors);
136 assertTrue(selectors.size() > 0); 139 assertTrue(selectors.size() > 0);
137 } 140 }
138 } 141 }
OLDNEW
« no previous file with comments | « dependencies ('k') | libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AppInfoJsObjectTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld