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

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

Issue 2277603002: Extract tabbed mode specific logic from the TabPersistenceStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs Created 4 years, 4 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/tabmodel/MultiInstanceMigrationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/MultiInstanceMigrationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/MultiInstanceMigrationTest.java
index 383b6ff6bffa861008bbfdbb7cc97c2b7d9c66cf..08d402229ca3958faa5498e8e1b3e96ec26063cd 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/MultiInstanceMigrationTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/MultiInstanceMigrationTest.java
@@ -9,6 +9,7 @@ import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.ContextUtils;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.AdvancedMockContext;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.TabState;
@@ -38,7 +39,7 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
// Set the shared pref stating that the legacy file migration has occurred. The
// multi-instance migration won't happen if the legacy path is taken.
ContextUtils.getAppSharedPreferences().edit().putBoolean(
- TabPersistentStore.PREF_HAS_RUN_FILE_MIGRATION, true).apply();
+ TabbedModeTabPersistencePolicy.PREF_HAS_RUN_FILE_MIGRATION, true).apply();
}
@Override
@@ -47,6 +48,20 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
ApplicationData.clearAppData(mAppContext);
}
+ private void buildPersistentStoreAndWaitForMigration() {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
+ TabbedModeTabPersistencePolicy persistencePolicy =
+ new TabbedModeTabPersistencePolicy(mAppContext, 0);
+ TabPersistentStore store = new TabPersistentStore(
+ persistencePolicy, selector, mAppContext, null, null, false);
+ store.waitForMigrationToFinish();
+ }
+ });
+ }
+
/**
* Tests that normal migration of multi-instance state files works.
*/
@@ -55,10 +70,11 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
public void testMigrateData() throws IOException {
// Write old state files.
File[] stateDirs = createOldStateDirs(TabWindowManager.MAX_SIMULTANEOUS_SELECTORS, true);
- File stateFile0 = new File(stateDirs[0], TabPersistentStore.SAVED_STATE_FILE);
- File stateFile1 = new File(stateDirs[1], TabPersistentStore.SAVED_STATE_FILE);
- File stateFile2 = new File(stateDirs[2], TabPersistentStore.SAVED_STATE_FILE);
- File customTabsStateFile = new File(stateDirs[3], TabPersistentStore.SAVED_STATE_FILE);
+ File stateFile0 = new File(stateDirs[0], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
+ File stateFile1 = new File(stateDirs[1], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
+ File stateFile2 = new File(stateDirs[2], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
+ File customTabsStateFile = new File(
+ stateDirs[3], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
assertTrue("Could not create state file 0", stateFile0.createNewFile());
assertTrue("Could not create state file 1", stateFile1.createNewFile());
@@ -83,21 +99,22 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
assertTrue("Could not create tab 6 file", tab6.createNewFile());
// Build the TabPersistentStore which will try to move the files.
- MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
- TabPersistentStore store =
- new TabPersistentStore(selector, 0, mAppContext, null, null, false);
- store.waitForMigrationToFinish();
+ buildPersistentStoreAndWaitForMigration();
// Make sure we don't hit the migration path again.
assertTrue(ContextUtils.getAppSharedPreferences().getBoolean(
- TabPersistentStore.PREF_HAS_RUN_MULTI_INSTANCE_FILE_MIGRATION, false));
+ TabbedModeTabPersistencePolicy.PREF_HAS_RUN_MULTI_INSTANCE_FILE_MIGRATION, false));
// Check that all metadata files moved.
- File newStateFile0 = new File(stateDirs[0], TabPersistentStore.getStateFileName(0));
- File newStateFile1 = new File(stateDirs[0], TabPersistentStore.getStateFileName(1));
- File newStateFile2 = new File(stateDirs[0], TabPersistentStore.getStateFileName(2));
- File newCustomTabsStateFile = new File(stateDirs[0], TabPersistentStore.getStateFileName(
- TabModelSelectorImpl.CUSTOM_TABS_SELECTOR_INDEX));
+ File newStateFile0 = new File(
+ stateDirs[0], TabbedModeTabPersistencePolicy.getStateFileName(0));
+ File newStateFile1 = new File(
+ stateDirs[0], TabbedModeTabPersistencePolicy.getStateFileName(1));
+ File newStateFile2 = new File(
+ stateDirs[0], TabbedModeTabPersistencePolicy.getStateFileName(2));
+ File newCustomTabsStateFile = new File(
+ stateDirs[0], TabbedModeTabPersistencePolicy.getStateFileName(
+ TabModelSelectorImpl.CUSTOM_TABS_SELECTOR_INDEX));
assertTrue("Could not find new state file 0", newStateFile0.exists());
assertTrue("Could not find new state file 1", newStateFile1.exists());
assertTrue("Could not find new state file 2", newStateFile2.exists());
@@ -146,8 +163,8 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
public void testMigrationLeavesOtherFilesAlone() throws IOException {
// Write old state files and an extra file.
File[] stateDirs = createOldStateDirs(2, false);
- File stateFile0 = new File(stateDirs[0], TabPersistentStore.SAVED_STATE_FILE);
- File stateFile1 = new File(stateDirs[1], TabPersistentStore.SAVED_STATE_FILE);
+ File stateFile0 = new File(stateDirs[0], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
+ File stateFile1 = new File(stateDirs[1], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
File tab0 = new File(stateDirs[0], TabState.SAVED_TAB_STATE_FILE_PREFIX + "0");
File tab1 = new File(stateDirs[1], TabState.SAVED_TAB_STATE_FILE_PREFIX + "1");
File otherFile = new File(stateDirs[1], "other.file");
@@ -159,10 +176,7 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
assertTrue("Could not create other file", otherFile.createNewFile());
// Build the TabPersistentStore which will try to move the files.
- MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
- TabPersistentStore store =
- new TabPersistentStore(selector, 0, mAppContext, null, null, false);
- store.waitForMigrationToFinish();
+ buildPersistentStoreAndWaitForMigration();
// Check that the other file wasn't moved.
File newOtherFile = new File(stateDirs[0], "other.file");
@@ -170,8 +184,10 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
assertTrue("Could not find original other file", otherFile.exists());
// Check that the metadata files were renamed and/or moved.
- File newStateFile0 = new File(stateDirs[0], TabPersistentStore.getStateFileName(0));
- File newStateFile1 = new File(stateDirs[0], TabPersistentStore.getStateFileName(1));
+ File newStateFile0 = new File(
+ stateDirs[0], TabbedModeTabPersistencePolicy.getStateFileName(0));
+ File newStateFile1 = new File(
+ stateDirs[0], TabbedModeTabPersistencePolicy.getStateFileName(1));
assertTrue("Could not find new state file 0", newStateFile0.exists());
assertTrue("Could not find new state file 1", newStateFile1.exists());
assertFalse("Could still find old state file 0", stateFile0.exists());
@@ -195,8 +211,8 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
public void testMigrateDataDuplicateTabFiles() throws IOException {
// Write old state files.
File[] stateDirs = createOldStateDirs(2, false);
- File stateFile0 = new File(stateDirs[0], TabPersistentStore.SAVED_STATE_FILE);
- File stateFile1 = new File(stateDirs[1], TabPersistentStore.SAVED_STATE_FILE);
+ File stateFile0 = new File(stateDirs[0], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
+ File stateFile1 = new File(stateDirs[1], TabPersistencePolicy.SAVED_STATE_FILE_PREFIX);
assertTrue("Could not create state file 0", stateFile0.createNewFile());
assertTrue("Could not create state file 1", stateFile1.createNewFile());
@@ -224,10 +240,7 @@ public class MultiInstanceMigrationTest extends InstrumentationTestCase {
}
// Build the TabPersistentStore which will try to move the files.
- MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
- TabPersistentStore store =
- new TabPersistentStore(selector, 0, mAppContext, null, null, false);
- store.waitForMigrationToFinish();
+ buildPersistentStoreAndWaitForMigration();
// Check that "tab0" still exists and has the expected last modified time.
assertTrue("Could not find tab 0 file", tab0Dir0.exists());

Powered by Google App Engine
This is Rietveld 408576698