Chromium Code Reviews| Index: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java |
| diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java |
| index f9bc08c08f2be1b17cbc77e642f11930a84781fc..515f412254bb12de9ff3bcc5174f0fb0d2b2ab36 100644 |
| --- a/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java |
| +++ b/chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java |
| @@ -5,6 +5,7 @@ |
| package org.chromium.chrome.browser.webapps; |
| import static org.junit.Assert.assertEquals; |
| +import static org.junit.Assert.assertFalse; |
| import static org.junit.Assert.assertTrue; |
| import android.content.Context; |
| @@ -63,6 +64,10 @@ public class WebappDataStorageTest { |
| updateTime(currentTime); |
| } |
| + public void advance(long millis) { |
| + mCurrentTime += millis; |
| + } |
| + |
| public void updateTime(long currentTime) { |
| mCurrentTime = currentTime; |
| } |
| @@ -315,6 +320,68 @@ public class WebappDataStorageTest { |
| mSharedPreferences.getBoolean(WebappDataStorage.KEY_IS_ICON_GENERATED, true)); |
| } |
| + @Test |
| + public void testShouldUpdateIfRelaxedUpdatesAndNoPriorWebApkUpdate() { |
| + assertTrue(WebappDataStorage.RELAXED_UPDATE_INTERVAL > WebappDataStorage.UPDATE_INTERVAL); |
| + |
| + final TestClock clock = new TestClock(System.currentTimeMillis()); |
| + WebappDataStorage.setClockForTests(clock); |
| + |
|
pkotwicz
2017/03/04 00:20:47
Nit: Remove new line
Xi Han
2017/03/06 22:14:21
Done.
|
| + WebappDataStorage storage = WebappDataStorage.open("test"); |
| + |
| + // Done when WebAPK is registered in {@link WebApkActivity}. |
| + storage.updateTimeOfLastCheckForUpdatedWebManifest(); |
|
pkotwicz
2017/03/04 00:20:47
Nit: Can you please add a new line? This way it is
Xi Han
2017/03/06 22:14:20
Done.
|
| + storage.setRelaxedUpdates(true); |
| + |
| + clock.advance(WebappDataStorage.UPDATE_INTERVAL); |
| + assertFalse(storage.shouldUpdate()); |
| + clock.advance( |
| + WebappDataStorage.RELAXED_UPDATE_INTERVAL - WebappDataStorage.UPDATE_INTERVAL); |
| + assertTrue(storage.shouldUpdate()); |
| + } |
| + |
| + @Test |
| + public void testShouldUpdateIfRegularUpdatesAndNoPriorWebApkUpdate() { |
| + assertTrue(WebappDataStorage.RELAXED_UPDATE_INTERVAL > WebappDataStorage.UPDATE_INTERVAL); |
| + |
| + final TestClock clock = new TestClock(System.currentTimeMillis()); |
| + WebappDataStorage.setClockForTests(clock); |
| + |
|
pkotwicz
2017/03/04 00:20:47
Nit: Remove new line
Xi Han
2017/03/06 22:14:20
Done.
|
| + WebappDataStorage storage = WebappDataStorage.open("test"); |
| + |
| + // Done when WebAPK is registered in {@link WebApkActivity}. |
| + storage.updateTimeOfLastCheckForUpdatedWebManifest(); |
| + storage.setRelaxedUpdates(false); |
| + |
| + assertFalse(storage.shouldUpdate()); |
| + clock.advance(WebappDataStorage.UPDATE_INTERVAL); |
| + assertTrue(storage.shouldUpdate()); |
| + } |
| + |
| + @Test |
| + public void testShouldUpdateIfPriorWebApkUpdateFailed() { |
| + assertTrue(WebappDataStorage.RELAXED_UPDATE_INTERVAL > WebappDataStorage.UPDATE_INTERVAL); |
|
pkotwicz
2017/03/04 00:20:47
Is this assertion relevant to this test?
Xi Han
2017/03/06 22:14:21
Good catch, removed.
|
| + |
| + final TestClock clock = new TestClock(System.currentTimeMillis()); |
| + WebappDataStorage.setClockForTests(clock); |
| + |
|
pkotwicz
2017/03/04 00:20:47
Nit: Remove new line
Xi Han
2017/03/06 22:14:21
Done.
|
| + WebappDataStorage storage = WebappDataStorage.open("test"); |
| + |
| + storage.updateTimeOfLastCheckForUpdatedWebManifest(); |
| + storage.updateTimeOfLastWebApkUpdateRequestCompletion(); |
| + storage.updateDidLastWebApkUpdateRequestSucceed(false); |
| + |
| + assertFalse(storage.shouldUpdate()); |
| + clock.advance(WebappDataStorage.RETRY_UPDATE_DURATION); |
| + |
| + // Verifies that {@link WebappDataStorage#ShouldUpdate()} returns true no matter whether we |
| + // want to check update less frequently. |
| + storage.setRelaxedUpdates(true); |
| + assertTrue(storage.shouldUpdate()); |
| + storage.setRelaxedUpdates(false); |
| + assertTrue(storage.shouldUpdate()); |
| + } |
| + |
| // TODO(lalitm) - There seems to be a bug in Robolectric where a Bitmap |
| // produced from a byte stream is hardcoded to be a 100x100 bitmap with |
| // ARGB_8888 pixel format. Because of this, we need to work around the |