OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
9 #include "base/win_util.h" | 9 #include "base/win_util.h" |
10 #endif | 10 #endif |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 int new_tab_count = 0; | 74 int new_tab_count = 0; |
75 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); | 75 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); |
76 EXPECT_EQ(++tab_count, new_tab_count); | 76 EXPECT_EQ(++tab_count, new_tab_count); |
77 } | 77 } |
78 | 78 |
79 // Get a handle to the restored tab. | 79 // Get a handle to the restored tab. |
80 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 80 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
81 ASSERT_GT(tab_count, expected_tabstrip_index); | 81 ASSERT_GT(tab_count, expected_tabstrip_index); |
82 scoped_refptr<TabProxy> restored_tab_proxy( | 82 scoped_refptr<TabProxy> restored_tab_proxy( |
83 browser_proxy->GetTab(expected_tabstrip_index)); | 83 browser_proxy->GetTab(expected_tabstrip_index)); |
| 84 ASSERT_TRUE(restored_tab_proxy.get()); |
84 // Wait for the restored tab to finish loading. | 85 // Wait for the restored tab to finish loading. |
85 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored( | 86 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored( |
86 action_max_timeout_ms())); | 87 action_max_timeout_ms())); |
87 | 88 |
88 // Ensure that the tab and window are active. | 89 // Ensure that the tab and window are active. |
89 CheckActiveWindow(browser_proxy.get()); | 90 CheckActiveWindow(browser_proxy.get()); |
90 EXPECT_EQ(expected_tabstrip_index, | 91 EXPECT_EQ(expected_tabstrip_index, |
91 GetActiveTabIndex(expected_window_index)); | 92 GetActiveTabIndex(expected_window_index)); |
92 } | 93 } |
93 | 94 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // in its original position, and active. | 143 // in its original position, and active. |
143 TEST_F(TabRestoreUITest, Basic) { | 144 TEST_F(TabRestoreUITest, Basic) { |
144 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 145 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
145 | 146 |
146 int starting_tab_count; | 147 int starting_tab_count; |
147 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); | 148 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
148 int tab_count = AddSomeTabs(browser_proxy.get(), 1); | 149 int tab_count = AddSomeTabs(browser_proxy.get(), 1); |
149 | 150 |
150 int closed_tab_index = tab_count - 1; | 151 int closed_tab_index = tab_count - 1; |
151 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 152 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 153 ASSERT_TRUE(new_tab.get()); |
152 // Make sure we're at url. | 154 // Make sure we're at url. |
153 new_tab->NavigateToURL(url1_); | 155 new_tab->NavigateToURL(url1_); |
154 // Close the tab. | 156 // Close the tab. |
155 new_tab->Close(true); | 157 new_tab->Close(true); |
156 new_tab = NULL; | 158 new_tab = NULL; |
157 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 159 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
158 EXPECT_EQ(starting_tab_count, tab_count); | 160 EXPECT_EQ(starting_tab_count, tab_count); |
159 | 161 |
160 RestoreTab(0, closed_tab_index); | 162 RestoreTab(0, closed_tab_index); |
161 | 163 |
162 // And make sure everything looks right. | 164 // And make sure everything looks right. |
163 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 165 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
164 EXPECT_EQ(starting_tab_count + 1, tab_count); | 166 EXPECT_EQ(starting_tab_count + 1, tab_count); |
165 EXPECT_EQ(closed_tab_index, GetActiveTabIndex()); | 167 EXPECT_EQ(closed_tab_index, GetActiveTabIndex()); |
166 EXPECT_EQ(url1_, GetActiveTabURL()); | 168 EXPECT_EQ(url1_, GetActiveTabURL()); |
167 } | 169 } |
168 | 170 |
169 // Close a tab not at the end of the current window, then restore it. The tab | 171 // Close a tab not at the end of the current window, then restore it. The tab |
170 // should be in its original position, and active. | 172 // should be in its original position, and active. |
171 TEST_F(TabRestoreUITest, MiddleTab) { | 173 TEST_F(TabRestoreUITest, MiddleTab) { |
172 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 174 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
173 | 175 |
174 int starting_tab_count; | 176 int starting_tab_count; |
175 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); | 177 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
176 int tab_count = AddSomeTabs(browser_proxy.get(), 3); | 178 int tab_count = AddSomeTabs(browser_proxy.get(), 3); |
177 | 179 |
178 // Close one in the middle | 180 // Close one in the middle |
179 int closed_tab_index = starting_tab_count + 1; | 181 int closed_tab_index = starting_tab_count + 1; |
180 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 182 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 183 ASSERT_TRUE(new_tab.get()); |
181 // Make sure we're at url. | 184 // Make sure we're at url. |
182 new_tab->NavigateToURL(url1_); | 185 new_tab->NavigateToURL(url1_); |
183 // Close the tab. | 186 // Close the tab. |
184 new_tab->Close(true); | 187 new_tab->Close(true); |
185 new_tab = NULL; | 188 new_tab = NULL; |
186 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 189 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
187 EXPECT_EQ(starting_tab_count + 2, tab_count); | 190 EXPECT_EQ(starting_tab_count + 2, tab_count); |
188 | 191 |
189 RestoreTab(0, closed_tab_index); | 192 RestoreTab(0, closed_tab_index); |
190 | 193 |
(...skipping 15 matching lines...) Expand all Loading... |
206 // CheckActiveWindow(). See comments in that function. | 209 // CheckActiveWindow(). See comments in that function. |
207 CheckActiveWindow(browser_proxy.get()); | 210 CheckActiveWindow(browser_proxy.get()); |
208 | 211 |
209 int starting_tab_count; | 212 int starting_tab_count; |
210 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); | 213 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
211 int tab_count = AddSomeTabs(browser_proxy.get(), 3); | 214 int tab_count = AddSomeTabs(browser_proxy.get(), 3); |
212 | 215 |
213 // Close one in the middle | 216 // Close one in the middle |
214 int closed_tab_index = starting_tab_count + 1; | 217 int closed_tab_index = starting_tab_count + 1; |
215 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 218 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 219 ASSERT_TRUE(new_tab.get()); |
216 // Make sure we're at url. | 220 // Make sure we're at url. |
217 new_tab->NavigateToURL(url1_); | 221 new_tab->NavigateToURL(url1_); |
218 // Close the tab. | 222 // Close the tab. |
219 new_tab->Close(true); | 223 new_tab->Close(true); |
220 new_tab = NULL; | 224 new_tab = NULL; |
221 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 225 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
222 EXPECT_EQ(starting_tab_count + 2, tab_count); | 226 EXPECT_EQ(starting_tab_count + 2, tab_count); |
223 | 227 |
224 // Create a new browser. | 228 // Create a new browser. |
225 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 229 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
(...skipping 19 matching lines...) Expand all Loading... |
245 TEST_F(TabRestoreUITest, MAYBE_BasicRestoreFromClosedWindow) { | 249 TEST_F(TabRestoreUITest, MAYBE_BasicRestoreFromClosedWindow) { |
246 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 250 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
247 CheckActiveWindow(browser_proxy.get()); | 251 CheckActiveWindow(browser_proxy.get()); |
248 | 252 |
249 int tab_count; | 253 int tab_count; |
250 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 254 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
251 | 255 |
252 // Close tabs until we only have one open. | 256 // Close tabs until we only have one open. |
253 while (tab_count > 1) { | 257 while (tab_count > 1) { |
254 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); | 258 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); |
| 259 ASSERT_TRUE(tab_to_close.get()); |
255 tab_to_close->Close(true); | 260 tab_to_close->Close(true); |
256 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 261 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
257 } | 262 } |
258 | 263 |
259 // Navigate to url1 then url2. | 264 // Navigate to url1 then url2. |
260 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 265 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 266 ASSERT_TRUE(tab_proxy.get()); |
261 tab_proxy->NavigateToURL(url1_); | 267 tab_proxy->NavigateToURL(url1_); |
262 tab_proxy->NavigateToURL(url2_); | 268 tab_proxy->NavigateToURL(url2_); |
263 | 269 |
264 // Create a new browser. | 270 // Create a new browser. |
265 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 271 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
266 int window_count; | 272 int window_count; |
267 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 273 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
268 EXPECT_EQ(2, window_count); | 274 EXPECT_EQ(2, window_count); |
269 CheckActiveWindow(automation()->GetBrowserWindow(1)); | 275 CheckActiveWindow(automation()->GetBrowserWindow(1)); |
270 | 276 |
271 // Close the final tab in the first browser. | 277 // Close the final tab in the first browser. |
272 EXPECT_TRUE(tab_proxy->Close(true)); | 278 EXPECT_TRUE(tab_proxy->Close(true)); |
273 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( | 279 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
274 1, action_max_timeout_ms())); | 280 1, action_max_timeout_ms())); |
275 | 281 |
276 // Tab and browser are no longer valid. | 282 // Tab and browser are no longer valid. |
277 tab_proxy = NULL; | 283 tab_proxy = NULL; |
278 browser_proxy = NULL; | 284 browser_proxy = NULL; |
279 | 285 |
280 RestoreTab(1, 0); | 286 RestoreTab(1, 0); |
281 | 287 |
282 // Tab should be in a new window. | 288 // Tab should be in a new window. |
283 browser_proxy = automation()->GetBrowserWindow(1); | 289 browser_proxy = automation()->GetBrowserWindow(1); |
284 CheckActiveWindow(browser_proxy.get()); | 290 CheckActiveWindow(browser_proxy.get()); |
285 tab_proxy = browser_proxy->GetActiveTab(); | 291 tab_proxy = browser_proxy->GetActiveTab(); |
| 292 ASSERT_TRUE(tab_proxy.get()); |
286 // And make sure the URLs matches. | 293 // And make sure the URLs matches. |
287 EXPECT_EQ(url2_, GetActiveTabURL(1)); | 294 EXPECT_EQ(url2_, GetActiveTabURL(1)); |
288 EXPECT_TRUE(tab_proxy->GoBack()); | 295 EXPECT_TRUE(tab_proxy->GoBack()); |
289 EXPECT_EQ(url1_, GetActiveTabURL(1)); | 296 EXPECT_EQ(url1_, GetActiveTabURL(1)); |
290 } | 297 } |
291 | 298 |
292 // Restore a tab then make sure it doesn't restore again. | 299 // Restore a tab then make sure it doesn't restore again. |
293 // Disabled because the command updater doesn't know the proper state of | 300 // Disabled because the command updater doesn't know the proper state of |
294 // the tab restore command. http://crbug.com/14428. | 301 // the tab restore command. http://crbug.com/14428. |
295 TEST_F(TabRestoreUITest, DISABLED_DontLoadRestoredTab) { | 302 TEST_F(TabRestoreUITest, DISABLED_DontLoadRestoredTab) { |
296 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 303 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
297 CheckActiveWindow(browser_proxy.get()); | 304 CheckActiveWindow(browser_proxy.get()); |
298 | 305 |
299 // Add two tabs | 306 // Add two tabs |
300 int starting_tab_count = 0; | 307 int starting_tab_count = 0; |
301 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); | 308 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
302 AddSomeTabs(browser_proxy.get(), 2); | 309 AddSomeTabs(browser_proxy.get(), 2); |
303 int current_tab_count = 0; | 310 int current_tab_count = 0; |
304 ASSERT_TRUE(browser_proxy->GetTabCount(¤t_tab_count)); | 311 ASSERT_TRUE(browser_proxy->GetTabCount(¤t_tab_count)); |
305 ASSERT_EQ(current_tab_count, starting_tab_count + 2); | 312 ASSERT_EQ(current_tab_count, starting_tab_count + 2); |
306 | 313 |
307 // Close one of them. | 314 // Close one of them. |
308 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); | 315 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); |
| 316 ASSERT_TRUE(tab_to_close.get()); |
309 tab_to_close->Close(true); | 317 tab_to_close->Close(true); |
310 ASSERT_TRUE(browser_proxy->GetTabCount(¤t_tab_count)); | 318 ASSERT_TRUE(browser_proxy->GetTabCount(¤t_tab_count)); |
311 ASSERT_EQ(current_tab_count, starting_tab_count + 1); | 319 ASSERT_EQ(current_tab_count, starting_tab_count + 1); |
312 | 320 |
313 // Restore it. | 321 // Restore it. |
314 RestoreTab(0, 0); | 322 RestoreTab(0, 0); |
315 ASSERT_TRUE(browser_proxy->GetTabCount(¤t_tab_count)); | 323 ASSERT_TRUE(browser_proxy->GetTabCount(¤t_tab_count)); |
316 ASSERT_EQ(current_tab_count, starting_tab_count + 2); | 324 ASSERT_EQ(current_tab_count, starting_tab_count + 2); |
317 | 325 |
318 // Make sure that there's nothing else to restore. | 326 // Make sure that there's nothing else to restore. |
(...skipping 14 matching lines...) Expand all Loading... |
333 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 341 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
334 CheckActiveWindow(browser_proxy.get()); | 342 CheckActiveWindow(browser_proxy.get()); |
335 | 343 |
336 int starting_tab_count; | 344 int starting_tab_count; |
337 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); | 345 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
338 int tab_count = AddSomeTabs(browser_proxy.get(), 3); | 346 int tab_count = AddSomeTabs(browser_proxy.get(), 3); |
339 | 347 |
340 // Close one in the middle | 348 // Close one in the middle |
341 int closed_tab_index = starting_tab_count + 1; | 349 int closed_tab_index = starting_tab_count + 1; |
342 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 350 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 351 ASSERT_TRUE(new_tab.get()); |
343 // Make sure we're at url. | 352 // Make sure we're at url. |
344 new_tab->NavigateToURL(url1_); | 353 new_tab->NavigateToURL(url1_); |
345 // Close the tab. | 354 // Close the tab. |
346 new_tab->Close(true); | 355 new_tab->Close(true); |
347 new_tab = NULL; | 356 new_tab = NULL; |
348 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 357 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
349 EXPECT_EQ(starting_tab_count + 2, tab_count); | 358 EXPECT_EQ(starting_tab_count + 2, tab_count); |
350 | 359 |
351 // Create a new browser. | 360 // Create a new browser. |
352 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 361 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 TEST_F(TabRestoreUITest, RestoreIntoSameWindow) { | 395 TEST_F(TabRestoreUITest, RestoreIntoSameWindow) { |
387 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 396 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
388 CheckActiveWindow(browser_proxy.get()); | 397 CheckActiveWindow(browser_proxy.get()); |
389 | 398 |
390 int starting_tab_count; | 399 int starting_tab_count; |
391 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); | 400 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
392 int tab_count = AddSomeTabs(browser_proxy.get(), 2); | 401 int tab_count = AddSomeTabs(browser_proxy.get(), 2); |
393 | 402 |
394 // Navigate the rightmost one to url2_ for easier identification. | 403 // Navigate the rightmost one to url2_ for easier identification. |
395 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 1)); | 404 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 1)); |
| 405 ASSERT_TRUE(tab_proxy.get()); |
396 tab_proxy->NavigateToURL(url2_); | 406 tab_proxy->NavigateToURL(url2_); |
397 | 407 |
398 // Create a new browser. | 408 // Create a new browser. |
399 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 409 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
400 int window_count; | 410 int window_count; |
401 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 411 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
402 EXPECT_EQ(2, window_count); | 412 EXPECT_EQ(2, window_count); |
403 CheckActiveWindow(automation()->GetBrowserWindow(1)); | 413 CheckActiveWindow(automation()->GetBrowserWindow(1)); |
404 | 414 |
405 // Close all but one tab in the first browser, left to right. | 415 // Close all but one tab in the first browser, left to right. |
406 while (tab_count > 1) { | 416 while (tab_count > 1) { |
407 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); | 417 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); |
| 418 ASSERT_TRUE(tab_to_close.get()); |
408 tab_to_close->Close(true); | 419 tab_to_close->Close(true); |
409 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 420 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
410 } | 421 } |
411 | 422 |
412 // Close the last tab, closing the browser. | 423 // Close the last tab, closing the browser. |
413 tab_proxy = browser_proxy->GetTab(0); | 424 tab_proxy = browser_proxy->GetTab(0); |
| 425 ASSERT_TRUE(tab_proxy.get()); |
414 EXPECT_TRUE(tab_proxy->Close(true)); | 426 EXPECT_TRUE(tab_proxy->Close(true)); |
415 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( | 427 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
416 1, action_max_timeout_ms())); | 428 1, action_max_timeout_ms())); |
417 browser_proxy = NULL; | 429 browser_proxy = NULL; |
418 tab_proxy = NULL; | 430 tab_proxy = NULL; |
419 | 431 |
420 // Restore the last-closed tab into a new window. | 432 // Restore the last-closed tab into a new window. |
421 RestoreTab(1, 0); | 433 RestoreTab(1, 0); |
422 browser_proxy = automation()->GetBrowserWindow(1); | 434 browser_proxy = automation()->GetBrowserWindow(1); |
423 CheckActiveWindow(browser_proxy.get()); | 435 CheckActiveWindow(browser_proxy.get()); |
(...skipping 22 matching lines...) Expand all Loading... |
446 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 458 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
447 int tab_count; | 459 int tab_count; |
448 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 460 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
449 | 461 |
450 // Add a tab | 462 // Add a tab |
451 browser_proxy->AppendTab(http_url1); | 463 browser_proxy->AppendTab(http_url1); |
452 int new_tab_count; | 464 int new_tab_count; |
453 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); | 465 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); |
454 EXPECT_EQ(++tab_count, new_tab_count); | 466 EXPECT_EQ(++tab_count, new_tab_count); |
455 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1)); | 467 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1)); |
| 468 ASSERT_TRUE(tab.get()); |
456 | 469 |
457 // Navigate to another same-site URL. | 470 // Navigate to another same-site URL. |
458 tab->NavigateToURL(http_url2); | 471 tab->NavigateToURL(http_url2); |
459 | 472 |
460 // Close the tab. | 473 // Close the tab. |
461 tab->Close(true); | 474 tab->Close(true); |
462 tab = NULL; | 475 tab = NULL; |
463 | 476 |
464 // Create a new tab to the original site. Assuming process-per-site is | 477 // Create a new tab to the original site. Assuming process-per-site is |
465 // enabled, this will ensure that the SiteInstance used by the restored tab | 478 // enabled, this will ensure that the SiteInstance used by the restored tab |
466 // will already exist when the restore happens. | 479 // will already exist when the restore happens. |
467 browser_proxy->AppendTab(http_url2); | 480 browser_proxy->AppendTab(http_url2); |
468 | 481 |
469 // Restore the closed tab. | 482 // Restore the closed tab. |
470 RestoreTab(0, tab_count - 1); | 483 RestoreTab(0, tab_count - 1); |
471 tab = browser_proxy->GetActiveTab(); | 484 tab = browser_proxy->GetActiveTab(); |
| 485 ASSERT_TRUE(tab.get()); |
472 | 486 |
473 // And make sure the URLs match. | 487 // And make sure the URLs match. |
474 EXPECT_EQ(http_url2, GetActiveTabURL()); | 488 EXPECT_EQ(http_url2, GetActiveTabURL()); |
475 EXPECT_TRUE(tab->GoBack()); | 489 EXPECT_TRUE(tab->GoBack()); |
476 EXPECT_EQ(http_url1, GetActiveTabURL()); | 490 EXPECT_EQ(http_url1, GetActiveTabURL()); |
477 } | 491 } |
478 | 492 |
479 // Tests that the SiteInstances used for entries in a restored tab's history | 493 // Tests that the SiteInstances used for entries in a restored tab's history |
480 // are given appropriate max page IDs, even if the renderer for the entry | 494 // are given appropriate max page IDs, even if the renderer for the entry |
481 // already exists. (Bug 1204135) | 495 // already exists. (Bug 1204135) |
482 TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { | 496 TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { |
483 const wchar_t kDocRoot[] = L"chrome/test/data"; | 497 const wchar_t kDocRoot[] = L"chrome/test/data"; |
484 scoped_refptr<HTTPTestServer> server = | 498 scoped_refptr<HTTPTestServer> server = |
485 HTTPTestServer::CreateServer(kDocRoot, NULL); | 499 HTTPTestServer::CreateServer(kDocRoot, NULL); |
486 ASSERT_TRUE(NULL != server.get()); | 500 ASSERT_TRUE(NULL != server.get()); |
487 GURL http_url1(server->TestServerPageW(L"files/title1.html")); | 501 GURL http_url1(server->TestServerPageW(L"files/title1.html")); |
488 GURL http_url2(server->TestServerPageW(L"files/title2.html")); | 502 GURL http_url2(server->TestServerPageW(L"files/title2.html")); |
489 | 503 |
490 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 504 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
491 int tab_count; | 505 int tab_count; |
492 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 506 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
493 | 507 |
494 // Add a tab | 508 // Add a tab |
495 browser_proxy->AppendTab(http_url1); | 509 browser_proxy->AppendTab(http_url1); |
496 int new_tab_count; | 510 int new_tab_count; |
497 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); | 511 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); |
498 EXPECT_EQ(++tab_count, new_tab_count); | 512 EXPECT_EQ(++tab_count, new_tab_count); |
499 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1)); | 513 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1)); |
| 514 ASSERT_TRUE(tab.get()); |
500 | 515 |
501 // Navigate to more URLs, then a cross-site URL. | 516 // Navigate to more URLs, then a cross-site URL. |
502 tab->NavigateToURL(http_url2); | 517 tab->NavigateToURL(http_url2); |
503 tab->NavigateToURL(http_url1); | 518 tab->NavigateToURL(http_url1); |
504 tab->NavigateToURL(url1_); | 519 tab->NavigateToURL(url1_); |
505 | 520 |
506 // Close the tab. | 521 // Close the tab. |
507 tab->Close(true); | 522 tab->Close(true); |
508 tab = NULL; | 523 tab = NULL; |
509 | 524 |
510 // Create a new tab to the original site. Assuming process-per-site is | 525 // Create a new tab to the original site. Assuming process-per-site is |
511 // enabled, this will ensure that the SiteInstance will already exist when | 526 // enabled, this will ensure that the SiteInstance will already exist when |
512 // the user clicks Back in the restored tab. | 527 // the user clicks Back in the restored tab. |
513 browser_proxy->AppendTab(http_url2); | 528 browser_proxy->AppendTab(http_url2); |
514 | 529 |
515 // Restore the closed tab. | 530 // Restore the closed tab. |
516 RestoreTab(0, tab_count - 1); | 531 RestoreTab(0, tab_count - 1); |
517 tab = browser_proxy->GetActiveTab(); | 532 tab = browser_proxy->GetActiveTab(); |
| 533 ASSERT_TRUE(tab.get()); |
518 | 534 |
519 // And make sure the URLs match. | 535 // And make sure the URLs match. |
520 EXPECT_EQ(url1_, GetActiveTabURL()); | 536 EXPECT_EQ(url1_, GetActiveTabURL()); |
521 EXPECT_TRUE(tab->GoBack()); | 537 EXPECT_TRUE(tab->GoBack()); |
522 EXPECT_EQ(http_url1, GetActiveTabURL()); | 538 EXPECT_EQ(http_url1, GetActiveTabURL()); |
523 | 539 |
524 // Navigating to a new URL should clear the forward list, because the max | 540 // Navigating to a new URL should clear the forward list, because the max |
525 // page ID of the renderer should have been updated when we restored the tab. | 541 // page ID of the renderer should have been updated when we restored the tab. |
526 tab->NavigateToURL(http_url2); | 542 tab->NavigateToURL(http_url2); |
527 EXPECT_FALSE(tab->GoForward()); | 543 EXPECT_FALSE(tab->GoForward()); |
(...skipping 10 matching lines...) Expand all Loading... |
538 EXPECT_EQ(++window_count, new_window_count); | 554 EXPECT_EQ(++window_count, new_window_count); |
539 | 555 |
540 // Create two more tabs, one with url1, the other url2. | 556 // Create two more tabs, one with url1, the other url2. |
541 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 557 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
542 int initial_tab_count; | 558 int initial_tab_count; |
543 ASSERT_TRUE(browser_proxy->GetTabCount(&initial_tab_count)); | 559 ASSERT_TRUE(browser_proxy->GetTabCount(&initial_tab_count)); |
544 browser_proxy->AppendTab(url1_); | 560 browser_proxy->AppendTab(url1_); |
545 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 1, | 561 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 1, |
546 action_max_timeout_ms())); | 562 action_max_timeout_ms())); |
547 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(initial_tab_count)); | 563 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(initial_tab_count)); |
| 564 ASSERT_TRUE(new_tab.get()); |
548 new_tab->NavigateToURL(url1_); | 565 new_tab->NavigateToURL(url1_); |
549 browser_proxy->AppendTab(url2_); | 566 browser_proxy->AppendTab(url2_); |
550 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 2, | 567 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 2, |
551 action_max_timeout_ms())); | 568 action_max_timeout_ms())); |
552 new_tab = browser_proxy->GetTab(initial_tab_count + 1); | 569 new_tab = browser_proxy->GetTab(initial_tab_count + 1); |
| 570 ASSERT_TRUE(new_tab.get()); |
553 new_tab->NavigateToURL(url2_); | 571 new_tab->NavigateToURL(url2_); |
554 | 572 |
555 // Close the window. | 573 // Close the window. |
556 ASSERT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW)); | 574 ASSERT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW)); |
557 browser_proxy = NULL; | 575 browser_proxy = NULL; |
558 new_tab = NULL; | 576 new_tab = NULL; |
559 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); | 577 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); |
560 EXPECT_EQ(window_count - 1, new_window_count); | 578 EXPECT_EQ(window_count - 1, new_window_count); |
561 | 579 |
562 // Restore the window. | 580 // Restore the window. |
563 browser_proxy = automation()->GetBrowserWindow(0); | 581 browser_proxy = automation()->GetBrowserWindow(0); |
564 ASSERT_TRUE(browser_proxy->RunCommand(IDC_RESTORE_TAB)); | 582 ASSERT_TRUE(browser_proxy->RunCommand(IDC_RESTORE_TAB)); |
565 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); | 583 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); |
566 EXPECT_EQ(window_count, new_window_count); | 584 EXPECT_EQ(window_count, new_window_count); |
567 | 585 |
568 browser_proxy = automation()->GetBrowserWindow(1); | 586 browser_proxy = automation()->GetBrowserWindow(1); |
569 int tab_count; | 587 int tab_count; |
570 EXPECT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 588 EXPECT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
571 EXPECT_EQ(initial_tab_count + 2, tab_count); | 589 EXPECT_EQ(initial_tab_count + 2, tab_count); |
572 | 590 |
573 scoped_refptr<TabProxy> restored_tab_proxy( | 591 scoped_refptr<TabProxy> restored_tab_proxy( |
574 browser_proxy->GetTab(initial_tab_count)); | 592 browser_proxy->GetTab(initial_tab_count)); |
| 593 ASSERT_TRUE(restored_tab_proxy.get()); |
575 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 594 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
576 GURL url; | 595 GURL url; |
577 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); | 596 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); |
578 EXPECT_TRUE(url == url1_); | 597 EXPECT_TRUE(url == url1_); |
579 | 598 |
580 restored_tab_proxy = browser_proxy->GetTab(initial_tab_count + 1); | 599 restored_tab_proxy = browser_proxy->GetTab(initial_tab_count + 1); |
| 600 ASSERT_TRUE(restored_tab_proxy.get()); |
581 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 601 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
582 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); | 602 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); |
583 EXPECT_TRUE(url == url2_); | 603 EXPECT_TRUE(url == url2_); |
584 } | 604 } |
OLD | NEW |