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

Delta Between Two Patch Sets: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/AndroidWebRequestTest.java

Issue 29536604: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Left Patch Set: Created Sept. 5, 2017, 12:28 p.m.
Right Patch Set: address comment Created Sept. 7, 2017, 12:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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
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 // creating not used anywhere FilterEngine object is not as useless as it seems: 31 // It inherits the fixture instantiating FilterEngine which is not explicitly
32 // it loads compat.js JsEngine to add XMLHttpRequest class support 32 // 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 // FilterEngine.
sergei 2017/09/07 12:55:54 As discussed in IRC, it's not removed, it's change
anton 2017/09/07 12:57:48 LGTM
33 public class AndroidWebRequestTest extends BaseFilterEngineTest 35 public class AndroidWebRequestTest extends BaseFilterEngineTest
34 { 36 {
35 @Override 37 @Override
36 protected WebRequest createWebRequest() 38 protected WebRequest createWebRequest()
37 { 39 {
38 return new AndroidWebRequest(true, true); 40 return new AndroidWebRequest(true, true);
39 } 41 }
40 42
41 @Test 43 @Test
42 public void testRealWebRequest() 44 public void testRealWebRequest()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {
84 jsEngine.evaluate( 86 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
85 "var result;\n" + 87 "var result;\n" +
86 "var request = new XMLHttpRequest();\n" + 88 "var request = new XMLHttpRequest();\n" +
87 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" + 89 "request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist. txt');\n" +
88 "request.setRequestHeader('X', 'Y');\n" + 90 "request.setRequestHeader('X', 'Y');\n" +
89 "request.setRequestHeader('X2', 'Y2');\n" + 91 "request.setRequestHeader('X2', 'Y2');\n" +
90 "request.overrideMimeType('text/plain');\n" + 92 "request.overrideMimeType('text/plain');\n" +
91 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" + 93 "request.addEventListener('load',function() {result=request.responseText;} , false);\n" +
92 "request.addEventListener('error',function() {result='error';}, false);\n" + 94 "request.addEventListener('error',function() {result='error';}, false);\n" +
93 "request.send(null);"); 95 "request.send(null);");
94 96
(...skipping 17 matching lines...) Expand all
112 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)").asS tring()); 114 assertEquals("[Adblock Plus ", jsEngine.evaluate("result.substr(0, 14)").asS tring());
113 assertEquals( 115 assertEquals(
114 "text/plain", 116 "text/plain",
115 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(0, 10) ").asString()); 117 jsEngine.evaluate("request.getResponseHeader('Content-Type').substr(0, 10) ").asString());
116 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").isNull ()); 118 assertTrue(jsEngine.evaluate("request.getResponseHeader('Location')").isNull ());
117 } 119 }
118 120
119 @Test 121 @Test
120 public void testGetElemhideElements() throws MalformedURLException, Interrupte dException 122 public void testGetElemhideElements() throws MalformedURLException, Interrupte dException
121 { 123 {
122 Thread.sleep(20 * 1000); // wait for the subscription to be downloaded 124 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
123 125
124 final String url = "www.mobile01.com/somepage.html"; 126 final String url = "www.mobile01.com/somepage.html";
125 127
126 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null ); 128 boolean isDocumentWhitelisted = filterEngine.isDocumentWhitelisted(url, null );
127 assertFalse(isDocumentWhitelisted); 129 assertFalse(isDocumentWhitelisted);
128 130
129 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null ); 131 boolean isElemhideWhitelisted = filterEngine.isElemhideWhitelisted(url, null );
130 assertFalse(isElemhideWhitelisted); 132 assertFalse(isElemhideWhitelisted);
131 133
132 List<String> selectors = filterEngine.getElementHidingSelectors(url); 134 List<String> selectors = filterEngine.getElementHidingSelectors(url);
133 assertNotNull(selectors); 135 assertNotNull(selectors);
134 assertTrue(selectors.size() > 0); 136 assertTrue(selectors.size() > 0);
135 } 137 }
136 } 138 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld