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

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: Allow downstream override of account fetching 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
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..1deef011a58cb1192307b3da209c8930cfdebdd8 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ChromeBackupAgentTest.java
@@ -8,10 +8,14 @@ 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;
import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
@@ -32,6 +36,14 @@ public class ChromeBackupAgentTest {
}
}
+ @Before
+ public void setUp() {
+ 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 testOnRestoreFinished_noUser() {
Bernhard Bauer 2016/05/23 12:40:15 Use camelCase throughout the test name.
aberent 2016/06/01 12:34:31 Done.
+ 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 testOnRestoreFinished_wrongUser() {
+ 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());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698