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