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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/tabmodel/RestoreMigrateTest.java

Issue 2766373004: Convert the rest of chrome_public_test_apk InstrumentationTestCases to JUnit4 (Closed)
Patch Set: nits and rebase Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.tabmodel; 5 package org.chromium.chrome.browser.tabmodel;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.support.test.InstrumentationRegistry;
9 import android.support.test.annotation.UiThreadTest;
8 import android.support.test.filters.SmallTest; 10 import android.support.test.filters.SmallTest;
9 import android.test.InstrumentationTestCase; 11 import android.support.test.rule.UiThreadTestRule;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
10 18
11 import org.chromium.base.ContextUtils; 19 import org.chromium.base.ContextUtils;
12 import org.chromium.base.StreamUtil; 20 import org.chromium.base.StreamUtil;
13 import org.chromium.base.ThreadUtils; 21 import org.chromium.base.ThreadUtils;
14 import org.chromium.base.annotations.SuppressFBWarnings; 22 import org.chromium.base.annotations.SuppressFBWarnings;
15 import org.chromium.base.metrics.RecordHistogram; 23 import org.chromium.base.metrics.RecordHistogram;
16 import org.chromium.base.test.util.AdvancedMockContext; 24 import org.chromium.base.test.util.AdvancedMockContext;
17 import org.chromium.base.test.util.Feature; 25 import org.chromium.base.test.util.Feature;
18 import org.chromium.base.test.util.RetryOnFailure; 26 import org.chromium.base.test.util.RetryOnFailure;
19 import org.chromium.chrome.browser.TabState; 27 import org.chromium.chrome.browser.TabState;
20 import org.chromium.chrome.browser.tab.Tab; 28 import org.chromium.chrome.browser.tab.Tab;
21 import org.chromium.chrome.browser.tab.TabIdManager; 29 import org.chromium.chrome.browser.tab.TabIdManager;
30 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
22 import org.chromium.chrome.test.util.ApplicationData; 31 import org.chromium.chrome.test.util.ApplicationData;
23 import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector; 32 import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector;
24 33
25 import java.io.File; 34 import java.io.File;
26 import java.io.FileOutputStream; 35 import java.io.FileOutputStream;
27 import java.io.IOException; 36 import java.io.IOException;
28 import java.util.concurrent.Callable; 37 import java.util.concurrent.Callable;
29 import java.util.concurrent.ExecutionException; 38 import java.util.concurrent.ExecutionException;
30 39
31 /** 40 /**
32 * Test that migrating the old tab state folder structure to the new one works. 41 * Test that migrating the old tab state folder structure to the new one works.
33 */ 42 */
34 public class RestoreMigrateTest extends InstrumentationTestCase { 43 @RunWith(ChromeJUnit4ClassRunner.class)
35 44 public class RestoreMigrateTest {
36 private Context mAppContext; 45 private Context mAppContext;
37 46
38 private void writeStateFile(final TabModelSelector selector, int index) thro ws IOException { 47 private void writeStateFile(final TabModelSelector selector, int index) thro ws IOException {
39 byte[] data = ThreadUtils.runOnUiThreadBlockingNoException( 48 byte[] data = ThreadUtils.runOnUiThreadBlockingNoException(
40 new Callable<byte[]>() { 49 new Callable<byte[]>() {
41 @Override 50 @Override
42 public byte[] call() throws Exception { 51 public byte[] call() throws Exception {
43 return TabPersistentStore.serializeTabModelSelector(sele ctor, null); 52 return TabPersistentStore.serializeTabModelSelector(sele ctor, null);
44 } 53 }
45 }); 54 });
(...skipping 11 matching lines...) Expand all
57 private int getMaxId(TabModelSelector selector) { 66 private int getMaxId(TabModelSelector selector) {
58 int maxId = 0; 67 int maxId = 0;
59 for (TabList list : selector.getModels()) { 68 for (TabList list : selector.getModels()) {
60 for (int i = 0; i < list.getCount(); i++) { 69 for (int i = 0; i < list.getCount(); i++) {
61 maxId = Math.max(maxId, list.getTabAt(i).getId()); 70 maxId = Math.max(maxId, list.getTabAt(i).getId());
62 } 71 }
63 } 72 }
64 return maxId; 73 return maxId;
65 } 74 }
66 75
67 @Override 76 @Rule
68 protected void setUp() throws Exception { 77 public UiThreadTestRule mRule = new UiThreadTestRule();
69 super.setUp(); 78
70 mAppContext = new AdvancedMockContext( 79 @Before
71 getInstrumentation().getTargetContext().getApplicationContext()) ; 80 public void setUp() throws Exception {
81 mAppContext = new AdvancedMockContext(InstrumentationRegistry.getInstrum entation()
82 .getTargetContext()
83 .getApplicationContext());
72 ContextUtils.initApplicationContextForTests(mAppContext); 84 ContextUtils.initApplicationContextForTests(mAppContext);
73 } 85 }
74 86
75 private TabPersistentStore buildTabPersistentStore( 87 private TabPersistentStore buildTabPersistentStore(
76 final TabModelSelector selector, final int selectorIndex) { 88 final TabModelSelector selector, final int selectorIndex) {
77 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<TabPers istentStore>() { 89 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<TabPers istentStore>() {
78 @Override 90 @Override
79 public TabPersistentStore call() throws Exception { 91 public TabPersistentStore call() throws Exception {
80 TabPersistencePolicy persistencePolicy = new TabbedModeTabPersis tencePolicy( 92 TabPersistencePolicy persistencePolicy = new TabbedModeTabPersis tencePolicy(
81 selectorIndex, false); 93 selectorIndex, false);
82 TabPersistentStore store = new TabPersistentStore( 94 TabPersistentStore store = new TabPersistentStore(
83 persistencePolicy, selector, null, null); 95 persistencePolicy, selector, null, null);
84 return store; 96 return store;
85 } 97 }
86 }); 98 });
87 } 99 }
88 100
89 /** 101 /**
90 * Test that normal migration of state files works. 102 * Test that normal migration of state files works.
91 * @throws IOException 103 * @throws IOException
92 * @throws InterruptedException 104 * @throws InterruptedException
93 * @throws ExecutionException 105 * @throws ExecutionException
94 */ 106 */
107 @Test
95 @SuppressWarnings("unused") 108 @SuppressWarnings("unused")
96 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") 109 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
97 @SmallTest 110 @SmallTest
98 @Feature({"TabPersistentStore"}) 111 @Feature({"TabPersistentStore"})
112 @UiThreadTest
99 public void testMigrateData() throws IOException, InterruptedException, Exec utionException { 113 public void testMigrateData() throws IOException, InterruptedException, Exec utionException {
100 ApplicationData.clearAppData(mAppContext); 114 ApplicationData.clearAppData(mAppContext);
101 115
102 // Write old state files. 116 // Write old state files.
103 File filesDir = mAppContext.getFilesDir(); 117 File filesDir = mAppContext.getFilesDir();
104 File stateFile = new File(filesDir, TabbedModeTabPersistencePolicy.LEGAC Y_SAVED_STATE_FILE); 118 File stateFile = new File(filesDir, TabbedModeTabPersistencePolicy.LEGAC Y_SAVED_STATE_FILE);
105 File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0 "); 119 File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0 ");
106 File tab1 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "1 "); 120 File tab1 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "1 ");
107 File tab2 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "2"); 121 File tab2 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "2");
108 File tab3 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "3"); 122 File tab3 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "3");
109 123
110 assertTrue("Could not create state file", stateFile.createNewFile()); 124 Assert.assertTrue("Could not create state file", stateFile.createNewFile ());
111 assertTrue("Could not create tab 0 file", tab0.createNewFile()); 125 Assert.assertTrue("Could not create tab 0 file", tab0.createNewFile());
112 assertTrue("Could not create tab 1 file", tab1.createNewFile()); 126 Assert.assertTrue("Could not create tab 1 file", tab1.createNewFile());
113 assertTrue("Could not create tab 2 file", tab2.createNewFile()); 127 Assert.assertTrue("Could not create tab 2 file", tab2.createNewFile());
114 assertTrue("Could not create tab 3 file", tab3.createNewFile()); 128 Assert.assertTrue("Could not create tab 3 file", tab3.createNewFile());
115 129
116 // Build the TabPersistentStore which will try to move the files. 130 // Build the TabPersistentStore which will try to move the files.
117 MockTabModelSelector selector = new MockTabModelSelector(0, 0, null); 131 MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
118 TabPersistentStore store = buildTabPersistentStore(selector, 0); 132 TabPersistentStore store = buildTabPersistentStore(selector, 0);
119 store.waitForMigrationToFinish(); 133 store.waitForMigrationToFinish();
120 134
121 // Make sure we don't hit the migration path again. 135 // Make sure we don't hit the migration path again.
122 assertTrue(ContextUtils.getAppSharedPreferences().getBoolean( 136 Assert.assertTrue(ContextUtils.getAppSharedPreferences().getBoolean(
123 TabbedModeTabPersistencePolicy.PREF_HAS_RUN_FILE_MIGRATION, fals e)); 137 TabbedModeTabPersistencePolicy.PREF_HAS_RUN_FILE_MIGRATION, fals e));
124 138
125 // Check that the files were moved. 139 // Check that the files were moved.
126 File newDir = TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateD irectory(); 140 File newDir = TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateD irectory();
127 File newStateFile = new File(newDir, TabbedModeTabPersistencePolicy.getS tateFileName(0)); 141 File newStateFile = new File(newDir, TabbedModeTabPersistencePolicy.getS tateFileName(0));
128 File newTab0 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 0"); 142 File newTab0 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 0");
129 File newTab1 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 1"); 143 File newTab1 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 1");
130 File newTab2 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "2"); 144 File newTab2 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "2");
131 File newTab3 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "3"); 145 File newTab3 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "3");
132 146
133 assertTrue("Could not find new state file", newStateFile.exists()); 147 Assert.assertTrue("Could not find new state file", newStateFile.exists() );
134 assertTrue("Could not find new tab 0 file", newTab0.exists()); 148 Assert.assertTrue("Could not find new tab 0 file", newTab0.exists());
135 assertTrue("Could not find new tab 1 file", newTab1.exists()); 149 Assert.assertTrue("Could not find new tab 1 file", newTab1.exists());
136 assertTrue("Could not find new tab 2 file", newTab2.exists()); 150 Assert.assertTrue("Could not find new tab 2 file", newTab2.exists());
137 assertTrue("Could not find new tab 3 file", newTab3.exists()); 151 Assert.assertTrue("Could not find new tab 3 file", newTab3.exists());
138 152
139 assertFalse("Could still find old state file", stateFile.exists()); 153 Assert.assertFalse("Could still find old state file", stateFile.exists() );
140 assertFalse("Could still find old tab 0 file", tab0.exists()); 154 Assert.assertFalse("Could still find old tab 0 file", tab0.exists());
141 assertFalse("Could still find old tab 1 file", tab1.exists()); 155 Assert.assertFalse("Could still find old tab 1 file", tab1.exists());
142 assertFalse("Could still find old tab 2 file", tab2.exists()); 156 Assert.assertFalse("Could still find old tab 2 file", tab2.exists());
143 assertFalse("Could still find old tab 3 file", tab3.exists()); 157 Assert.assertFalse("Could still find old tab 3 file", tab3.exists());
144 158
145 ApplicationData.clearAppData(mAppContext); 159 ApplicationData.clearAppData(mAppContext);
146 } 160 }
147 161
148 /** 162 /**
149 * Test that migration skips if it already has files in the new folder. 163 * Test that migration skips if it already has files in the new folder.
150 * @throws IOException 164 * @throws IOException
151 * @throws InterruptedException 165 * @throws InterruptedException
152 * @throws ExecutionException 166 * @throws ExecutionException
153 */ 167 */
168 @Test
154 @SuppressWarnings("unused") 169 @SuppressWarnings("unused")
155 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") 170 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
156 @SmallTest 171 @SmallTest
157 @Feature({"TabPersistentStore"}) 172 @Feature({"TabPersistentStore"})
173 @UiThreadTest
158 public void testSkipMigrateData() throws IOException, InterruptedException, ExecutionException { 174 public void testSkipMigrateData() throws IOException, InterruptedException, ExecutionException {
159 ApplicationData.clearAppData(mAppContext); 175 ApplicationData.clearAppData(mAppContext);
160 176
161 // Write old state files. 177 // Write old state files.
162 File filesDir = mAppContext.getFilesDir(); 178 File filesDir = mAppContext.getFilesDir();
163 File stateFile = new File(filesDir, TabbedModeTabPersistencePolicy.LEGAC Y_SAVED_STATE_FILE); 179 File stateFile = new File(filesDir, TabbedModeTabPersistencePolicy.LEGAC Y_SAVED_STATE_FILE);
164 File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0 "); 180 File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0 ");
165 File tab1 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "1 "); 181 File tab1 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "1 ");
166 File tab2 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "2"); 182 File tab2 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "2");
167 File tab3 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "3"); 183 File tab3 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INCO GNITO + "3");
168 184
169 assertTrue("Could not create state file", stateFile.createNewFile()); 185 Assert.assertTrue("Could not create state file", stateFile.createNewFile ());
170 assertTrue("Could not create tab 0 file", tab0.createNewFile()); 186 Assert.assertTrue("Could not create tab 0 file", tab0.createNewFile());
171 assertTrue("Could not create tab 1 file", tab1.createNewFile()); 187 Assert.assertTrue("Could not create tab 1 file", tab1.createNewFile());
172 assertTrue("Could not create tab 2 file", tab2.createNewFile()); 188 Assert.assertTrue("Could not create tab 2 file", tab2.createNewFile());
173 assertTrue("Could not create tab 3 file", tab3.createNewFile()); 189 Assert.assertTrue("Could not create tab 3 file", tab3.createNewFile());
174 190
175 // Write new state files 191 // Write new state files
176 File newDir = TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateD irectory(); 192 File newDir = TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateD irectory();
177 File newStateFile = new File(newDir, TabbedModeTabPersistencePolicy.getS tateFileName(0)); 193 File newStateFile = new File(newDir, TabbedModeTabPersistencePolicy.getS tateFileName(0));
178 File newTab4 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 4"); 194 File newTab4 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 4");
179 195
180 assertTrue("Could not create new tab 4 file", newTab4.createNewFile()); 196 Assert.assertTrue("Could not create new tab 4 file", newTab4.createNewFi le());
181 assertTrue("Could not create new state file", newStateFile.createNewFile ()); 197 Assert.assertTrue("Could not create new state file", newStateFile.create NewFile());
182 198
183 // Build the TabPersistentStore which will try to move the files. 199 // Build the TabPersistentStore which will try to move the files.
184 MockTabModelSelector selector = new MockTabModelSelector(0, 0, null); 200 MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
185 TabPersistentStore store = buildTabPersistentStore(selector, 0); 201 TabPersistentStore store = buildTabPersistentStore(selector, 0);
186 store.waitForMigrationToFinish(); 202 store.waitForMigrationToFinish();
187 203
188 assertTrue("Could not find new state file", newStateFile.exists()); 204 Assert.assertTrue("Could not find new state file", newStateFile.exists() );
189 assertTrue("Could not find new tab 4 file", newTab4.exists()); 205 Assert.assertTrue("Could not find new tab 4 file", newTab4.exists());
190 206
191 // Make sure the old files did not move 207 // Make sure the old files did not move
192 File newTab0 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 0"); 208 File newTab0 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 0");
193 File newTab1 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 1"); 209 File newTab1 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 1");
194 File newTab2 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "2"); 210 File newTab2 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "2");
195 File newTab3 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "3"); 211 File newTab3 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX_INC OGNITO + "3");
196 212
197 assertFalse("Could find new tab 0 file", newTab0.exists()); 213 Assert.assertFalse("Could find new tab 0 file", newTab0.exists());
198 assertFalse("Could find new tab 1 file", newTab1.exists()); 214 Assert.assertFalse("Could find new tab 1 file", newTab1.exists());
199 assertFalse("Could find new tab 2 file", newTab2.exists()); 215 Assert.assertFalse("Could find new tab 2 file", newTab2.exists());
200 assertFalse("Could find new tab 3 file", newTab3.exists()); 216 Assert.assertFalse("Could find new tab 3 file", newTab3.exists());
201 217
202 ApplicationData.clearAppData(mAppContext); 218 ApplicationData.clearAppData(mAppContext);
203 } 219 }
204 220
205 /** 221 /**
206 * Test that the state file migration skips unrelated files. 222 * Test that the state file migration skips unrelated files.
207 * @throws IOException 223 * @throws IOException
208 * @throws InterruptedException 224 * @throws InterruptedException
209 * @throws ExecutionException 225 * @throws ExecutionException
210 */ 226 */
227 @Test
211 @SuppressWarnings("unused") 228 @SuppressWarnings("unused")
212 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") 229 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
213 @SmallTest 230 @SmallTest
214 @Feature({"TabPersistentStore"}) 231 @Feature({"TabPersistentStore"})
215 public void testMigrationLeavesOtherFilesAlone() throws IOException, Interru ptedException, 232 @UiThreadTest
216 ExecutionException { 233 public void testMigrationLeavesOtherFilesAlone()
234 throws IOException, InterruptedException, ExecutionException {
217 ApplicationData.clearAppData(mAppContext); 235 ApplicationData.clearAppData(mAppContext);
218 236
219 // Write old state files. 237 // Write old state files.
220 File filesDir = mAppContext.getFilesDir(); 238 File filesDir = mAppContext.getFilesDir();
221 File stateFile = new File(filesDir, TabbedModeTabPersistencePolicy.LEGAC Y_SAVED_STATE_FILE); 239 File stateFile = new File(filesDir, TabbedModeTabPersistencePolicy.LEGAC Y_SAVED_STATE_FILE);
222 File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0 "); 240 File tab0 = new File(filesDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + "0 ");
223 File otherFile = new File(filesDir, "other.file"); 241 File otherFile = new File(filesDir, "other.file");
224 242
225 assertTrue("Could not create state file", stateFile.createNewFile()); 243 Assert.assertTrue("Could not create state file", stateFile.createNewFile ());
226 assertTrue("Could not create tab 0 file", tab0.createNewFile()); 244 Assert.assertTrue("Could not create tab 0 file", tab0.createNewFile());
227 assertTrue("Could not create other file", otherFile.createNewFile()); 245 Assert.assertTrue("Could not create other file", otherFile.createNewFile ());
228 246
229 // Build the TabPersistentStore which will try to move the files. 247 // Build the TabPersistentStore which will try to move the files.
230 MockTabModelSelector selector = new MockTabModelSelector(0, 0, null); 248 MockTabModelSelector selector = new MockTabModelSelector(0, 0, null);
231 TabPersistentStore store = buildTabPersistentStore(selector, 0); 249 TabPersistentStore store = buildTabPersistentStore(selector, 0);
232 store.waitForMigrationToFinish(); 250 store.waitForMigrationToFinish();
233 251
234 assertFalse("Could still find old state file", stateFile.exists()); 252 Assert.assertFalse("Could still find old state file", stateFile.exists() );
235 assertFalse("Could still find old tab 0 file", tab0.exists()); 253 Assert.assertFalse("Could still find old tab 0 file", tab0.exists());
236 assertTrue("Could not find other file", otherFile.exists()); 254 Assert.assertTrue("Could not find other file", otherFile.exists());
237 255
238 // Check that the files were moved. 256 // Check that the files were moved.
239 File newDir = TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateD irectory(); 257 File newDir = TabbedModeTabPersistencePolicy.getOrCreateTabbedModeStateD irectory();
240 File newStateFile = new File(newDir, TabbedModeTabPersistencePolicy.getS tateFileName(0)); 258 File newStateFile = new File(newDir, TabbedModeTabPersistencePolicy.getS tateFileName(0));
241 File newTab0 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 0"); 259 File newTab0 = new File(newDir, TabState.SAVED_TAB_STATE_FILE_PREFIX + " 0");
242 File newOtherFile = new File(newDir, "other.file"); 260 File newOtherFile = new File(newDir, "other.file");
243 261
244 assertTrue("Could not find new state file", newStateFile.exists()); 262 Assert.assertTrue("Could not find new state file", newStateFile.exists() );
245 assertTrue("Could not find new tab 0 file", newTab0.exists()); 263 Assert.assertTrue("Could not find new tab 0 file", newTab0.exists());
246 assertFalse("Could find new other file", newOtherFile.exists()); 264 Assert.assertFalse("Could find new other file", newOtherFile.exists());
247 265
248 ApplicationData.clearAppData(mAppContext); 266 ApplicationData.clearAppData(mAppContext);
249 } 267 }
250 268
251 /** 269 /**
252 * Tests that the max id returned is the max of all of the tab models. 270 * Tests that the max id returned is the max of all of the tab models.
253 * @throws IOException 271 * @throws IOException
254 */ 272 */
273 @Test
255 @SmallTest 274 @SmallTest
256 @Feature({"TabPersistentStore"}) 275 @Feature({"TabPersistentStore"})
276 @UiThreadTest
257 @RetryOnFailure 277 @RetryOnFailure
258 public void testFindsMaxIdProperly() throws IOException { 278 public void testFindsMaxIdProperly() throws IOException {
259 TabModelSelector selector0 = new MockTabModelSelector(1, 1, null); 279 TabModelSelector selector0 = new MockTabModelSelector(1, 1, null);
260 TabModelSelector selector1 = new MockTabModelSelector(1, 1, null); 280 TabModelSelector selector1 = new MockTabModelSelector(1, 1, null);
261 281
262 writeStateFile(selector0, 0); 282 writeStateFile(selector0, 0);
263 writeStateFile(selector1, 1); 283 writeStateFile(selector1, 1);
264 284
265 TabModelSelector selectorIn = new MockTabModelSelector(0, 0, null); 285 TabModelSelector selectorIn = new MockTabModelSelector(0, 0, null);
266 TabPersistentStore storeIn = buildTabPersistentStore(selectorIn, 0); 286 TabPersistentStore storeIn = buildTabPersistentStore(selectorIn, 0);
267 287
268 int maxId = Math.max(getMaxId(selector0), getMaxId(selector1)); 288 int maxId = Math.max(getMaxId(selector0), getMaxId(selector1));
269 try { 289 try {
270 RecordHistogram.setDisabledForTests(true); 290 RecordHistogram.setDisabledForTests(true);
271 storeIn.loadState(false /* ignoreIncognitoFiles */); 291 storeIn.loadState(false /* ignoreIncognitoFiles */);
272 assertEquals("Invalid next id", maxId + 1, 292 Assert.assertEquals("Invalid next id", maxId + 1,
273 TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_I D)); 293 TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_I D));
274 } finally { 294 } finally {
275 RecordHistogram.setDisabledForTests(false); 295 RecordHistogram.setDisabledForTests(false);
276 } 296 }
277 } 297 }
278 298
279 /** 299 /**
280 * Tests that each model loads the subset of tabs it is responsible for. In this case, just 300 * Tests that each model loads the subset of tabs it is responsible for. In this case, just
281 * check that the model has the expected number of tabs to load. Since each model is loading 301 * check that the model has the expected number of tabs to load. Since each model is loading
282 * a different number of tabs we can tell if they are each attempting to loa d their specific 302 * a different number of tabs we can tell if they are each attempting to loa d their specific
283 * set. 303 * set.
284 * @throws IOException 304 * @throws IOException
285 */ 305 */
306 @Test
286 @SmallTest 307 @SmallTest
287 @Feature({"TabPersistentStore"}) 308 @Feature({"TabPersistentStore"})
309 @UiThreadTest
288 public void testOnlyLoadsSingleModel() throws IOException { 310 public void testOnlyLoadsSingleModel() throws IOException {
289 TabModelSelector selector0 = new MockTabModelSelector(3, 3, null); 311 TabModelSelector selector0 = new MockTabModelSelector(3, 3, null);
290 TabModelSelector selector1 = new MockTabModelSelector(2, 1, null); 312 TabModelSelector selector1 = new MockTabModelSelector(2, 1, null);
291 313
292 writeStateFile(selector0, 0); 314 writeStateFile(selector0, 0);
293 writeStateFile(selector1, 1); 315 writeStateFile(selector1, 1);
294 316
295 TabModelSelector selectorIn0 = new MockTabModelSelector(0, 0, null); 317 TabModelSelector selectorIn0 = new MockTabModelSelector(0, 0, null);
296 TabModelSelector selectorIn1 = new MockTabModelSelector(0, 0, null); 318 TabModelSelector selectorIn1 = new MockTabModelSelector(0, 0, null);
297 319
298 TabPersistentStore storeIn0 = buildTabPersistentStore(selectorIn0, 0); 320 TabPersistentStore storeIn0 = buildTabPersistentStore(selectorIn0, 0);
299 321
300 TabPersistentStore storeIn1 = buildTabPersistentStore(selectorIn1, 1); 322 TabPersistentStore storeIn1 = buildTabPersistentStore(selectorIn1, 1);
301 323
302 try { 324 try {
303 RecordHistogram.setDisabledForTests(true); 325 RecordHistogram.setDisabledForTests(true);
304 storeIn0.loadState(false /* ignoreIncognitoFiles */); 326 storeIn0.loadState(false /* ignoreIncognitoFiles */);
305 storeIn1.loadState(false /* ignoreIncognitoFiles */); 327 storeIn1.loadState(false /* ignoreIncognitoFiles */);
306 } finally { 328 } finally {
307 RecordHistogram.setDisabledForTests(false); 329 RecordHistogram.setDisabledForTests(false);
308 } 330 }
309 331
310 assertEquals("Unexpected number of tabs to load", 6, storeIn0.getRestore dTabCount()); 332 Assert.assertEquals("Unexpected number of tabs to load", 6, storeIn0.get RestoredTabCount());
311 assertEquals("Unexpected number of tabs to load", 3, storeIn1.getRestore dTabCount()); 333 Assert.assertEquals("Unexpected number of tabs to load", 3, storeIn1.get RestoredTabCount());
312
313 } 334 }
314 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698