Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1167)

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebappDataStorageTest.java

Issue 1867543002: Enable deep-linking from notifications for recently used web apps on the Android home screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bulk-webappdatastorage
Patch Set: Address nits Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 2582b402c2045082f77127616de3cee2b3ac21f4..a1baa2b4e239755c1a85c78277611fedd2fe4cda 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
@@ -22,6 +22,8 @@ import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
+import java.util.concurrent.TimeUnit;
+
/**
* Tests the WebappDataStorage class by ensuring that it persists data to
* SharedPreferences as expected.
@@ -47,6 +49,23 @@ public class WebappDataStorageTest {
}
}
+ private static class TestClock extends WebappDataStorage.Clock {
+ private long mCurrentTime;
+
+ public TestClock(long currentTime) {
+ updateTime(currentTime);
+ }
+
+ public void updateTime(long currentTime) {
+ mCurrentTime = currentTime;
+ }
+
+ @Override
+ public long currentTimeMillis() {
+ return mCurrentTime;
+ }
+ }
+
@Before
public void setUp() throws Exception {
mSharedPreferences = Robolectric.application
@@ -149,13 +168,13 @@ public class WebappDataStorageTest {
@Test
@Feature({"Webapp"})
- public void testURLRetrieval() throws Exception {
+ public void testUrlRetrieval() throws Exception {
final String url = "https://www.google.com";
mSharedPreferences.edit()
.putString(WebappDataStorage.KEY_URL, url)
.commit();
- WebappDataStorage.getURL(Robolectric.application, "test",
+ WebappDataStorage.getUrl(Robolectric.application, "test",
new FetchCallback<String>(url));
BackgroundShadowAsyncTask.runBackgroundTasks();
Robolectric.runUiThreadTasks();
@@ -165,6 +184,71 @@ public class WebappDataStorageTest {
@Test
@Feature({"Webapp"})
+ public void testWasLaunchedRecently() throws Exception {
+ final TestClock clock = new TestClock(System.currentTimeMillis());
+ WebappDataStorage.setClockForTests(clock);
+
+ WebappDataStorage storage = WebappDataStorage.open(Robolectric.application, "test");
+ storage.updateLastUsedTime();
+ BackgroundShadowAsyncTask.runBackgroundTasks();
+ Robolectric.runUiThreadTasks();
+ assertTrue(!storage.wasLaunchedRecently());
+
+ long lastUsedTime = mSharedPreferences.getLong(WebappDataStorage.KEY_LAST_USED,
+ WebappDataStorage.LAST_USED_INVALID);
+
+ assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_UNSET);
+ assertTrue(lastUsedTime != WebappDataStorage.LAST_USED_INVALID);
+
+ // Mark as launched, check launched recently.
+ mSharedPreferences.edit()
+ .putBoolean(WebappDataStorage.KEY_LAUNCHED, true)
+ .commit();
+ assertTrue(storage.wasLaunchedRecently());
+
+ // Move the last used time one day in the past.
+ mSharedPreferences.edit()
+ .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUnit.DAYS.toMillis(1L))
+ .commit();
+ assertTrue(storage.wasLaunchedRecently());
+
+ // Move the last used time three days in the past.
+ mSharedPreferences.edit()
+ .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUnit.DAYS.toMillis(3L))
+ .commit();
+ assertTrue(storage.wasLaunchedRecently());
+
+ // Move the last used time one week in the past.
+ mSharedPreferences.edit()
+ .putLong(WebappDataStorage.KEY_LAST_USED, lastUsedTime - TimeUnit.DAYS.toMillis(7L))
+ .commit();
+ assertTrue(storage.wasLaunchedRecently());
+
+ // Move the last used time just under ten days in the past.
+ mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED,
+ lastUsedTime - TimeUnit.DAYS.toMillis(10L) + 1).commit();
+ assertTrue(storage.wasLaunchedRecently());
+
+ // Mark as not launched.
+ mSharedPreferences.edit()
+ .putBoolean(WebappDataStorage.KEY_LAUNCHED, false)
+ .commit();
+ assertTrue(!storage.wasLaunchedRecently());
+
+ // Mark as launched.
+ mSharedPreferences.edit()
+ .putBoolean(WebappDataStorage.KEY_LAUNCHED, true)
+ .commit();
+ assertTrue(storage.wasLaunchedRecently());
+
+ // Move the last used time to exactly ten days in the past.
+ mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED,
+ lastUsedTime - TimeUnit.DAYS.toMillis(10L)).commit();
+ assertTrue(!storage.wasLaunchedRecently());
+ }
+
+ @Test
+ @Feature({"Webapp"})
public void testIntentUpdate() throws Exception {
final String id = "id";
final String action = "action";

Powered by Google App Engine
This is Rietveld 408576698