| 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());
|
| + }
|
| }
|
|
|