Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-present eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
18 package org.adblockplus.libadblockplus; | |
19 | |
20 import android.os.SystemClock; | |
21 import android.util.Log; | |
22 | |
23 import java.util.List; | |
24 | |
25 public abstract class BaseFilterEngineTest extends BaseJsEngineTest | |
26 { | |
27 private final static String TAG = BaseFilterEngineTest.class.getSimpleName(); | |
28 protected final static int UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS = 5 * 1000; | |
29 protected final static int UPDATE_SUBSCRIPTIONS_WAIT_CHUNKS = 50; | |
30 | |
31 @Override | |
32 protected void setUp() throws Exception | |
33 { | |
34 super.setUp(); | |
35 this.setupFilterEngine(); | |
36 } | |
37 | |
38 protected int getUpdateRequestCount() | |
39 { | |
40 return 0; | |
41 } | |
42 | |
43 protected int updateSubscriptions() | |
44 { | |
45 return updateSubscriptions(false); | |
46 } | |
47 | |
48 protected int updateSubscriptions(boolean noWait) | |
49 { | |
50 final int init = getUpdateRequestCount(); | |
51 | |
52 List<Subscription> subscriptions = filterEngine.getListedSubscriptions(); | |
53 final int num = subscriptions.size(); | |
54 for (final Subscription s : subscriptions) | |
55 { | |
56 try | |
57 { | |
58 s.updateFilters(); | |
59 } | |
60 finally | |
61 { | |
62 s.dispose(); | |
63 } | |
64 } | |
65 | |
66 if (!noWait) | |
67 { | |
68 for (int i = 0; i < UPDATE_SUBSCRIPTIONS_WAIT_CHUNKS; i++) | |
69 { | |
70 if (getUpdateRequestCount() - init >= num) | |
71 { | |
72 break; | |
73 } | |
74 SystemClock.sleep(UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS / UPDATE_SUBSCRIPTI ONS_WAIT_CHUNKS); | |
75 } | |
76 } | |
77 | |
78 return num; | |
79 } | |
80 | |
81 public boolean removeListedSubscriptions() | |
82 { | |
83 while (filterEngine.getListedSubscriptions().size() > 0) | |
84 { | |
85 int prev = filterEngine.getListedSubscriptions().size(); | |
86 filterEngine.getListedSubscriptions().get(0).removeFromList(); | |
anton
2018/09/17 06:55:13
isn't it better to return `boolean` for `removeFro
| |
87 if (prev == filterEngine.getListedSubscriptions().size()) | |
anton
2018/10/16 13:24:55
this still looks suspicious.
sergey: "removing sho
| |
88 { | |
89 Log.e(TAG, "Failed to clear listed subscriptions."); | |
90 return false; | |
91 } | |
92 } | |
93 return true; | |
94 } | |
95 } | |
anton
2018/10/18 11:40:13
the file does not correspond to last revision of f
| |
OLD | NEW |