OLD | NEW |
---|---|
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_loader.h" | |
20 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 21 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
23 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
24 #include "chrome/browser/ui/browser_live_tab_context.h" | 25 #include "chrome/browser/ui/browser_live_tab_context.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.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" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 content::NOTIFICATION_LOAD_STOP, | 632 content::NOTIFICATION_LOAD_STOP, |
632 content::NotificationService::AllSources()); | 633 content::NotificationService::AllSources()); |
633 chrome::RestoreTab(active_browser_list_->get(0)); | 634 chrome::RestoreTab(active_browser_list_->get(0)); |
634 open_window_observer.Wait(); | 635 open_window_observer.Wait(); |
635 EXPECT_EQ(window_count, active_browser_list_->size()); | 636 EXPECT_EQ(window_count, active_browser_list_->size()); |
636 | 637 |
637 Browser* browser = GetBrowser(1); | 638 Browser* browser = GetBrowser(1); |
638 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count()); | 639 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count()); |
639 load_stop_observer.Wait(); | 640 load_stop_observer.Wait(); |
640 | 641 |
642 EXPECT_EQ(initial_tab_count + 1, browser->tab_strip_model()->active_index()); | |
641 content::WebContents* restored_tab = | 643 content::WebContents* restored_tab = |
644 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count + 1); | |
645 EnsureTabFinishedRestoring(restored_tab); | |
646 EXPECT_EQ(url2_, restored_tab->GetURL()); | |
647 | |
648 restored_tab = | |
642 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count); | 649 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count); |
643 EnsureTabFinishedRestoring(restored_tab); | 650 EnsureTabFinishedRestoring(restored_tab); |
644 EXPECT_EQ(url1_, restored_tab->GetURL()); | 651 EXPECT_EQ(url1_, restored_tab->GetURL()); |
645 | |
646 restored_tab = | |
647 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count + 1); | |
648 EnsureTabFinishedRestoring(restored_tab); | |
649 EXPECT_EQ(url2_, restored_tab->GetURL()); | |
650 } | 652 } |
651 | 653 |
652 // Restore tab with special URL chrome://credits/ and make sure the page loads | 654 // Restore tab with special URL chrome://credits/ and make sure the page loads |
653 // properly after restore. See http://crbug.com/31905. | 655 // properly after restore. See http://crbug.com/31905. |
654 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) { | 656 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) { |
655 // Navigate new tab to a special URL. | 657 // Navigate new tab to a special URL. |
656 ui_test_utils::NavigateToURLWithDisposition( | 658 ui_test_utils::NavigateToURLWithDisposition( |
657 browser(), GURL(chrome::kChromeUICreditsURL), | 659 browser(), GURL(chrome::kChromeUICreditsURL), |
658 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 660 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
659 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 661 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 observer.Wait(); | 754 observer.Wait(); |
753 | 755 |
754 SessionRestoreTestHelper helper; | 756 SessionRestoreTestHelper helper; |
755 // Restore browser (this is what Cmd-Shift-T does on Mac). | 757 // Restore browser (this is what Cmd-Shift-T does on Mac). |
756 chrome::OpenWindowWithRestoredTabs(profile); | 758 chrome::OpenWindowWithRestoredTabs(profile); |
757 if (SessionRestore::IsRestoring(profile)) | 759 if (SessionRestore::IsRestoring(profile)) |
758 helper.Wait(); | 760 helper.Wait(); |
759 Browser* browser = GetBrowser(0); | 761 Browser* browser = GetBrowser(0); |
760 EXPECT_EQ(4, browser->tab_strip_model()->count()); | 762 EXPECT_EQ(4, browser->tab_strip_model()->count()); |
761 } | 763 } |
764 | |
765 #if BUILDFLAG(ENABLE_SESSION_SERVICE) | |
sky
2017/03/02 19:12:05
Why does this require session service?
Michael K. (Yandex Team)
2017/03/03 08:26:37
Because of TabLoader: it depends on this buildflag
| |
766 IN_PROC_BROWSER_TEST_F(TabRestoreTest, | |
767 TabsFromRestoredWindowsAreLoadedGradually) { | |
768 ui_test_utils::NavigateToURLWithDisposition( | |
769 browser(), url2_, | |
770 WindowOpenDisposition::NEW_WINDOW, | |
771 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | |
772 Browser* browser2 = GetBrowser(1); | |
773 | |
774 // Add tabs and close browser. | |
775 AddSomeTabs(browser2, 3); | |
776 EXPECT_EQ(4, browser2->tab_strip_model()->count()); | |
sky
2017/03/02 19:12:05
Use a constant for this so to make it clear the re
Michael K. (Yandex Team)
2017/03/03 08:26:37
Done.
| |
777 content::WindowedNotificationObserver observer( | |
778 chrome::NOTIFICATION_BROWSER_CLOSED, | |
779 content::NotificationService::AllSources()); | |
780 chrome::CloseWindow(browser2); | |
781 observer.Wait(); | |
782 | |
783 // Limit the number of restored tabs that should be loaded. | |
sky
2017/03/02 19:12:05
'should be' -> 'are'
Michael K. (Yandex Team)
2017/03/03 08:26:37
Done.
| |
784 TabLoader::SetMaxLoadedTabCountForTest(2); | |
785 | |
786 // Restore recently closed window. | |
787 content::WindowedNotificationObserver open_window_observer( | |
788 chrome::NOTIFICATION_BROWSER_OPENED, | |
789 content::NotificationService::AllSources()); | |
790 chrome::OpenWindowWithRestoredTabs(browser()->profile()); | |
791 open_window_observer.Wait(); | |
792 browser2 = GetBrowser(1); | |
793 | |
794 EXPECT_EQ(4, browser2->tab_strip_model()->count()); | |
795 EXPECT_EQ(3, browser2->tab_strip_model()->active_index()); | |
796 // These two tabs should be loaded by TabLoader. | |
797 EnsureTabFinishedRestoring(browser2->tab_strip_model()->GetWebContentsAt(3)); | |
798 EnsureTabFinishedRestoring(browser2->tab_strip_model()->GetWebContentsAt(0)); | |
799 // It isn't necessary but just to be sure there is no any async task that | |
sky
2017/03/02 19:12:05
I don't understand this comment. Can you elaborate
Michael K. (Yandex Team)
2017/03/03 08:26:37
I made small fix here in the next patchset.
What
| |
800 // could have an impact on the expectations below. | |
801 content::RunAllPendingInMessageLoop(); | |
802 | |
803 // These tabs shouldn't want to be loaded. | |
804 for (int tab_idx = 1; tab_idx < 3; ++tab_idx) { | |
805 auto* contents = browser2->tab_strip_model()->GetWebContentsAt(tab_idx); | |
806 EXPECT_FALSE(contents->IsLoading()); | |
807 EXPECT_TRUE(contents->GetController().NeedsReload()); | |
808 } | |
809 } | |
810 #endif // ENABLE_SESSION_SERVICE | |
OLD | NEW |