| 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 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 25 import org.adblockplus.libadblockplus.JsValue; | 25 import org.adblockplus.libadblockplus.JsValue; | 
| 26 import org.adblockplus.libadblockplus.LazyLogSystem; | 26 import org.adblockplus.libadblockplus.LazyLogSystem; | 
| 27 import org.adblockplus.libadblockplus.LazyWebRequest; | 27 import org.adblockplus.libadblockplus.LazyWebRequest; | 
| 28 import org.adblockplus.libadblockplus.ServerResponse; | 28 import org.adblockplus.libadblockplus.ServerResponse; | 
| 29 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; | 29 import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; | 
| 30 | 30 | 
| 31 import org.junit.Test; | 31 import org.junit.Test; | 
| 32 | 32 | 
| 33 import java.util.List; | 33 import java.util.List; | 
| 34 | 34 | 
| 35 public class UpdateCheckTest extends BaseJsTest | 35 public class UpdateCheckTest extends BaseFilterEngineTest | 
| 36 { | 36 { | 
| 37   protected String previousRequestUrl; | 37   protected String previousRequestUrl; | 
| 38 | 38 | 
| 39   public class TestWebRequest extends LazyWebRequest | 39   public class TestWebRequest extends LazyWebRequest | 
| 40   { | 40   { | 
| 41     public ServerResponse response = new ServerResponse(); | 41     public ServerResponse response = new ServerResponse(); | 
| 42 | 42 | 
| 43     @Override | 43     @Override | 
| 44     public ServerResponse httpGET(String url, List<HeaderEntry> headers) | 44     public ServerResponse httpGET(String url, List<HeaderEntry> headers) | 
| 45     { | 45     { | 
| 46       if (url.indexOf("easylist") >= 0) | 46       if (url.indexOf("easylist") >= 0) | 
| 47       { | 47       { | 
| 48         return super.httpGET(url, headers); | 48         return super.httpGET(url, headers); | 
| 49       } | 49       } | 
| 50 | 50 | 
| 51       previousRequestUrl = url; | 51       previousRequestUrl = url; | 
| 52       return response; | 52       return response; | 
| 53     } | 53     } | 
| 54   } | 54   } | 
| 55 | 55 | 
| 56   protected AppInfo appInfo; | 56   protected AppInfo appInfo; | 
| 57   protected TestWebRequest webRequest; | 57   protected TestWebRequest webRequest; | 
| 58   protected JsEngine jsEngine; |  | 
| 59   protected FilterEngine filterEngine; |  | 
| 60 | 58 | 
| 61   protected boolean eventCallbackCalled; | 59   protected boolean eventCallbackCalled; | 
| 62   protected List<JsValue> eventCallbackParams; | 60   protected List<JsValue> eventCallbackParams; | 
| 63   protected boolean updateCallbackCalled; | 61   protected boolean updateCallbackCalled; | 
| 64   protected String updateError; | 62   protected String updateError; | 
| 65 | 63 | 
| 66   private EventCallback eventCallback = new EventCallback() | 64   private EventCallback eventCallback = new EventCallback() | 
| 67   { | 65   { | 
| 68     @Override | 66     @Override | 
| 69     public void eventCallback(List<JsValue> params) | 67     public void eventCallback(List<JsValue> params) | 
| 70     { | 68     { | 
| 71       eventCallbackCalled = true; | 69       eventCallbackCalled = true; | 
| 72       eventCallbackParams = params; | 70       eventCallbackParams = params; | 
| 73     } | 71     } | 
| 74   }; | 72   }; | 
| 75 | 73 | 
| 76   private UpdateCheckDoneCallback updateCallback = new UpdateCheckDoneCallback() | 74   private UpdateCheckDoneCallback updateCallback = new UpdateCheckDoneCallback() | 
| 77   { | 75   { | 
| 78     @Override | 76     @Override | 
| 79     public void updateCheckDoneCallback(String error) | 77     public void updateCheckDoneCallback(String error) | 
| 80     { | 78     { | 
| 81       updateCallbackCalled = true; | 79       updateCallbackCalled = true; | 
| 82       updateError = error; | 80       updateError = error; | 
| 83     } | 81     } | 
| 84   }; | 82   }; | 
| 85 | 83 | 
| 86   public void reset() | 84   public void reset() throws InterruptedException | 
| 87   { | 85   { | 
|  | 86     disposeFilterEngine(); | 
|  | 87     if (jsEngine != null) | 
|  | 88     { | 
|  | 89       jsEngine.dispose(); | 
|  | 90     } | 
| 88     jsEngine = new JsEngine(appInfo, new LazyLogSystem(), webRequest, | 91     jsEngine = new JsEngine(appInfo, new LazyLogSystem(), webRequest, | 
| 89         getContext().getFilesDir().getAbsolutePath()); | 92         getContext().getFilesDir().getAbsolutePath()); | 
| 90     jsEngine.setEventCallback("updateAvailable", eventCallback); | 93     jsEngine.setEventCallback("updateAvailable", eventCallback); | 
| 91 |  | 
| 92     filterEngine = new FilterEngine(jsEngine); | 94     filterEngine = new FilterEngine(jsEngine); | 
| 93   } | 95   } | 
| 94 | 96 | 
| 95   @Override | 97   @Override | 
| 96   protected void setUp() throws Exception | 98   protected void setUp() throws Exception | 
| 97   { | 99   { | 
| 98     super.setUp(); |  | 
| 99 |  | 
| 100     appInfo = AppInfo.builder().build(); | 100     appInfo = AppInfo.builder().build(); | 
| 101     webRequest = new TestWebRequest(); | 101     webRequest = new TestWebRequest(); | 
| 102     eventCallbackCalled = false; | 102     eventCallbackCalled = false; | 
| 103     updateCallbackCalled = false; | 103     updateCallbackCalled = false; | 
| 104     reset(); | 104     reset(); | 
| 105   } | 105   } | 
| 106 | 106 | 
| 107   public void forceUpdateCheck() | 107   public void forceUpdateCheck() | 
| 108   { | 108   { | 
| 109     filterEngine.forceUpdateCheck(updateCallback); | 109     filterEngine.forceUpdateCheck(updateCallback); | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 256     reset(); | 256     reset(); | 
| 257     forceUpdateCheck(); | 257     forceUpdateCheck(); | 
| 258 | 258 | 
| 259     Thread.sleep(1000); | 259     Thread.sleep(1000); | 
| 260 | 260 | 
| 261     assertFalse(eventCallbackCalled); | 261     assertFalse(eventCallbackCalled); | 
| 262     assertTrue(updateCallbackCalled); | 262     assertTrue(updateCallbackCalled); | 
| 263     assertTrue(updateError.length() > 0); | 263     assertTrue(updateError.length() > 0); | 
| 264   } | 264   } | 
| 265 } | 265 } | 
| OLD | NEW | 
|---|