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

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

Issue 2114673002: Fix restore of a tab from a recently-closed browser window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 4 years, 5 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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/sessions/tab_restore_service_factory.h" 16 #include "chrome/browser/sessions/tab_restore_service_factory.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_commands.h" 18 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/browser_live_tab_context.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 21 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/find_bar/find_notification_details.h" 22 #include "chrome/browser/ui/find_bar/find_notification_details.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
26 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
27 #include "components/sessions/core/tab_restore_service.h" 28 #include "components/sessions/core/tab_restore_service.h"
28 #include "components/sessions/core/tab_restore_service_observer.h" 29 #include "components/sessions/core/tab_restore_service_observer.h"
29 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 EXPECT_EQ(url2_, 404 EXPECT_EQ(url2_,
404 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 405 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
405 406
406 // Restore the next-to-last-closed tab into the same window. 407 // Restore the next-to-last-closed tab into the same window.
407 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); 408 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
408 EXPECT_EQ(2, browser->tab_strip_model()->count()); 409 EXPECT_EQ(2, browser->tab_strip_model()->count());
409 EXPECT_EQ(url1_, 410 EXPECT_EQ(url1_,
410 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 411 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
411 } 412 }
412 413
414 // Open a window with two tabs, close both (closing the window), then restore
415 // one by ID. Guards against regression of crbug.com/622752.
416 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabFromClosedWindowByID) {
417 ui_test_utils::NavigateToURLWithDisposition(
418 browser(), url1_, NEW_FOREGROUND_TAB,
419 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
420 ui_test_utils::NavigateToURLWithDisposition(
421 browser(), url2_, NEW_FOREGROUND_TAB,
422 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
423
424 // Create a new browser.
425 ui_test_utils::NavigateToURLWithDisposition(
426 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW,
427 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
428 EXPECT_EQ(2u, active_browser_list_->size());
429
430 // Close the window.
431 content::WindowedNotificationObserver close_window_observer(
432 chrome::NOTIFICATION_BROWSER_CLOSED,
433 content::NotificationService::AllSources());
434 chrome::CloseWindow(browser());
435 close_window_observer.Wait();
436 EXPECT_EQ(1u, active_browser_list_->size());
437
438 // Check that the TabRestoreService has the contents of the closed window.
439 Browser* browser = GetBrowser(0);
440 sessions::TabRestoreService* service =
441 TabRestoreServiceFactory::GetForProfile(browser->profile());
442 const sessions::TabRestoreService::Entries& entries = service->entries();
443 EXPECT_EQ(1u, entries.size());
444 sessions::TabRestoreService::Entry* entry = entries.front();
445 EXPECT_EQ(entry->type, sessions::TabRestoreService::WINDOW);
sky 2016/07/19 17:42:40 nit: assertions have expected, actual. You want WI
blundell 2016/07/20 08:18:11 Done.
446 sessions::TabRestoreService::Window* entry_win =
447 static_cast<sessions::TabRestoreService::Window*>(entry);
448 std::vector<sessions::TabRestoreService::Tab>& tabs = entry_win->tabs;
449 EXPECT_EQ(3u, tabs.size());
450
451 // Find the Tab to restore.
452 sessions::TabRestoreService::Tab tab_to_restore;
453 bool found_tab_to_restore = false;
454 for (const auto& tab : tabs) {
455 if (tab.navigations[tab.current_navigation_index].virtual_url() == url1_) {
456 tab_to_restore = tab;
457 found_tab_to_restore = true;
458 break;
459 }
460 }
461 EXPECT_TRUE(found_tab_to_restore);
sky 2016/07/19 17:42:40 ASSERT, as if you didn't find it tab_to_restore is
blundell 2016/07/20 08:18:11 Done.
462
463 // Restore the tab into the current window.
464 EXPECT_EQ(1, browser->tab_strip_model()->count());
465 content::WindowedNotificationObserver tab_added_observer(
466 chrome::NOTIFICATION_TAB_PARENTED,
467 content::NotificationService::AllSources());
468 content::WindowedNotificationObserver tab_loaded_observer(
469 content::NOTIFICATION_LOAD_STOP,
470 content::NotificationService::AllSources());
471 service->RestoreEntryById(browser->live_tab_context(), tab_to_restore.id,
472 NEW_FOREGROUND_TAB);
473 tab_added_observer.Wait();
474 tab_loaded_observer.Wait();
475
476 // Check that the tab was correctly restored.
477 EXPECT_EQ(2, browser->tab_strip_model()->count());
478 EXPECT_EQ(url1_,
479 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
480 }
481
413 // Tests that a duplicate history entry is not created when we restore a page 482 // Tests that a duplicate history entry is not created when we restore a page
414 // to an existing SiteInstance. (Bug 1230446) 483 // to an existing SiteInstance. (Bug 1230446)
415 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) { 484 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) {
416 ASSERT_TRUE(embedded_test_server()->Start()); 485 ASSERT_TRUE(embedded_test_server()->Start());
417 486
418 GURL http_url1(embedded_test_server()->GetURL("/title1.html")); 487 GURL http_url1(embedded_test_server()->GetURL("/title1.html"));
419 GURL http_url2(embedded_test_server()->GetURL("/title2.html")); 488 GURL http_url2(embedded_test_server()->GetURL("/title2.html"));
420 int tab_count = browser()->tab_strip_model()->count(); 489 int tab_count = browser()->tab_strip_model()->count();
421 490
422 // Add a tab 491 // Add a tab
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 while (browser()->tab_strip_model()->count()) 700 while (browser()->tab_strip_model()->count())
632 CloseTab(0); 701 CloseTab(0);
633 } 702 }
634 703
635 // Verifies restoring a tab works on startup. 704 // Verifies restoring a tab works on startup.
636 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) { 705 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) {
637 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); 706 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
638 EXPECT_EQ(url1_, 707 EXPECT_EQ(url1_,
639 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); 708 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL());
640 } 709 }
OLDNEW
« no previous file with comments | « no previous file | components/components_tests.gyp » ('j') | components/sessions/core/tab_restore_service_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698