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

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

Issue 2868983003: Ensure History > Recent Tabs restore preserves window disposition. (Closed)
Patch Set: Remove NOTREACHED(). Created 3 years, 4 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/lifetime/keep_alive_types.h" 16 #include "chrome/browser/lifetime/keep_alive_types.h"
17 #include "chrome/browser/lifetime/scoped_keep_alive.h" 17 #include "chrome/browser/lifetime/scoped_keep_alive.h"
18 #include "chrome/browser/prefs/session_startup_pref.h" 18 #include "chrome/browser/prefs/session_startup_pref.h"
19 #include "chrome/browser/sessions/session_restore_test_helper.h" 19 #include "chrome/browser/sessions/session_restore_test_helper.h"
20 #include "chrome/browser/sessions/tab_restore_service_factory.h" 20 #include "chrome/browser/sessions/tab_restore_service_factory.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_commands.h" 22 #include "chrome/browser/ui/browser_commands.h"
23 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_live_tab_context.h" 24 #include "chrome/browser/ui/browser_live_tab_context.h"
25 #include "chrome/browser/ui/browser_tabstrip.h" 25 #include "chrome/browser/ui/browser_tabstrip.h"
26 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/find_bar/find_notification_details.h" 27 #include "chrome/browser/ui/find_bar/find_notification_details.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "chrome/test/base/in_process_browser_test.h" 31 #include "chrome/test/base/in_process_browser_test.h"
31 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
32 #include "components/sessions/core/tab_restore_service.h" 33 #include "components/sessions/core/tab_restore_service.h"
33 #include "components/sessions/core/tab_restore_service_observer.h" 34 #include "components/sessions/core/tab_restore_service_observer.h"
34 #include "content/public/browser/navigation_controller.h" 35 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 EXPECT_EQ(url2_, 416 EXPECT_EQ(url2_,
416 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 417 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
417 418
418 // Restore the next-to-last-closed tab into the same window. 419 // Restore the next-to-last-closed tab into the same window.
419 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); 420 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
420 EXPECT_EQ(2, browser->tab_strip_model()->count()); 421 EXPECT_EQ(2, browser->tab_strip_model()->count());
421 EXPECT_EQ(url1_, 422 EXPECT_EQ(url1_,
422 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 423 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
423 } 424 }
424 425
426 // Open a window with two tabs, close the window, then restore the window.
427 // Ensure that the restored window has the expected bounds.
428 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindowBounds) {
429 // Create a browser window with two tabs.
430 ui_test_utils::NavigateToURLWithDisposition(
431 browser(), url1_, WindowOpenDisposition::CURRENT_TAB,
432 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
433 ui_test_utils::NavigateToURLWithDisposition(
434 browser(), url2_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
435 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
436
437 // Create a second browser window.
438 ui_test_utils::NavigateToURLWithDisposition(
439 browser(), GURL(chrome::kChromeUINewTabURL),
440 WindowOpenDisposition::NEW_WINDOW,
441 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
442 EXPECT_EQ(2u, active_browser_list_->size());
443
444 // Deliberately change the bounds of the first window to something different.
445 gfx::Rect bounds = browser()->window()->GetBounds();
446 bounds.set_width(640);
447 bounds.set_height(480);
448 bounds.Offset(20, 20);
449 browser()->window()->SetBounds(bounds);
450 gfx::Rect bounds2 = browser()->window()->GetBounds();
451 EXPECT_EQ(bounds, bounds2);
452
453 // Close the first window.
454 content::WindowedNotificationObserver close_window_observer(
455 chrome::NOTIFICATION_BROWSER_CLOSED,
456 content::NotificationService::AllSources());
457 chrome::CloseWindow(browser());
458 close_window_observer.Wait();
459 EXPECT_EQ(1u, active_browser_list_->size());
460
461 // Check that the TabRestoreService has the contents of the closed window and
462 // the correct bounds.
463 Browser* browser = GetBrowser(0);
464 sessions::TabRestoreService* service =
465 TabRestoreServiceFactory::GetForProfile(browser->profile());
466 const sessions::TabRestoreService::Entries& entries = service->entries();
467 EXPECT_EQ(1u, entries.size());
468 sessions::TabRestoreService::Entry* entry = entries.front().get();
469 ASSERT_EQ(sessions::TabRestoreService::WINDOW, entry->type);
470 sessions::TabRestoreService::Window* entry_win =
471 static_cast<sessions::TabRestoreService::Window*>(entry);
472 EXPECT_EQ(bounds, entry_win->bounds);
473 auto& tabs = entry_win->tabs;
474 EXPECT_EQ(2u, tabs.size());
475
476 // Restore the window. Ensure that a second window is created, that is has 2
477 // tabs, and that it has the expected bounds.
478 service->RestoreMostRecentEntry(browser->live_tab_context());
479 EXPECT_EQ(2u, active_browser_list_->size());
480 browser = GetBrowser(1);
481 EXPECT_EQ(2, browser->tab_strip_model()->count());
482 // We expect the overridden bounds to the browser window to have been
483 // specified at window creation. The actual bounds of the window itself may
484 // change as the browser refuses to create windows that are offscreen, so will
485 // adjust bounds slightly in some cases.
486 EXPECT_EQ(bounds, browser->override_bounds());
487 }
488
425 // Open a window with two tabs, close both (closing the window), then restore 489 // Open a window with two tabs, close both (closing the window), then restore
426 // one by ID. Guards against regression of crbug.com/622752. 490 // one by ID. Guards against regression of crbug.com/622752.
427 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabFromClosedWindowByID) { 491 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabFromClosedWindowByID) {
428 ui_test_utils::NavigateToURLWithDisposition( 492 ui_test_utils::NavigateToURLWithDisposition(
429 browser(), url1_, WindowOpenDisposition::NEW_FOREGROUND_TAB, 493 browser(), url1_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
430 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 494 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
431 ui_test_utils::NavigateToURLWithDisposition( 495 ui_test_utils::NavigateToURLWithDisposition(
432 browser(), url2_, WindowOpenDisposition::NEW_FOREGROUND_TAB, 496 browser(), url2_, WindowOpenDisposition::NEW_FOREGROUND_TAB,
433 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 497 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
434 498
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 content::RunAllPendingInMessageLoop(); 871 content::RunAllPendingInMessageLoop();
808 872
809 // These tabs shouldn't want to be loaded. 873 // These tabs shouldn't want to be loaded.
810 for (int tab_idx = 1; tab_idx < tabs_count - 1; ++tab_idx) { 874 for (int tab_idx = 1; tab_idx < tabs_count - 1; ++tab_idx) {
811 auto* contents = browser2->tab_strip_model()->GetWebContentsAt(tab_idx); 875 auto* contents = browser2->tab_strip_model()->GetWebContentsAt(tab_idx);
812 EXPECT_FALSE(contents->IsLoading()); 876 EXPECT_FALSE(contents->IsLoading());
813 EXPECT_TRUE(contents->GetController().NeedsReload()); 877 EXPECT_TRUE(contents->GetController().NeedsReload());
814 } 878 }
815 } 879 }
816 #endif // BUILDFLAG(ENABLE_SESSION_SERVICE) 880 #endif // BUILDFLAG(ENABLE_SESSION_SERVICE)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698