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

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

Issue 1990233002: [Android backup] Restore nothing if signed in user isn't valid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to more comments Created 4 years, 7 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 62853b63670ed4184200d8536f827d5e3cead0cb..4d7d9305255e9da41136be958c3672a4fc154a65 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 org.chromium.base.ContextUtils;
@@ -36,6 +39,10 @@ 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
@@ -58,4 +65,38 @@ public class ChromeBackupAgentTest {
assertThat(sharedPrefs.getString("first_run_signin_account_name", null), equalTo("user1"));
}
+ @Test
+ public void testOnRestoreFinishedNoUser() {
+ SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
+ 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 = ContextUtils.getAppSharedPreferences();
+ 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