Index: chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java |
index 1b9c000234070a578fa2f473c8a353eb53a45222..d2c1fd4729f9ff3ea2700cc0e6e6f2fc8ec73190 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java |
@@ -4,7 +4,6 @@ |
package org.chromium.chrome.browser.physicalweb; |
-import android.content.Context; |
import android.content.SharedPreferences; |
import android.support.test.filters.SmallTest; |
import android.test.InstrumentationTestCase; |
@@ -41,16 +40,15 @@ public class UrlManagerTest extends InstrumentationTestCase { |
private UrlManager mUrlManager = null; |
private MockPwsClient mMockPwsClient = null; |
private MockNotificationManagerProxy mMockNotificationManagerProxy = null; |
- private SharedPreferences mSharedPreferences = null; |
@Override |
protected void setUp() throws Exception { |
super.setUp(); |
- Context context = getInstrumentation().getTargetContext().getApplicationContext(); |
- mSharedPreferences = ContextUtils.getAppSharedPreferences(); |
- mSharedPreferences.edit().putInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON).apply(); |
- UrlManager.clearPrefsForTesting(context); |
- mUrlManager = new UrlManager(context); |
+ ContextUtils.getAppSharedPreferences().edit() |
+ .putInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON) |
+ .apply(); |
+ UrlManager.clearPrefsForTesting(); |
+ mUrlManager = new UrlManager(); |
mMockPwsClient = new MockPwsClient(); |
mUrlManager.overridePwsClientForTesting(mMockPwsClient); |
mMockNotificationManagerProxy = new MockNotificationManagerProxy(); |
@@ -90,7 +88,9 @@ public class UrlManagerTest extends InstrumentationTestCase { |
} |
private void setOnboarding() { |
- mSharedPreferences.edit().putInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ONBOARDING).apply(); |
+ ContextUtils.getAppSharedPreferences().edit() |
+ .putInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ONBOARDING) |
+ .apply(); |
} |
@SmallTest |
@@ -445,13 +445,12 @@ public class UrlManagerTest extends InstrumentationTestCase { |
Set<String> serializedUrls = new HashSet<>(); |
serializedUrls.add(new UrlInfo(URL1, 99.5, curTime + 42).jsonSerialize().toString()); |
serializedUrls.add("{\"not_a_value\": \"This is totally not a serialized UrlInfo.\"}"); |
- mSharedPreferences.edit() |
+ ContextUtils.getAppSharedPreferences().edit() |
.putStringSet("physicalweb_all_urls", serializedUrls) |
.apply(); |
// Make sure only the properly serialized URL is restored. |
- Context context = getInstrumentation().getTargetContext().getApplicationContext(); |
- UrlManager urlManager = new UrlManager(context); |
+ UrlManager urlManager = new UrlManager(); |
List<UrlInfo> urlInfos = urlManager.getUrls(); |
assertEquals(1, urlInfos.size()); |
assertEquals(URL1, urlInfos.get(0).getUrl()); |
@@ -468,8 +467,7 @@ public class UrlManagerTest extends InstrumentationTestCase { |
getInstrumentation().waitForIdleSync(); |
// Make sure all URLs are restored. |
- Context context = getInstrumentation().getTargetContext().getApplicationContext(); |
- UrlManager urlManager = new UrlManager(context); |
+ UrlManager urlManager = new UrlManager(); |
List<UrlInfo> urlInfos = urlManager.getUrls(); |
assertEquals(2, urlInfos.size()); |
Set<String> resolvedUrls = urlManager.getResolvedUrls(); |
@@ -486,8 +484,7 @@ public class UrlManagerTest extends InstrumentationTestCase { |
getInstrumentation().waitForIdleSync(); |
// Make sure all URLs are restored. |
- Context context = getInstrumentation().getTargetContext().getApplicationContext(); |
- UrlManager urlManager = new UrlManager(context); |
+ UrlManager urlManager = new UrlManager(); |
List<UrlInfo> urlInfos = urlManager.getUrls(); |
assertEquals(0, urlInfos.size()); |
Set<String> resolvedUrls = urlManager.getResolvedUrls(); |
@@ -498,23 +495,24 @@ public class UrlManagerTest extends InstrumentationTestCase { |
public void testUpgradeFromNone() throws Exception { |
Set<String> oldResolvedUrls = new HashSet<String>(); |
oldResolvedUrls.add("old"); |
- Context context = getInstrumentation().getTargetContext().getApplicationContext(); |
- mSharedPreferences.edit() |
+ ContextUtils.getAppSharedPreferences().edit() |
.remove(UrlManager.getVersionKey()) |
.putStringSet("physicalweb_resolved_urls", oldResolvedUrls) |
.apply(); |
- new UrlManager(context); |
+ new UrlManager(); |
// Make sure the new prefs are populated and old prefs are gone. |
+ final SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); |
CriteriaHelper.pollInstrumentationThread(new Criteria() { |
@Override |
public boolean isSatisfied() { |
- return mSharedPreferences.contains(UrlManager.getVersionKey()) |
- && !mSharedPreferences.contains("physicalweb_resolved_urls"); |
+ SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); |
+ return sharedPreferences.contains(UrlManager.getVersionKey()) |
+ && !sharedPreferences.contains("physicalweb_resolved_urls"); |
} |
}, 5000, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
assertEquals(UrlManager.getVersion(), |
- mSharedPreferences.getInt(UrlManager.getVersionKey(), 0)); |
+ sharedPreferences.getInt(UrlManager.getVersionKey(), 0)); |
} |
} |