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

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

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

Powered by Google App Engine
This is Rietveld 408576698