| Index: chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/RestoreMigrateTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/RestoreMigrateTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/RestoreMigrateTest.java
|
| index 89504bf4bc65f8af523a6c38692e9e02c139346c..f959d971f434e5857a1ebf1e89efffd4f1c5f27e 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/RestoreMigrateTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/RestoreMigrateTest.java
|
| @@ -4,13 +4,16 @@
|
|
|
| package org.chromium.chrome.browser.tabmodel;
|
|
|
| +import android.content.Context;
|
| import android.test.InstrumentationTestCase;
|
| import android.test.suitebuilder.annotation.SmallTest;
|
|
|
| +import org.chromium.base.ContextUtils;
|
| import org.chromium.base.StreamUtil;
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| import org.chromium.base.metrics.RecordHistogram;
|
| +import org.chromium.base.test.util.AdvancedMockContext;
|
| import org.chromium.chrome.browser.TabState;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.chrome.browser.tab.TabIdManager;
|
| @@ -28,6 +31,8 @@ import java.util.concurrent.ExecutionException;
|
| */
|
| public class RestoreMigrateTest extends InstrumentationTestCase {
|
|
|
| + private Context mAppContext;
|
| +
|
| private void writeStateFile(final TabModelSelector selector, int index) throws IOException {
|
| byte[] data = ThreadUtils.runOnUiThreadBlockingNoException(
|
| new Callable<byte[]>() {
|
| @@ -56,6 +61,14 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| return maxId;
|
| }
|
|
|
| + @Override
|
| + protected void setUp() throws Exception {
|
| + super.setUp();
|
| + mAppContext = new AdvancedMockContext(
|
| + getInstrumentation().getTargetContext().getApplicationContext());
|
| + ContextUtils.initApplicationContextForTests(mAppContext);
|
| + }
|
| +
|
| /**
|
| * Test that normal migration of state files works.
|
| * @throws IOException
|
| @@ -66,10 +79,10 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
|
| @SmallTest
|
| public void testMigrateData() throws IOException, InterruptedException, ExecutionException {
|
| - ApplicationData.clearAppData(getInstrumentation().getTargetContext());
|
| + ApplicationData.clearAppData(mAppContext);
|
|
|
| // Write old state files.
|
| - File filesDir = getInstrumentation().getTargetContext().getFilesDir();
|
| + File filesDir = mAppContext.getFilesDir();
|
| File stateFile = new File(filesDir, TabPersistentStore.SAVED_STATE_FILE);
|
| File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0");
|
| File tab1 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "1");
|
| @@ -84,8 +97,7 @@ public class RestoreMigrateTest 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,
|
| - getInstrumentation().getTargetContext(), null, null);
|
| + TabPersistentStore store = new TabPersistentStore(selector, 0, mAppContext, null, null);
|
| store.waitForMigrationToFinish();
|
|
|
| // Check that the files were moved.
|
| @@ -108,7 +120,7 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| assertFalse("Could still find old tab 2 file", tab2.exists());
|
| assertFalse("Could still find old tab 3 file", tab3.exists());
|
|
|
| - ApplicationData.clearAppData(getInstrumentation().getTargetContext());
|
| + ApplicationData.clearAppData(mAppContext);
|
| }
|
|
|
| /**
|
| @@ -121,10 +133,10 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
|
| @SmallTest
|
| public void testSkipMigrateData() throws IOException, InterruptedException, ExecutionException {
|
| - ApplicationData.clearAppData(getInstrumentation().getTargetContext());
|
| + ApplicationData.clearAppData(mAppContext);
|
|
|
| // Write old state files.
|
| - File filesDir = getInstrumentation().getTargetContext().getFilesDir();
|
| + File filesDir = mAppContext.getFilesDir();
|
| File stateFile = new File(filesDir, TabPersistentStore.SAVED_STATE_FILE);
|
| File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0");
|
| File tab1 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "1");
|
| @@ -147,8 +159,7 @@ public class RestoreMigrateTest 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,
|
| - getInstrumentation().getTargetContext(), null, null);
|
| + TabPersistentStore store = new TabPersistentStore(selector, 0, mAppContext, null, null);
|
| store.waitForMigrationToFinish();
|
|
|
| assertTrue("Could not find new state file", newStateFile.exists());
|
| @@ -165,7 +176,7 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| assertFalse("Could find new tab 2 file", newTab2.exists());
|
| assertFalse("Could find new tab 3 file", newTab3.exists());
|
|
|
| - ApplicationData.clearAppData(getInstrumentation().getTargetContext());
|
| + ApplicationData.clearAppData(mAppContext);
|
| }
|
|
|
| /**
|
| @@ -179,10 +190,10 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| @SmallTest
|
| public void testMigrationLeavesOtherFilesAlone() throws IOException, InterruptedException,
|
| ExecutionException {
|
| - ApplicationData.clearAppData(getInstrumentation().getTargetContext());
|
| + ApplicationData.clearAppData(mAppContext);
|
|
|
| // Write old state files.
|
| - File filesDir = getInstrumentation().getTargetContext().getFilesDir();
|
| + File filesDir = mAppContext.getFilesDir();
|
| File stateFile = new File(filesDir, TabPersistentStore.SAVED_STATE_FILE);
|
| File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0");
|
| File otherFile = new File(filesDir, "other.file");
|
| @@ -193,8 +204,7 @@ public class RestoreMigrateTest 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,
|
| - getInstrumentation().getTargetContext(), null, null);
|
| + TabPersistentStore store = new TabPersistentStore(selector, 0, mAppContext, null, null);
|
| store.waitForMigrationToFinish();
|
|
|
| assertFalse("Could still find old state file", stateFile.exists());
|
| @@ -211,7 +221,7 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| assertTrue("Could not find new tab 0 file", newTab0.exists());
|
| assertFalse("Could find new other file", newOtherFile.exists());
|
|
|
| - ApplicationData.clearAppData(getInstrumentation().getTargetContext());
|
| + ApplicationData.clearAppData(mAppContext);
|
| }
|
|
|
| /**
|
| @@ -227,8 +237,7 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| writeStateFile(selector1, 1);
|
|
|
| TabModelSelector selectorIn = new MockTabModelSelector(0, 0, null);
|
| - TabPersistentStore storeIn = new TabPersistentStore(selectorIn, 0,
|
| - getInstrumentation().getTargetContext(), null, null);
|
| + TabPersistentStore storeIn = new TabPersistentStore(selectorIn, 0, mAppContext, null, null);
|
|
|
| int maxId = Math.max(getMaxId(selector0), getMaxId(selector1));
|
| RecordHistogram.disableForTests();
|
| @@ -255,10 +264,10 @@ public class RestoreMigrateTest extends InstrumentationTestCase {
|
| TabModelSelector selectorIn0 = new MockTabModelSelector(0, 0, null);
|
| TabModelSelector selectorIn1 = new MockTabModelSelector(0, 0, null);
|
|
|
| - TabPersistentStore storeIn0 = new TabPersistentStore(selectorIn0, 0,
|
| - getInstrumentation().getTargetContext(), null, null);
|
| - TabPersistentStore storeIn1 = new TabPersistentStore(selectorIn1, 1,
|
| - getInstrumentation().getTargetContext(), null, null);
|
| + TabPersistentStore storeIn0 = new TabPersistentStore(
|
| + selectorIn0, 0, mAppContext, null, null);
|
| + TabPersistentStore storeIn1 = new TabPersistentStore(
|
| + selectorIn1, 1, mAppContext, null, null);
|
|
|
| RecordHistogram.disableForTests();
|
| storeIn0.loadState();
|
|
|