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 81e01bf3eb392fe03ccedf64795a48d336ba29a1..eb71f8a5272e33df096e692dbdf5f9728378473f 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 |
| @@ -13,11 +13,13 @@ import android.content.SharedPreferences; |
| import android.graphics.Bitmap; |
| import android.os.AsyncTask; |
| +import org.chromium.base.ContextUtils; |
| import org.chromium.base.test.util.Feature; |
| import org.chromium.blink_public.platform.WebDisplayMode; |
| import org.chromium.chrome.browser.ShortcutHelper; |
| import org.chromium.testing.local.BackgroundShadowAsyncTask; |
| import org.chromium.testing.local.LocalRobolectricTestRunner; |
| +import org.junit.After; |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| @@ -71,8 +73,9 @@ public class WebappDataStorageTest { |
| @Before |
| public void setUp() throws Exception { |
| - mSharedPreferences = RuntimeEnvironment.application |
| - .getSharedPreferences("webapp_test", Context.MODE_PRIVATE); |
| + ContextUtils.initApplicationContextForTests(RuntimeEnvironment.application); |
| + mSharedPreferences = ContextUtils.getApplicationContext().getSharedPreferences( |
| + "webapp_test", Context.MODE_PRIVATE); |
| // Set the last_used as if the web app had been registered by WebappRegistry. |
| mSharedPreferences.edit().putLong("last_used", 0).apply(); |
| @@ -80,6 +83,11 @@ public class WebappDataStorageTest { |
| mCallbackCalled = false; |
| } |
| + @After |
| + public void tearDown() { |
| + mSharedPreferences.edit().clear().apply(); |
| + } |
| + |
| @Test |
| @Feature({"Webapp"}) |
| public void testBackwardCompat() { |
| @@ -105,7 +113,7 @@ public class WebappDataStorageTest { |
| public void testLastUsedRetrieval() throws Exception { |
| mSharedPreferences.edit().putLong(WebappDataStorage.KEY_LAST_USED, 100L).apply(); |
| - WebappDataStorage.getLastUsedTime(RuntimeEnvironment.application, "test", |
| + WebappDataStorage.getLastUsedTime(ContextUtils.getApplicationContext(), "test", |
|
Peter Wen
2016/09/21 14:58:41
Don't need any of these ContextUtils calls.
dominickn
2016/09/22 03:47:00
Done.
|
| new FetchCallback<Long>(new Long(100L))); |
| BackgroundShadowAsyncTask.runBackgroundTasks(); |
| ShadowLooper.runUiThreadTasks(); |
| @@ -121,7 +129,7 @@ public class WebappDataStorageTest { |
| .putString(WebappDataStorage.KEY_SPLASH_ICON, |
| ShortcutHelper.encodeBitmapAsString(expected)) |
| .commit(); |
| - WebappDataStorage.open(RuntimeEnvironment.application, "test") |
| + WebappDataStorage.open(ContextUtils.getApplicationContext(), "test") |
| .getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() { |
| @Override |
| public void onDataRetrieved(Bitmap actual) { |
| @@ -143,7 +151,7 @@ public class WebappDataStorageTest { |
| @Feature({"Webapp"}) |
| public void testSplashImageUpdate() throws Exception { |
| final Bitmap expectedImage = createBitmap(); |
| - WebappDataStorage.open(RuntimeEnvironment.application, "test") |
| + WebappDataStorage.open(ContextUtils.getApplicationContext(), "test") |
| .updateSplashScreenImage(expectedImage); |
| BackgroundShadowAsyncTask.runBackgroundTasks(); |
| @@ -157,7 +165,7 @@ public class WebappDataStorageTest { |
| final String scope = "http://drive.google.com"; |
| mSharedPreferences.edit().putString(WebappDataStorage.KEY_SCOPE, scope).apply(); |
| - WebappDataStorage.getScope(RuntimeEnvironment.application, "test", |
| + WebappDataStorage.getScope(ContextUtils.getApplicationContext(), "test", |
| new FetchCallback<String>(scope)); |
| BackgroundShadowAsyncTask.runBackgroundTasks(); |
| ShadowLooper.runUiThreadTasks(); |
| @@ -171,7 +179,7 @@ public class WebappDataStorageTest { |
| final String url = "https://www.google.com"; |
| mSharedPreferences.edit().putString(WebappDataStorage.KEY_URL, url).apply(); |
| - WebappDataStorage.getUrl(RuntimeEnvironment.application, "test", |
| + WebappDataStorage.getUrl(ContextUtils.getApplicationContext(), "test", |
| new FetchCallback<String>(url)); |
| BackgroundShadowAsyncTask.runBackgroundTasks(); |
| ShadowLooper.runUiThreadTasks(); |
| @@ -186,7 +194,8 @@ public class WebappDataStorageTest { |
| WebappDataStorage.setClockForTests(clock); |
| // Opening a data storage doesn't count as a launch. |
| - WebappDataStorage storage = WebappDataStorage.open(RuntimeEnvironment.application, "test"); |
| + WebappDataStorage storage = |
| + WebappDataStorage.open(ContextUtils.getApplicationContext(), "test"); |
| BackgroundShadowAsyncTask.runBackgroundTasks(); |
| ShadowLooper.runUiThreadTasks(); |
| assertTrue(!storage.wasLaunchedRecently()); |
| @@ -257,7 +266,8 @@ public class WebappDataStorageTest { |
| }; |
| Intent shortcutIntent = shortcutIntentTask.execute().get(); |
| - WebappDataStorage storage = WebappDataStorage.open(RuntimeEnvironment.application, "test"); |
| + WebappDataStorage storage = |
| + WebappDataStorage.open(ContextUtils.getApplicationContext(), "test"); |
| storage.updateFromShortcutIntent(shortcutIntent); |
| BackgroundShadowAsyncTask.runBackgroundTasks(); |
| ShadowLooper.runUiThreadTasks(); |