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 6cfc8f4a7e177f798de10627a3ca106856d5d93b..98102c7d84300a5808b6b82bd933a4c26f5da40a 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 |
@@ -32,6 +32,20 @@ public class WebappDataStorageTest { |
private SharedPreferences mSharedPreferences; |
private boolean mCallbackCalled; |
+ private class FetchCallback<T> implements WebappDataStorage.FetchCallback<T> { |
+ T mExpected; |
+ |
+ FetchCallback(T expected) { |
+ mExpected = expected; |
+ } |
+ |
+ @Override |
+ public void onDataRetrieved(T readObject) { |
+ mCallbackCalled = true; |
+ assertEquals(mExpected, readObject); |
+ } |
+ } |
+ |
@Before |
public void setUp() throws Exception { |
mSharedPreferences = Robolectric.application |
@@ -49,6 +63,7 @@ public class WebappDataStorageTest { |
assertEquals("webapp_", WebappDataStorage.SHARED_PREFS_FILE_PREFIX); |
assertEquals("splash_icon", WebappDataStorage.KEY_SPLASH_ICON); |
assertEquals("last_used", WebappDataStorage.KEY_LAST_USED); |
+ assertEquals("url", WebappDataStorage.KEY_URL); |
} |
@Test |
@@ -59,13 +74,7 @@ public class WebappDataStorageTest { |
.commit(); |
WebappDataStorage.getLastUsedTime(Robolectric.application, "test", |
- new WebappDataStorage.FetchCallback<Long>() { |
- @Override |
- public void onDataRetrieved(Long readObject) { |
- mCallbackCalled = true; |
- assertEquals(100L, (long) readObject); |
- } |
- }); |
+ new FetchCallback<Long>(new Long(100L))); |
BackgroundShadowAsyncTask.runBackgroundTasks(); |
Robolectric.runUiThreadTasks(); |
@@ -143,4 +152,41 @@ public class WebappDataStorageTest { |
private static Bitmap createBitmap() { |
return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444); |
} |
-} |
+ |
+ @Test |
+ @Feature({"Webapp"}) |
+ public void testUrlRetrieval() throws Exception { |
+ final String url = "http://drive.google.com"; |
+ mSharedPreferences.edit() |
+ .putString(WebappDataStorage.KEY_URL, url) |
+ .commit(); |
+ |
+ WebappDataStorage.getUrl(Robolectric.application, "test", |
+ new FetchCallback<String>(url)); |
+ BackgroundShadowAsyncTask.runBackgroundTasks(); |
+ Robolectric.runUiThreadTasks(); |
+ |
+ assertTrue(mCallbackCalled); |
+ } |
+ |
+ @Test |
+ @Feature({"Webapp"}) |
+ public void testUrlUpdate() throws Exception { |
+ final String url1 = "http://maps.google.com"; |
+ final String url2 = "http://drive.google.com"; |
+ |
+ WebappDataStorage.setUrl(Robolectric.application, "test", url1); |
+ BackgroundShadowAsyncTask.runBackgroundTasks(); |
+ Robolectric.runUiThreadTasks(); |
+ |
+ assertEquals(url1, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null)); |
+ |
+ // Ensure that calling setUrl with a different URL after it has been set |
+ // doesn't change the URL stored. |
+ WebappDataStorage.setUrl(Robolectric.application, "test", url2); |
+ BackgroundShadowAsyncTask.runBackgroundTasks(); |
+ Robolectric.runUiThreadTasks(); |
+ |
+ assertEquals(url1, mSharedPreferences.getString(WebappDataStorage.KEY_URL, null)); |
+ } |
+} |