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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java

Issue 2047473003: [Android backup] Sync settings, and new to old version restore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs issues 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
Index: chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java
index b2f9b69b566b821bce1dd50f6ff3420b60300acb..0dad887e2033a16fd7d49ae365693ccd9c49882a 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java
@@ -12,16 +12,25 @@ import android.os.Build;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.ContextUtils;
+import org.chromium.base.StreamUtil;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
+import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.signin.AccountIdProvider;
import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
import org.chromium.sync.signin.AccountManagerHelper;
import org.chromium.sync.signin.ChromeSigninController;
import org.chromium.sync.test.util.MockAccountManager;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
/**
* Android backup tests.
*/
@@ -63,7 +72,7 @@ public class ChromeBackupIntegrationTest extends ChromeTabbedActivityTestBase {
protected Account[] getAccounts() {
// ChromeBackupAgent can't use Chrome's account manager, so we override this to mock
// the existence of the account.
- return new Account[]{new Account(TEST_ACCOUNT_1, GOOGLE_ACCOUNT_TYPE)};
+ return new Account[] {new Account(TEST_ACCOUNT_1, GOOGLE_ACCOUNT_TYPE)};
}
}
@@ -87,7 +96,7 @@ public class ChromeBackupIntegrationTest extends ChromeTabbedActivityTestBase {
@SmallTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
- public void testSimpleRestore() throws InterruptedException {
+ public void testSimpleRestore() throws InterruptedException, IOException {
// Fake having previously gone through FRE and signed in.
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
@@ -95,6 +104,16 @@ public class ChromeBackupIntegrationTest extends ChromeTabbedActivityTestBase {
preferenceEditor.putBoolean(FirstRunStatus.FIRST_RUN_FLOW_COMPLETE, true);
preferenceEditor.putBoolean(FirstRunSignInProcessor.FIRST_RUN_FLOW_SIGNIN_SETUP, true);
+ String chromeInputPrefs =
+ "{\"junk1\":\"abc\", "
+ + "\"sync\":{ \"has_setup_completed\":\"true\", "
+ + " \"keep_everything_synced\":\"false\", "
+ + " \"passwords\":\"true\", "
+ + " \"junk2\":\"xxx\""
+ + " }}";
+
+ writeTestChromePrefs(chromeInputPrefs);
+
// Set up the mocked account as the signed in account.
preferenceEditor.putString(ChromeSigninController.SIGNED_IN_ACCOUNT_KEY, TEST_ACCOUNT_1);
preferenceEditor.commit();
@@ -108,11 +127,19 @@ public class ChromeBackupIntegrationTest extends ChromeTabbedActivityTestBase {
assertTrue(ChromeSigninController.get(mTargetContext).isSignedIn());
assertEquals(TEST_ACCOUNT_1,
ChromeSigninController.get(mTargetContext).getSignedInAccountName());
+
+ String chromeOutputPrefs = readChromePrefs();
+
+ assertTrue(chromeOutputPrefs.contains("\"keep_everything_synced\":\"false\""));
+ assertTrue(chromeOutputPrefs.contains("\"passwords\":\"true\""));
+ assertFalse(chromeOutputPrefs.contains("junk"));
+
}
+
@SmallTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
- public void testRestoreAccountMissing() throws InterruptedException {
+ public void testRestoreAccountMissing() throws InterruptedException, IOException {
// Fake having previously gone through FRE and signed in.
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
SharedPreferences.Editor preferenceEditor = prefs.edit();
@@ -123,6 +150,9 @@ public class ChromeBackupIntegrationTest extends ChromeTabbedActivityTestBase {
preferenceEditor.putString(ChromeSigninController.SIGNED_IN_ACCOUNT_KEY, TEST_ACCOUNT_2);
preferenceEditor.commit();
+ String chromeInputPrefs = "{}";
+
+ writeTestChromePrefs(chromeInputPrefs);
// Run Chrome's restore code.
new ChromeTestBackupAgent(mTargetContext).onRestoreFinished();
@@ -133,4 +163,40 @@ public class ChromeBackupIntegrationTest extends ChromeTabbedActivityTestBase {
assertFalse(ChromeSigninController.get(mTargetContext).isSignedIn());
}
+ private void writeTestChromePrefs(String chromeInputPrefs)
+ throws FileNotFoundException, UnsupportedEncodingException, IOException {
+ FileOutputStream prefsFileWriter = null;
+ try {
+ File prefsDir =
+ mTargetContext.getDir(ChromeBrowserInitializer.PRIVATE_DATA_DIRECTORY_SUFFIX,
+ Context.MODE_PRIVATE);
+ prefsDir = new File(prefsDir, "Default");
+ assertTrue(prefsDir.mkdirs());
+ File prefsFile = new File(prefsDir, "Preferences");
+ prefsFileWriter = new FileOutputStream(prefsFile);
+ prefsFileWriter.write(chromeInputPrefs.getBytes("UTF-8"));
+ } finally {
+ StreamUtil.closeQuietly(prefsFileWriter);
+ }
+ }
+
+ private String readChromePrefs()
+ throws FileNotFoundException, IOException, UnsupportedEncodingException {
+ FileInputStream prefsFileReader = null;
+ try {
+ File prefsDir =
+ mTargetContext.getDir(ChromeBrowserInitializer.PRIVATE_DATA_DIRECTORY_SUFFIX,
+ Context.MODE_PRIVATE);
+ prefsDir = new File(prefsDir, "Default");
+ File prefsFile = new File(prefsDir, "Preferences");
+ prefsFileReader = new FileInputStream(prefsFile);
+ int fileLength = (int) prefsFile.length();
+ byte[] inputBuffer = new byte[fileLength];
+ assertEquals(fileLength, prefsFileReader.read(inputBuffer));
+ return new String(inputBuffer, "UTF-8");
+ } finally {
+ StreamUtil.closeQuietly(prefsFileReader);
+ }
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698