| 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 |
| 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 android.os.SystemClock; | 20 import android.os.SystemClock; |
| 21 | 21 |
| 22 import org.adblockplus.libadblockplus.AppInfo; |
| 22 import org.adblockplus.libadblockplus.FilterEngine; | 23 import org.adblockplus.libadblockplus.FilterEngine; |
| 23 import org.adblockplus.libadblockplus.HeaderEntry; | 24 import org.adblockplus.libadblockplus.HeaderEntry; |
| 24 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback; | 25 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback; |
| 26 import org.adblockplus.libadblockplus.JsEngine; |
| 25 import org.adblockplus.libadblockplus.ServerResponse; | 27 import org.adblockplus.libadblockplus.ServerResponse; |
| 26 import org.adblockplus.libadblockplus.Subscription; | 28 import org.adblockplus.libadblockplus.Subscription; |
| 27 import org.adblockplus.libadblockplus.WebRequest; | 29 import org.adblockplus.libadblockplus.WebRequest; |
| 28 import org.adblockplus.libadblockplus.android.AndroidWebRequest; | 30 import org.adblockplus.libadblockplus.android.AndroidWebRequest; |
| 29 import org.junit.Test; | 31 import org.junit.Test; |
| 30 | 32 |
| 31 import java.util.LinkedList; | 33 import java.util.LinkedList; |
| 32 import java.util.List; | 34 import java.util.List; |
| 33 | 35 |
| 34 public class IsAllowedConnectionCallbackTest extends BaseJsTest | 36 public class IsAllowedConnectionCallbackTest extends BaseFilterEngineTest |
| 35 { | 37 { |
| 36 private static final int UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS = 5 * 1000; // 5s | 38 private static final int UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS = 5 * 1000; // 5s |
| 37 | 39 |
| 38 private static final class TestRequest extends AndroidWebRequest | 40 private static final class TestRequest extends AndroidWebRequest |
| 39 { | 41 { |
| 40 private List<String> urls = new LinkedList<String>(); | 42 private List<String> urls = new LinkedList<String>(); |
| 41 | 43 |
| 42 public List<String> getUrls() | 44 public List<String> getUrls() |
| 43 { | 45 { |
| 44 return urls; | 46 return urls; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 { | 85 { |
| 84 this.invoked = true; | 86 this.invoked = true; |
| 85 this.connectionType = connectionType; | 87 this.connectionType = connectionType; |
| 86 | 88 |
| 87 return result; | 89 return result; |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 | 92 |
| 91 private TestRequest request; | 93 private TestRequest request; |
| 92 private TestCallback callback; | 94 private TestCallback callback; |
| 93 private FilterEngine filterEngine; | |
| 94 | 95 |
| 95 @Override | 96 @Override |
| 96 protected void setUp() throws Exception | 97 protected void setUp() throws Exception |
| 97 { | 98 { |
| 98 super.setUp(); | 99 jsEngine = new JsEngine(AppInfo.builder().build(), createLogSystem(), create
WebRequest(), |
| 99 | 100 getContext().getFilesDir().getAbsolutePath()); |
| 100 callback = new TestCallback(); | 101 callback = new TestCallback(); |
| 101 filterEngine = new FilterEngine(jsEngine, callback); | 102 filterEngine = new FilterEngine(jsEngine, callback); |
| 102 } | 103 } |
| 103 | 104 |
| 104 @Override | 105 @Override |
| 105 protected WebRequest createWebRequest() | 106 protected WebRequest createWebRequest() |
| 106 { | 107 { |
| 107 return request = new TestRequest(); | 108 return request = new TestRequest(); |
| 108 } | 109 } |
| 109 | 110 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 updateSubscriptions(); | 155 updateSubscriptions(); |
| 155 SystemClock.sleep(UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS); | 156 SystemClock.sleep(UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS); |
| 156 | 157 |
| 157 assertTrue(callback.isInvoked()); | 158 assertTrue(callback.isInvoked()); |
| 158 assertNotNull(callback.getConnectionType()); | 159 assertNotNull(callback.getConnectionType()); |
| 159 assertEquals(allowedConnectionType, callback.getConnectionType()); | 160 assertEquals(allowedConnectionType, callback.getConnectionType()); |
| 160 | 161 |
| 161 assertEquals(0, request.getUrls().size()); | 162 assertEquals(0, request.getUrls().size()); |
| 162 } | 163 } |
| 163 } | 164 } |
| OLD | NEW |