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

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

Issue 2047673002: [Android backup] Restore nothing if signed in user isn't valid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java
index 20e1cb013f532fcd83b582f6498eed5792d52d2d..2afb449c9943889056b23745bb30217e09be09fd 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java
@@ -8,6 +8,9 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
@@ -32,6 +35,15 @@ public class ChromeBackupAgentTest {
}
}
+ @Before
+ public void setUp() throws Exception {
+ ContextUtils.initApplicationContextForTests(Robolectric.application);
+ AccountManager manager =
+ (AccountManager) Robolectric.application.getSystemService(Context.ACCOUNT_SERVICE);
+ manager.addAccountExplicitly(new Account("user1", "dummy"), null, null);
+ manager.addAccountExplicitly(new Account("user2", "dummy"), null, null);
+ }
+
@Test
public void testOnRestoreFinished() {
SharedPreferences sharedPrefs =
@@ -53,4 +65,40 @@ public class ChromeBackupAgentTest {
assertThat(sharedPrefs.getString("first_run_signin_account_name", null), equalTo("user1"));
}
+ @Test
+ public void testOnRestoreFinishedNoUser() {
+ SharedPreferences sharedPrefs =
+ PreferenceManager.getDefaultSharedPreferences(Robolectric.application);
+ SharedPreferences.Editor editor = sharedPrefs.edit();
+ editor.putBoolean("crash_dump_upload", false);
+ editor.putString("junk", "junk");
+ editor.commit();
+
+ new ChromeTestBackupAgent().onRestoreFinished();
+
+ // Check that we haven't restored any preferences
+ assertThat(sharedPrefs.getBoolean("crash_dump_upload", true), equalTo(true));
+ assertThat(sharedPrefs.getString("google.services.username", null), nullValue());
+ assertThat(sharedPrefs.getString("junk", null), nullValue());
+ assertThat(sharedPrefs.getString("first_run_signin_account_name", null), nullValue());
+ }
+
+ @Test
+ public void testOnRestoreFinishedWrongUser() {
+ SharedPreferences sharedPrefs =
+ PreferenceManager.getDefaultSharedPreferences(Robolectric.application);
+ SharedPreferences.Editor editor = sharedPrefs.edit();
+ editor.putBoolean("crash_dump_upload", false);
+ editor.putString("google.services.username", "wrong_user");
+ editor.putString("junk", "junk");
+ editor.commit();
+
+ new ChromeTestBackupAgent().onRestoreFinished();
+
+ // Check that we haven't restored any preferences
+ assertThat(sharedPrefs.getBoolean("crash_dump_upload", true), equalTo(true));
+ assertThat(sharedPrefs.getString("google.services.username", null), nullValue());
+ assertThat(sharedPrefs.getString("junk", null), nullValue());
+ assertThat(sharedPrefs.getString("first_run_signin_account_name", null), nullValue());
+ }
}
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698