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

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

Issue 2727663004: Use TabLoader in TabRestoreService. (Closed)
Patch Set: Fix review notes: comments, namings etc. Created 3 years, 9 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 24 matching lines...) Expand all
35 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/notification_types.h" 37 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/page_navigator.h" 38 #include "content/public/browser/page_navigator.h"
39 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
40 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
41 #include "content/public/test/browser_test_utils.h" 41 #include "content/public/test/browser_test_utils.h"
42 #include "net/test/embedded_test_server/embedded_test_server.h" 42 #include "net/test/embedded_test_server/embedded_test_server.h"
43 #include "url/gurl.h" 43 #include "url/gurl.h"
44 44
45 #if BUILDFLAG(ENABLE_SESSION_SERVICE)
46 #include "chrome/browser/sessions/tab_loader.h"
47 #endif // BUILDFLAG(ENABLE_SESSION_SERVICE)
48
45 // Class used to run a message loop waiting for the TabRestoreService to finish 49 // Class used to run a message loop waiting for the TabRestoreService to finish
46 // loading. Does nothing if the TabRestoreService was already loaded. 50 // loading. Does nothing if the TabRestoreService was already loaded.
47 class WaitForLoadObserver : public sessions::TabRestoreServiceObserver { 51 class WaitForLoadObserver : public sessions::TabRestoreServiceObserver {
48 public: 52 public:
49 explicit WaitForLoadObserver(Browser* browser) 53 explicit WaitForLoadObserver(Browser* browser)
50 : tab_restore_service_( 54 : tab_restore_service_(
51 TabRestoreServiceFactory::GetForProfile(browser->profile())), 55 TabRestoreServiceFactory::GetForProfile(browser->profile())),
52 do_wait_(!tab_restore_service_->IsLoaded()) { 56 do_wait_(!tab_restore_service_->IsLoaded()) {
53 if (do_wait_) 57 if (do_wait_)
54 tab_restore_service_->AddObserver(this); 58 tab_restore_service_->AddObserver(this);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 content::NOTIFICATION_LOAD_STOP, 635 content::NOTIFICATION_LOAD_STOP,
632 content::NotificationService::AllSources()); 636 content::NotificationService::AllSources());
633 chrome::RestoreTab(active_browser_list_->get(0)); 637 chrome::RestoreTab(active_browser_list_->get(0));
634 open_window_observer.Wait(); 638 open_window_observer.Wait();
635 EXPECT_EQ(window_count, active_browser_list_->size()); 639 EXPECT_EQ(window_count, active_browser_list_->size());
636 640
637 Browser* browser = GetBrowser(1); 641 Browser* browser = GetBrowser(1);
638 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count()); 642 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count());
639 load_stop_observer.Wait(); 643 load_stop_observer.Wait();
640 644
645 EXPECT_EQ(initial_tab_count + 1, browser->tab_strip_model()->active_index());
641 content::WebContents* restored_tab = 646 content::WebContents* restored_tab =
647 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count + 1);
648 EnsureTabFinishedRestoring(restored_tab);
649 EXPECT_EQ(url2_, restored_tab->GetURL());
650
651 restored_tab =
642 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count); 652 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count);
643 EnsureTabFinishedRestoring(restored_tab); 653 EnsureTabFinishedRestoring(restored_tab);
644 EXPECT_EQ(url1_, restored_tab->GetURL()); 654 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 } 655 }
651 656
652 // Restore tab with special URL chrome://credits/ and make sure the page loads 657 // Restore tab with special URL chrome://credits/ and make sure the page loads
653 // properly after restore. See http://crbug.com/31905. 658 // properly after restore. See http://crbug.com/31905.
654 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) { 659 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) {
655 // Navigate new tab to a special URL. 660 // Navigate new tab to a special URL.
656 ui_test_utils::NavigateToURLWithDisposition( 661 ui_test_utils::NavigateToURLWithDisposition(
657 browser(), GURL(chrome::kChromeUICreditsURL), 662 browser(), GURL(chrome::kChromeUICreditsURL),
658 WindowOpenDisposition::NEW_FOREGROUND_TAB, 663 WindowOpenDisposition::NEW_FOREGROUND_TAB,
659 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 664 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 observer.Wait(); 757 observer.Wait();
753 758
754 SessionRestoreTestHelper helper; 759 SessionRestoreTestHelper helper;
755 // Restore browser (this is what Cmd-Shift-T does on Mac). 760 // Restore browser (this is what Cmd-Shift-T does on Mac).
756 chrome::OpenWindowWithRestoredTabs(profile); 761 chrome::OpenWindowWithRestoredTabs(profile);
757 if (SessionRestore::IsRestoring(profile)) 762 if (SessionRestore::IsRestoring(profile))
758 helper.Wait(); 763 helper.Wait();
759 Browser* browser = GetBrowser(0); 764 Browser* browser = GetBrowser(0);
760 EXPECT_EQ(4, browser->tab_strip_model()->count()); 765 EXPECT_EQ(4, browser->tab_strip_model()->count());
761 } 766 }
767
768 // TabLoader (used here) is available only when browser is built
769 // with ENABLE_SESSION_SERVICE.
770 #if BUILDFLAG(ENABLE_SESSION_SERVICE)
771 IN_PROC_BROWSER_TEST_F(TabRestoreTest,
772 TabsFromRestoredWindowsAreLoadedGradually) {
773 ui_test_utils::NavigateToURLWithDisposition(
774 browser(), url2_, WindowOpenDisposition::NEW_WINDOW,
775 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
776 Browser* browser2 = GetBrowser(1);
777
778 // Add tabs and close browser.
779 const int tabs_count = 4;
780 AddSomeTabs(browser2, tabs_count - browser2->tab_strip_model()->count());
781 EXPECT_EQ(tabs_count, browser2->tab_strip_model()->count());
782 content::WindowedNotificationObserver observer(
783 chrome::NOTIFICATION_BROWSER_CLOSED,
784 content::NotificationService::AllSources());
785 chrome::CloseWindow(browser2);
786 observer.Wait();
787
788 // Limit the number of restored tabs that are loaded.
789 TabLoader::SetMaxLoadedTabCountForTest(2);
790
791 // Restore recently closed window.
792 content::WindowedNotificationObserver open_window_observer(
793 chrome::NOTIFICATION_BROWSER_OPENED,
794 content::NotificationService::AllSources());
795 chrome::OpenWindowWithRestoredTabs(browser()->profile());
796 open_window_observer.Wait();
797 browser2 = GetBrowser(1);
798
799 EXPECT_EQ(tabs_count, browser2->tab_strip_model()->count());
800 EXPECT_EQ(tabs_count - 1, browser2->tab_strip_model()->active_index());
801 // These two tabs should be loaded by TabLoader.
802 EnsureTabFinishedRestoring(
803 browser2->tab_strip_model()->GetWebContentsAt(tabs_count - 1));
804 EnsureTabFinishedRestoring(browser2->tab_strip_model()->GetWebContentsAt(0));
805
806 // The following isn't necessary but just to be sure there is no any async
807 // task that could have an impact on the expectations below.
808 content::RunAllPendingInMessageLoop();
809
810 // These tabs shouldn't want to be loaded.
811 for (int tab_idx = 1; tab_idx < tabs_count - 1; ++tab_idx) {
812 auto* contents = browser2->tab_strip_model()->GetWebContentsAt(tab_idx);
813 EXPECT_FALSE(contents->IsLoading());
814 EXPECT_TRUE(contents->GetController().NeedsReload());
815 }
816 }
817 #endif // BUILDFLAG(ENABLE_SESSION_SERVICE)
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_loader.cc ('k') | chrome/browser/ui/android/tab_model/android_live_tab_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698