| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 import java.util.HashSet; | 33 import java.util.HashSet; |
| 34 import java.util.LinkedList; | 34 import java.util.LinkedList; |
| 35 import java.util.List; | 35 import java.util.List; |
| 36 import java.util.Map; | 36 import java.util.Map; |
| 37 import java.util.Set; | 37 import java.util.Set; |
| 38 | 38 |
| 39 public class AndroidWebRequestResourceWrapperTest extends FilterEngineGenericTes t | 39 public class AndroidWebRequestResourceWrapperTest extends FilterEngineGenericTes t |
| 40 { | 40 { |
| 41 private static final int UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS = 5 * 1000; // 5s | 41 private static final int UPDATE_SUBSCRIPTIONS_WAIT_DELAY_MS = 5 * 1000; // 5s |
| 42 | 42 |
| 43 private class TestRequest extends AndroidWebRequest | 43 private static final class TestRequest extends AndroidWebRequest |
|
diegocarloslima
2017/04/27 18:57:46
This inner class can be static
anton
2017/04/28 06:04:48
Acknowledged.
Also it can be final. Taking into ac
anton
2017/04/28 06:10:35
uploaded new patch set
| |
| 44 { | 44 { |
| 45 private List<String> urls = new LinkedList<String>(); | 45 private List<String> urls = new LinkedList<String>(); |
| 46 | 46 |
| 47 public List<String> getUrls() | 47 public List<String> getUrls() |
| 48 { | 48 { |
| 49 return urls; | 49 return urls; |
| 50 } | 50 } |
| 51 | 51 |
| 52 @Override | 52 @Override |
| 53 public ServerResponse httpGET(String urlStr, List<HeaderEntry> headers) | 53 public ServerResponse httpGET(String urlStr, List<HeaderEntry> headers) |
| 54 { | 54 { |
| 55 urls.add(urlStr); | 55 urls.add(urlStr); |
| 56 return super.httpGET(urlStr, headers); | 56 return super.httpGET(urlStr, headers); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 // in-memory storage for testing only | 60 // in-memory storage for testing only |
| 61 private class TestStorage implements AndroidWebRequestResourceWrapper.Storage | 61 private static final class TestStorage implements AndroidWebRequestResourceWra pper.Storage |
|
diegocarloslima
2017/04/27 18:57:46
This inner class can be static
anton
2017/04/28 06:04:49
Acknowledged.
| |
| 62 { | 62 { |
| 63 private Set<String> interceptedUrls = new HashSet<String>(); | 63 private Set<String> interceptedUrls = new HashSet<String>(); |
| 64 | 64 |
| 65 public Set<String> getInterceptedUrls() | 65 public Set<String> getInterceptedUrls() |
| 66 { | 66 { |
| 67 return interceptedUrls; | 67 return interceptedUrls; |
| 68 } | 68 } |
| 69 | 69 |
| 70 @Override | 70 @Override |
| 71 public synchronized void put(String url) | 71 public synchronized void put(String url) |
| 72 { | 72 { |
| 73 interceptedUrls.add(url); | 73 interceptedUrls.add(url); |
| 74 } | 74 } |
| 75 | 75 |
| 76 @Override | 76 @Override |
| 77 public synchronized boolean contains(String url) | 77 public synchronized boolean contains(String url) |
| 78 { | 78 { |
| 79 return interceptedUrls.contains(url); | 79 return interceptedUrls.contains(url); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 private class TestWrapperListener implements AndroidWebRequestResourceWrapper. Listener | 83 private static final class TestWrapperListener implements AndroidWebRequestRes ourceWrapper.Listener |
|
diegocarloslima
2017/04/27 18:57:46
This inner class can be static
anton
2017/04/28 06:04:48
Acknowledged.
| |
| 84 { | 84 { |
| 85 private Map<String, Integer> urlsToResourceId = new HashMap<String, Integer> (); | 85 private Map<String, Integer> urlsToResourceId = new HashMap<String, Integer> (); |
| 86 | 86 |
| 87 public Map<String, Integer> getUrlsToResourceId() | 87 public Map<String, Integer> getUrlsToResourceId() |
| 88 { | 88 { |
| 89 return urlsToResourceId; | 89 return urlsToResourceId; |
| 90 } | 90 } |
| 91 | 91 |
| 92 @Override | 92 @Override |
| 93 public void onIntercepted(String url, int resourceId) | 93 public void onIntercepted(String url, int resourceId) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 111 preloadMap = new HashMap<String, Integer>(); | 111 preloadMap = new HashMap<String, Integer>(); |
| 112 storage = new TestStorage(); | 112 storage = new TestStorage(); |
| 113 wrapper = new AndroidWebRequestResourceWrapper( | 113 wrapper = new AndroidWebRequestResourceWrapper( |
| 114 getInstrumentation().getContext(), request, preloadMap, storage); | 114 getInstrumentation().getContext(), request, preloadMap, storage); |
| 115 wrapperListener = new TestWrapperListener(); | 115 wrapperListener = new TestWrapperListener(); |
| 116 wrapper.setListener(wrapperListener); | 116 wrapper.setListener(wrapperListener); |
| 117 | 117 |
| 118 jsEngine.setWebRequest(wrapper); | 118 jsEngine.setWebRequest(wrapper); |
| 119 } | 119 } |
| 120 | 120 |
| 121 private void updateSubscriptions() | 121 private void updateSubscriptions() |
|
anton
2017/04/13 13:51:41
actually it's copy-paste from AdblockEngine but it
diegocarloslima
2017/04/27 18:57:46
Yeah, since it's just for testing... I think you c
anton
2017/04/28 06:04:48
Acknowledged.
| |
| 122 { | 122 { |
| 123 for (final Subscription s : this.filterEngine.getListedSubscriptions()) | 123 for (final Subscription s : this.filterEngine.getListedSubscriptions()) |
| 124 { | 124 { |
| 125 try | 125 try |
| 126 { | 126 { |
| 127 s.updateFilters(); | 127 s.updateFilters(); |
| 128 } | 128 } |
| 129 finally | 129 finally |
| 130 { | 130 { |
| 131 s.dispose(); | 131 s.dispose(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 { | 175 { |
| 176 if (Utils.getUrlWithoutParams(eachString).equals(preloadUrl)) | 176 if (Utils.getUrlWithoutParams(eachString).equals(preloadUrl)) |
| 177 { | 177 { |
| 178 assertEquals(resourceId, wrapperListener.getUrlsToResourceId().get(eachS tring).intValue()); | 178 assertEquals(resourceId, wrapperListener.getUrlsToResourceId().get(eachS tring).intValue()); |
| 179 break; | 179 break; |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 @Test | 184 @Test |
| 185 public void testIntercepted_Easylist() | 185 public void testIntercepted_Easylist() |
|
diegocarloslima
2017/04/27 18:57:46
Why there's this underscore on the method name? I
anton
2017/04/28 06:04:48
"testIntercepted" is a general test direction (for
diegocarloslima
2017/04/28 12:54:35
Acknowledged.
| |
| 186 { | 186 { |
| 187 testIntercepted( | 187 testIntercepted( |
| 188 AndroidWebRequestResourceWrapper.EASYLIST, R.raw.easylist); | 188 AndroidWebRequestResourceWrapper.EASYLIST, R.raw.easylist); |
| 189 } | 189 } |
| 190 | 190 |
| 191 @Test | 191 @Test |
| 192 public void testIntercepted_AcceptableAds() | 192 public void testIntercepted_AcceptableAds() |
|
diegocarloslima
2017/04/27 18:57:47
Same here, I think you should stick to the camelCa
anton
2017/04/28 06:04:48
Replied above
| |
| 193 { | 193 { |
| 194 testIntercepted( | 194 testIntercepted( |
| 195 AndroidWebRequestResourceWrapper.ACCEPTABLE_ADS, R.raw.exceptionrules); | 195 AndroidWebRequestResourceWrapper.ACCEPTABLE_ADS, R.raw.exceptionrules); |
| 196 } | 196 } |
| 197 | 197 |
| 198 @Test | 198 @Test |
| 199 public void testIntercepted_OnceOnly() | 199 public void testIntercepted_OnceOnly() |
|
diegocarloslima
2017/04/27 18:57:46
Same here, I think you should stick to the camelCa
anton
2017/04/28 06:04:49
Replied above
| |
| 200 { | 200 { |
| 201 final String preloadUrl = AndroidWebRequestResourceWrapper.EASYLIST; | 201 final String preloadUrl = AndroidWebRequestResourceWrapper.EASYLIST; |
| 202 | 202 |
| 203 preloadMap.clear(); | 203 preloadMap.clear(); |
| 204 preloadMap.put(preloadUrl, R.raw.easylist); | 204 preloadMap.put(preloadUrl, R.raw.easylist); |
| 205 | 205 |
| 206 assertEquals(0, request.getUrls().size()); | 206 assertEquals(0, request.getUrls().size()); |
| 207 | 207 |
| 208 assertEquals(0, storage.getInterceptedUrls().size()); | 208 assertEquals(0, storage.getInterceptedUrls().size()); |
| 209 | 209 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 } | 323 } |
| 324 | 324 |
| 325 @Test | 325 @Test |
| 326 public void testNotIntercepted_AcceptableAds() | 326 public void testNotIntercepted_AcceptableAds() |
| 327 { | 327 { |
| 328 testNotIntercepted( | 328 testNotIntercepted( |
| 329 AndroidWebRequestResourceWrapper.EASYLIST, R.raw.easylist, | 329 AndroidWebRequestResourceWrapper.EASYLIST, R.raw.easylist, |
| 330 AndroidWebRequestResourceWrapper.ACCEPTABLE_ADS); | 330 AndroidWebRequestResourceWrapper.ACCEPTABLE_ADS); |
| 331 } | 331 } |
| 332 } | 332 } |
| LEFT | RIGHT |