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

Side by Side Diff: chrome/browser/sessions/tab_restore_browsertest.cc

Issue 2248873002: Convert WindowOpenDisposition to an enum class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return active_browser_list_->get(index); 100 return active_browser_list_->get(index);
101 } 101 }
102 102
103 // Adds tabs to the given browser, all navigated to url1_. Returns 103 // Adds tabs to the given browser, all navigated to url1_. Returns
104 // the final number of tabs. 104 // the final number of tabs.
105 int AddSomeTabs(Browser* browser, int how_many) { 105 int AddSomeTabs(Browser* browser, int how_many) {
106 int starting_tab_count = browser->tab_strip_model()->count(); 106 int starting_tab_count = browser->tab_strip_model()->count();
107 107
108 for (int i = 0; i < how_many; ++i) { 108 for (int i = 0; i < how_many; ++i) {
109 ui_test_utils::NavigateToURLWithDisposition( 109 ui_test_utils::NavigateToURLWithDisposition(
110 browser, url1_, NEW_FOREGROUND_TAB, 110 browser, url1_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
111 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 111 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
112 } 112 }
113 int tab_count = browser->tab_strip_model()->count(); 113 int tab_count = browser->tab_strip_model()->count();
114 EXPECT_EQ(starting_tab_count + how_many, tab_count); 114 EXPECT_EQ(starting_tab_count + how_many, tab_count);
115 return tab_count; 115 return tab_count;
116 } 116 }
117 117
118 void CloseTab(int index) { 118 void CloseTab(int index) {
119 content::WebContentsDestroyedWatcher destroyed_watcher( 119 content::WebContentsDestroyedWatcher destroyed_watcher(
120 browser()->tab_strip_model()->GetWebContentsAt(index)); 120 browser()->tab_strip_model()->GetWebContentsAt(index));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 // Ensure that the tab and window are active. 173 // Ensure that the tab and window are active.
174 EXPECT_EQ(expected_tabstrip_index, 174 EXPECT_EQ(expected_tabstrip_index,
175 browser->tab_strip_model()->active_index()); 175 browser->tab_strip_model()->active_index());
176 } 176 }
177 177
178 void GoBack(Browser* browser) { 178 void GoBack(Browser* browser) {
179 content::WindowedNotificationObserver observer( 179 content::WindowedNotificationObserver observer(
180 content::NOTIFICATION_LOAD_STOP, 180 content::NOTIFICATION_LOAD_STOP,
181 content::NotificationService::AllSources()); 181 content::NotificationService::AllSources());
182 chrome::GoBack(browser, CURRENT_TAB); 182 chrome::GoBack(browser, WindowOpenDisposition::CURRENT_TAB);
183 observer.Wait(); 183 observer.Wait();
184 } 184 }
185 185
186 void EnsureTabFinishedRestoring(content::WebContents* tab) { 186 void EnsureTabFinishedRestoring(content::WebContents* tab) {
187 content::NavigationController* controller = &tab->GetController(); 187 content::NavigationController* controller = &tab->GetController();
188 if (!controller->NeedsReload() && !controller->GetPendingEntry() && 188 if (!controller->NeedsReload() && !controller->GetPendingEntry() &&
189 !controller->GetWebContents()->IsLoading()) 189 !controller->GetWebContents()->IsLoading())
190 return; 190 return;
191 191
192 content::WindowedNotificationObserver observer( 192 content::WindowedNotificationObserver observer(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 int starting_tab_count = browser()->tab_strip_model()->count(); 249 int starting_tab_count = browser()->tab_strip_model()->count();
250 AddSomeTabs(browser(), 3); 250 AddSomeTabs(browser(), 3);
251 251
252 // Close one in the middle 252 // Close one in the middle
253 int closed_tab_index = starting_tab_count + 1; 253 int closed_tab_index = starting_tab_count + 1;
254 CloseTab(closed_tab_index); 254 CloseTab(closed_tab_index);
255 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count()); 255 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count());
256 256
257 // Create a new browser. 257 // Create a new browser.
258 ui_test_utils::NavigateToURLWithDisposition( 258 ui_test_utils::NavigateToURLWithDisposition(
259 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, 259 browser(), GURL(chrome::kChromeUINewTabURL),
260 WindowOpenDisposition::NEW_WINDOW,
260 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 261 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
261 EXPECT_EQ(2u, active_browser_list_->size()); 262 EXPECT_EQ(2u, active_browser_list_->size());
262 263
263 // Restore tab into original browser. 264 // Restore tab into original browser.
264 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); 265 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index));
265 266
266 // And make sure everything looks right. 267 // And make sure everything looks right.
267 EXPECT_EQ(starting_tab_count + 3, browser()->tab_strip_model()->count()); 268 EXPECT_EQ(starting_tab_count + 3, browser()->tab_strip_model()->count());
268 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index()); 269 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index());
269 EXPECT_EQ(url1_, 270 EXPECT_EQ(url1_,
270 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 271 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
271 } 272 }
272 273
273 // Close a tab, open a new window, close the first window, then restore the 274 // Close a tab, open a new window, close the first window, then restore the
274 // tab. It should be in a new window. 275 // tab. It should be in a new window.
275 // If this becomes flaky, use http://crbug.com/14774 276 // If this becomes flaky, use http://crbug.com/14774
276 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DISABLED_BasicRestoreFromClosedWindow) { 277 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DISABLED_BasicRestoreFromClosedWindow) {
277 // Navigate to url1 then url2. 278 // Navigate to url1 then url2.
278 ui_test_utils::NavigateToURL(browser(), url1_); 279 ui_test_utils::NavigateToURL(browser(), url1_);
279 ui_test_utils::NavigateToURL(browser(), url2_); 280 ui_test_utils::NavigateToURL(browser(), url2_);
280 281
281 // Create a new browser. 282 // Create a new browser.
282 ui_test_utils::NavigateToURLWithDisposition( 283 ui_test_utils::NavigateToURLWithDisposition(
283 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, 284 browser(), GURL(chrome::kChromeUINewTabURL),
285 WindowOpenDisposition::NEW_WINDOW,
284 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 286 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
285 EXPECT_EQ(2u, active_browser_list_->size()); 287 EXPECT_EQ(2u, active_browser_list_->size());
286 288
287 // Close the final tab in the first browser. 289 // Close the final tab in the first browser.
288 content::WindowedNotificationObserver window_observer( 290 content::WindowedNotificationObserver window_observer(
289 chrome::NOTIFICATION_BROWSER_CLOSED, 291 chrome::NOTIFICATION_BROWSER_CLOSED,
290 content::NotificationService::AllSources()); 292 content::NotificationService::AllSources());
291 CloseTab(0); 293 CloseTab(0);
292 window_observer.Wait(); 294 window_observer.Wait();
293 295
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 int starting_tab_count = browser()->tab_strip_model()->count(); 338 int starting_tab_count = browser()->tab_strip_model()->count();
337 AddSomeTabs(browser(), 3); 339 AddSomeTabs(browser(), 3);
338 340
339 // Close one in the middle 341 // Close one in the middle
340 int closed_tab_index = starting_tab_count + 1; 342 int closed_tab_index = starting_tab_count + 1;
341 CloseTab(closed_tab_index); 343 CloseTab(closed_tab_index);
342 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count()); 344 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count());
343 345
344 // Create a new browser. 346 // Create a new browser.
345 ui_test_utils::NavigateToURLWithDisposition( 347 ui_test_utils::NavigateToURLWithDisposition(
346 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, 348 browser(), GURL(chrome::kChromeUINewTabURL),
349 WindowOpenDisposition::NEW_WINDOW,
347 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 350 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
348 EXPECT_EQ(2u, active_browser_list_->size()); 351 EXPECT_EQ(2u, active_browser_list_->size());
349 352
350 // Close the first browser. 353 // Close the first browser.
351 content::WindowedNotificationObserver observer( 354 content::WindowedNotificationObserver observer(
352 chrome::NOTIFICATION_BROWSER_CLOSED, 355 chrome::NOTIFICATION_BROWSER_CLOSED,
353 content::NotificationService::AllSources()); 356 content::NotificationService::AllSources());
354 chrome::CloseWindow(browser()); 357 chrome::CloseWindow(browser());
355 observer.Wait(); 358 observer.Wait();
356 EXPECT_EQ(1u, active_browser_list_->size()); 359 EXPECT_EQ(1u, active_browser_list_->size());
357 360
358 // Restore the first window. The expected_tabstrip_index (second argument) 361 // Restore the first window. The expected_tabstrip_index (second argument)
359 // indicates the expected active tab. 362 // indicates the expected active tab.
360 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1)); 363 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1));
361 Browser* browser = GetBrowser(1); 364 Browser* browser = GetBrowser(1);
362 EXPECT_EQ(starting_tab_count + 2, browser->tab_strip_model()->count()); 365 EXPECT_EQ(starting_tab_count + 2, browser->tab_strip_model()->count());
363 366
364 // Restore the closed tab. 367 // Restore the closed tab.
365 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index)); 368 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index));
366 EXPECT_EQ(starting_tab_count + 3, browser->tab_strip_model()->count()); 369 EXPECT_EQ(starting_tab_count + 3, browser->tab_strip_model()->count());
367 EXPECT_EQ(url1_, 370 EXPECT_EQ(url1_,
368 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 371 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
369 } 372 }
370 373
371 // Open a window with two tabs, close both (closing the window), then restore 374 // Open a window with two tabs, close both (closing the window), then restore
372 // both. Make sure both restored tabs are in the same window. 375 // both. Make sure both restored tabs are in the same window.
373 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) { 376 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) {
374 ui_test_utils::NavigateToURLWithDisposition( 377 ui_test_utils::NavigateToURLWithDisposition(
375 browser(), url1_, NEW_FOREGROUND_TAB, 378 browser(), url1_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
376 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 379 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
377 // Navigate the rightmost one to url2_ for easier identification. 380 // Navigate the rightmost one to url2_ for easier identification.
378 ui_test_utils::NavigateToURLWithDisposition( 381 ui_test_utils::NavigateToURLWithDisposition(
379 browser(), url2_, NEW_FOREGROUND_TAB, 382 browser(), url2_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
380 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 383 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
381 384
382 // Create a new browser. 385 // Create a new browser.
383 ui_test_utils::NavigateToURLWithDisposition( 386 ui_test_utils::NavigateToURLWithDisposition(
384 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, 387 browser(), GURL(chrome::kChromeUINewTabURL),
388 WindowOpenDisposition::NEW_WINDOW,
385 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 389 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
386 EXPECT_EQ(2u, active_browser_list_->size()); 390 EXPECT_EQ(2u, active_browser_list_->size());
387 391
388 // Close all but one tab in the first browser, left to right. 392 // Close all but one tab in the first browser, left to right.
389 while (browser()->tab_strip_model()->count() > 1) 393 while (browser()->tab_strip_model()->count() > 1)
390 CloseTab(0); 394 CloseTab(0);
391 395
392 // Close the last tab, closing the browser. 396 // Close the last tab, closing the browser.
393 content::WindowedNotificationObserver observer( 397 content::WindowedNotificationObserver observer(
394 chrome::NOTIFICATION_BROWSER_CLOSED, 398 chrome::NOTIFICATION_BROWSER_CLOSED,
(...skipping 13 matching lines...) Expand all
408 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); 412 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
409 EXPECT_EQ(2, browser->tab_strip_model()->count()); 413 EXPECT_EQ(2, browser->tab_strip_model()->count());
410 EXPECT_EQ(url1_, 414 EXPECT_EQ(url1_,
411 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 415 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
412 } 416 }
413 417
414 // Open a window with two tabs, close both (closing the window), then restore 418 // Open a window with two tabs, close both (closing the window), then restore
415 // one by ID. Guards against regression of crbug.com/622752. 419 // one by ID. Guards against regression of crbug.com/622752.
416 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabFromClosedWindowByID) { 420 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabFromClosedWindowByID) {
417 ui_test_utils::NavigateToURLWithDisposition( 421 ui_test_utils::NavigateToURLWithDisposition(
418 browser(), url1_, NEW_FOREGROUND_TAB, 422 browser(), url1_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
419 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 423 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
420 ui_test_utils::NavigateToURLWithDisposition( 424 ui_test_utils::NavigateToURLWithDisposition(
421 browser(), url2_, NEW_FOREGROUND_TAB, 425 browser(), url2_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
422 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 426 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
423 427
424 // Create a new browser. 428 // Create a new browser.
425 ui_test_utils::NavigateToURLWithDisposition( 429 ui_test_utils::NavigateToURLWithDisposition(
426 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, 430 browser(), GURL(chrome::kChromeUINewTabURL),
431 WindowOpenDisposition::NEW_WINDOW,
427 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 432 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
428 EXPECT_EQ(2u, active_browser_list_->size()); 433 EXPECT_EQ(2u, active_browser_list_->size());
429 434
430 // Close the window. 435 // Close the window.
431 content::WindowedNotificationObserver close_window_observer( 436 content::WindowedNotificationObserver close_window_observer(
432 chrome::NOTIFICATION_BROWSER_CLOSED, 437 chrome::NOTIFICATION_BROWSER_CLOSED,
433 content::NotificationService::AllSources()); 438 content::NotificationService::AllSources());
434 chrome::CloseWindow(browser()); 439 chrome::CloseWindow(browser());
435 close_window_observer.Wait(); 440 close_window_observer.Wait();
436 EXPECT_EQ(1u, active_browser_list_->size()); 441 EXPECT_EQ(1u, active_browser_list_->size());
(...skipping 26 matching lines...) Expand all
463 468
464 // Restore the tab into the current window. 469 // Restore the tab into the current window.
465 EXPECT_EQ(1, browser->tab_strip_model()->count()); 470 EXPECT_EQ(1, browser->tab_strip_model()->count());
466 content::WindowedNotificationObserver tab_added_observer( 471 content::WindowedNotificationObserver tab_added_observer(
467 chrome::NOTIFICATION_TAB_PARENTED, 472 chrome::NOTIFICATION_TAB_PARENTED,
468 content::NotificationService::AllSources()); 473 content::NotificationService::AllSources());
469 content::WindowedNotificationObserver tab_loaded_observer( 474 content::WindowedNotificationObserver tab_loaded_observer(
470 content::NOTIFICATION_LOAD_STOP, 475 content::NOTIFICATION_LOAD_STOP,
471 content::NotificationService::AllSources()); 476 content::NotificationService::AllSources());
472 service->RestoreEntryById(browser->live_tab_context(), tab_id_to_restore, 477 service->RestoreEntryById(browser->live_tab_context(), tab_id_to_restore,
473 NEW_FOREGROUND_TAB); 478 WindowOpenDisposition::NEW_FOREGROUND_TAB);
474 tab_added_observer.Wait(); 479 tab_added_observer.Wait();
475 tab_loaded_observer.Wait(); 480 tab_loaded_observer.Wait();
476 481
477 // Check that the tab was correctly restored. 482 // Check that the tab was correctly restored.
478 EXPECT_EQ(2, browser->tab_strip_model()->count()); 483 EXPECT_EQ(2, browser->tab_strip_model()->count());
479 EXPECT_EQ(url1_, 484 EXPECT_EQ(url1_,
480 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 485 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
481 } 486 }
482 487
483 // Tests that a duplicate history entry is not created when we restore a page 488 // Tests that a duplicate history entry is not created when we restore a page
484 // to an existing SiteInstance. (Bug 1230446) 489 // to an existing SiteInstance. (Bug 1230446)
485 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) { 490 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) {
486 ASSERT_TRUE(embedded_test_server()->Start()); 491 ASSERT_TRUE(embedded_test_server()->Start());
487 492
488 GURL http_url1(embedded_test_server()->GetURL("/title1.html")); 493 GURL http_url1(embedded_test_server()->GetURL("/title1.html"));
489 GURL http_url2(embedded_test_server()->GetURL("/title2.html")); 494 GURL http_url2(embedded_test_server()->GetURL("/title2.html"));
490 int tab_count = browser()->tab_strip_model()->count(); 495 int tab_count = browser()->tab_strip_model()->count();
491 496
492 // Add a tab 497 // Add a tab
493 ui_test_utils::NavigateToURLWithDisposition( 498 ui_test_utils::NavigateToURLWithDisposition(
494 browser(), http_url1, NEW_FOREGROUND_TAB, 499 browser(), http_url1, WindowOpenDisposition::NEW_FOREGROUND_TAB,
495 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 500 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
496 EXPECT_EQ(++tab_count, browser()->tab_strip_model()->count()); 501 EXPECT_EQ(++tab_count, browser()->tab_strip_model()->count());
497 502
498 // Navigate to another same-site URL. 503 // Navigate to another same-site URL.
499 content::WebContents* tab = 504 content::WebContents* tab =
500 browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); 505 browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
501 content::WindowedNotificationObserver observer( 506 content::WindowedNotificationObserver observer(
502 content::NOTIFICATION_LOAD_STOP, 507 content::NOTIFICATION_LOAD_STOP,
503 content::NotificationService::AllSources()); 508 content::NotificationService::AllSources());
504 static_cast<content::WebContentsDelegate*>(browser())->OpenURLFromTab( 509 static_cast<content::WebContentsDelegate*>(browser())->OpenURLFromTab(
505 tab, 510 tab, content::OpenURLParams(http_url2, content::Referrer(),
506 content::OpenURLParams(http_url2, content::Referrer(), CURRENT_TAB, 511 WindowOpenDisposition::CURRENT_TAB,
507 ui::PAGE_TRANSITION_TYPED, false)); 512 ui::PAGE_TRANSITION_TYPED, false));
508 observer.Wait(); 513 observer.Wait();
509 514
510 // Close the tab. 515 // Close the tab.
511 CloseTab(1); 516 CloseTab(1);
512 517
513 // Create a new tab to the original site. Assuming process-per-site is 518 // Create a new tab to the original site. Assuming process-per-site is
514 // enabled, this will ensure that the SiteInstance used by the restored tab 519 // enabled, this will ensure that the SiteInstance used by the restored tab
515 // will already exist when the restore happens. 520 // will already exist when the restore happens.
516 ui_test_utils::NavigateToURLWithDisposition( 521 ui_test_utils::NavigateToURLWithDisposition(
517 browser(), http_url2, NEW_FOREGROUND_TAB, 522 browser(), http_url2, WindowOpenDisposition::NEW_FOREGROUND_TAB,
518 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 523 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
519 524
520 // Restore the closed tab. 525 // Restore the closed tab.
521 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1)); 526 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1));
522 527
523 // And make sure the URLs match. 528 // And make sure the URLs match.
524 EXPECT_EQ(http_url2, 529 EXPECT_EQ(http_url2,
525 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 530 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
526 GoBack(browser()); 531 GoBack(browser());
527 EXPECT_EQ(http_url1, 532 EXPECT_EQ(http_url1,
(...skipping 16 matching lines...) Expand all
544 MAYBE_RestoreCrossSiteWithExistingSiteInstance) { 549 MAYBE_RestoreCrossSiteWithExistingSiteInstance) {
545 ASSERT_TRUE(embedded_test_server()->Start()); 550 ASSERT_TRUE(embedded_test_server()->Start());
546 551
547 GURL http_url1(embedded_test_server()->GetURL("/title1.html")); 552 GURL http_url1(embedded_test_server()->GetURL("/title1.html"));
548 GURL http_url2(embedded_test_server()->GetURL("/title2.html")); 553 GURL http_url2(embedded_test_server()->GetURL("/title2.html"));
549 554
550 int tab_count = browser()->tab_strip_model()->count(); 555 int tab_count = browser()->tab_strip_model()->count();
551 556
552 // Add a tab 557 // Add a tab
553 ui_test_utils::NavigateToURLWithDisposition( 558 ui_test_utils::NavigateToURLWithDisposition(
554 browser(), http_url1, NEW_FOREGROUND_TAB, 559 browser(), http_url1, WindowOpenDisposition::NEW_FOREGROUND_TAB,
555 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 560 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
556 EXPECT_EQ(++tab_count, browser()->tab_strip_model()->count()); 561 EXPECT_EQ(++tab_count, browser()->tab_strip_model()->count());
557 562
558 // Navigate to more URLs, then a cross-site URL. 563 // Navigate to more URLs, then a cross-site URL.
559 ui_test_utils::NavigateToURL(browser(), http_url2); 564 ui_test_utils::NavigateToURL(browser(), http_url2);
560 ui_test_utils::NavigateToURL(browser(), http_url1); 565 ui_test_utils::NavigateToURL(browser(), http_url1);
561 ui_test_utils::NavigateToURL(browser(), url1_); 566 ui_test_utils::NavigateToURL(browser(), url1_);
562 567
563 // Close the tab. 568 // Close the tab.
564 CloseTab(1); 569 CloseTab(1);
565 570
566 // Create a new tab to the original site. Assuming process-per-site is 571 // Create a new tab to the original site. Assuming process-per-site is
567 // enabled, this will ensure that the SiteInstance will already exist when 572 // enabled, this will ensure that the SiteInstance will already exist when
568 // the user clicks Back in the restored tab. 573 // the user clicks Back in the restored tab.
569 ui_test_utils::NavigateToURLWithDisposition( 574 ui_test_utils::NavigateToURLWithDisposition(
570 browser(), http_url2, NEW_FOREGROUND_TAB, 575 browser(), http_url2, WindowOpenDisposition::NEW_FOREGROUND_TAB,
571 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 576 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
572 577
573 // Restore the closed tab. 578 // Restore the closed tab.
574 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1)); 579 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1));
575 580
576 // And make sure the URLs match. 581 // And make sure the URLs match.
577 EXPECT_EQ(url1_, 582 EXPECT_EQ(url1_,
578 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 583 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
579 GoBack(browser()); 584 GoBack(browser());
580 EXPECT_EQ(http_url1, 585 EXPECT_EQ(http_url1,
581 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 586 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
582 587
583 // Navigating to a new URL should clear the forward list, because the max 588 // Navigating to a new URL should clear the forward list, because the max
584 // page ID of the renderer should have been updated when we restored the tab. 589 // page ID of the renderer should have been updated when we restored the tab.
585 ui_test_utils::NavigateToURL(browser(), http_url2); 590 ui_test_utils::NavigateToURL(browser(), http_url2);
586 EXPECT_FALSE(chrome::CanGoForward(browser())); 591 EXPECT_FALSE(chrome::CanGoForward(browser()));
587 EXPECT_EQ(http_url2, 592 EXPECT_EQ(http_url2,
588 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 593 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
589 } 594 }
590 595
591 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) { 596 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) {
592 // Create a new window. 597 // Create a new window.
593 size_t window_count = active_browser_list_->size(); 598 size_t window_count = active_browser_list_->size();
594 ui_test_utils::NavigateToURLWithDisposition( 599 ui_test_utils::NavigateToURLWithDisposition(
595 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, 600 browser(), GURL(chrome::kChromeUINewTabURL),
601 WindowOpenDisposition::NEW_WINDOW,
596 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 602 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
597 EXPECT_EQ(++window_count, active_browser_list_->size()); 603 EXPECT_EQ(++window_count, active_browser_list_->size());
598 604
599 // Create two more tabs, one with url1, the other url2. 605 // Create two more tabs, one with url1, the other url2.
600 int initial_tab_count = browser()->tab_strip_model()->count(); 606 int initial_tab_count = browser()->tab_strip_model()->count();
601 ui_test_utils::NavigateToURLWithDisposition( 607 ui_test_utils::NavigateToURLWithDisposition(
602 browser(), url1_, NEW_FOREGROUND_TAB, 608 browser(), url1_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
603 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 609 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
604 ui_test_utils::NavigateToURLWithDisposition( 610 ui_test_utils::NavigateToURLWithDisposition(
605 browser(), url2_, NEW_FOREGROUND_TAB, 611 browser(), url2_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
606 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 612 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
607 613
608 // Close the window. 614 // Close the window.
609 content::WindowedNotificationObserver close_window_observer( 615 content::WindowedNotificationObserver close_window_observer(
610 chrome::NOTIFICATION_BROWSER_CLOSED, 616 chrome::NOTIFICATION_BROWSER_CLOSED,
611 content::NotificationService::AllSources()); 617 content::NotificationService::AllSources());
612 chrome::CloseWindow(browser()); 618 chrome::CloseWindow(browser());
613 close_window_observer.Wait(); 619 close_window_observer.Wait();
614 EXPECT_EQ(window_count - 1, active_browser_list_->size()); 620 EXPECT_EQ(window_count - 1, active_browser_list_->size());
615 621
(...skipping 21 matching lines...) Expand all
637 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count + 1); 643 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count + 1);
638 EnsureTabFinishedRestoring(restored_tab); 644 EnsureTabFinishedRestoring(restored_tab);
639 EXPECT_EQ(url2_, restored_tab->GetURL()); 645 EXPECT_EQ(url2_, restored_tab->GetURL());
640 } 646 }
641 647
642 // Restore tab with special URL chrome://credits/ and make sure the page loads 648 // Restore tab with special URL chrome://credits/ and make sure the page loads
643 // properly after restore. See http://crbug.com/31905. 649 // properly after restore. See http://crbug.com/31905.
644 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) { 650 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) {
645 // Navigate new tab to a special URL. 651 // Navigate new tab to a special URL.
646 ui_test_utils::NavigateToURLWithDisposition( 652 ui_test_utils::NavigateToURLWithDisposition(
647 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB, 653 browser(), GURL(chrome::kChromeUICreditsURL),
654 WindowOpenDisposition::NEW_FOREGROUND_TAB,
648 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 655 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
649 656
650 // Close the tab. 657 // Close the tab.
651 CloseTab(1); 658 CloseTab(1);
652 659
653 // Restore the closed tab. 660 // Restore the closed tab.
654 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); 661 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
655 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1); 662 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
656 EnsureTabFinishedRestoring(tab); 663 EnsureTabFinishedRestoring(tab);
657 664
658 // See if content is as expected. 665 // See if content is as expected.
659 EXPECT_GT( 666 EXPECT_GT(
660 ui_test_utils::FindInPage(tab, base::ASCIIToUTF16("webkit"), true, false, 667 ui_test_utils::FindInPage(tab, base::ASCIIToUTF16("webkit"), true, false,
661 NULL, NULL), 668 NULL, NULL),
662 0); 669 0);
663 } 670 }
664 671
665 // Restore tab with special URL in its navigation history, go back to that 672 // Restore tab with special URL in its navigation history, go back to that
666 // entry and see that it loads properly. See http://crbug.com/31905 673 // entry and see that it loads properly. See http://crbug.com/31905
667 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURLOnBack) { 674 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURLOnBack) {
668 ASSERT_TRUE(embedded_test_server()->Start()); 675 ASSERT_TRUE(embedded_test_server()->Start());
669 676
670 const GURL http_url(embedded_test_server()->GetURL("/title1.html")); 677 const GURL http_url(embedded_test_server()->GetURL("/title1.html"));
671 678
672 // Navigate new tab to a special URL. 679 // Navigate new tab to a special URL.
673 ui_test_utils::NavigateToURLWithDisposition( 680 ui_test_utils::NavigateToURLWithDisposition(
674 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB, 681 browser(), GURL(chrome::kChromeUICreditsURL),
682 WindowOpenDisposition::NEW_FOREGROUND_TAB,
675 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 683 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
676 684
677 // Then navigate to a normal URL. 685 // Then navigate to a normal URL.
678 ui_test_utils::NavigateToURL(browser(), http_url); 686 ui_test_utils::NavigateToURL(browser(), http_url);
679 687
680 // Close the tab. 688 // Close the tab.
681 CloseTab(1); 689 CloseTab(1);
682 690
683 // Restore the closed tab. 691 // Restore the closed tab.
684 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); 692 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
(...skipping 16 matching lines...) Expand all
701 while (browser()->tab_strip_model()->count()) 709 while (browser()->tab_strip_model()->count())
702 CloseTab(0); 710 CloseTab(0);
703 } 711 }
704 712
705 // Verifies restoring a tab works on startup. 713 // Verifies restoring a tab works on startup.
706 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) { 714 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) {
707 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); 715 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
708 EXPECT_EQ(url1_, 716 EXPECT_EQ(url1_,
709 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); 717 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL());
710 } 718 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore_browsertest.cc ('k') | chrome/browser/signin/chrome_signin_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698