Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chrome_notification_types.h" | 5 #include "chrome/browser/chrome_notification_types.h" |
| 6 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 6 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_live_tab_context.h" | 10 #include "chrome/browser/ui/browser_live_tab_context.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" | 12 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/interactive_test_utils.h" | 14 #include "chrome/test/base/interactive_test_utils.h" |
| 15 #include "components/sessions/core/tab_restore_service.h" | 15 #include "components/sessions/core/tab_restore_service.h" |
| 16 #include "content/public/browser/notification_service.h" | |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 19 | 20 |
| 20 typedef InProcessBrowserTest BrowserTabRestoreTest; | 21 typedef InProcessBrowserTest BrowserTabRestoreTest; |
| 21 | 22 |
| 22 void AwaitTabsReady(content::DOMMessageQueue* message_queue, int tabs) { | 23 void AwaitTabsReady(content::DOMMessageQueue* message_queue, int tabs) { |
| 23 for (int i = 0; i < tabs; ++i) { | 24 for (int i = 0; i < tabs; ++i) { |
| 24 std::string message; | 25 std::string message; |
| 25 EXPECT_TRUE(message_queue->WaitForMessage(&message)); | 26 EXPECT_TRUE(message_queue->WaitForMessage(&message)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 Browser* browser = active_browser_list->get(0); | 84 Browser* browser = active_browser_list->get(0); |
| 84 RecentTabsSubMenuModel menu(NULL, browser, NULL); | 85 RecentTabsSubMenuModel menu(NULL, browser, NULL); |
| 85 menu.ExecuteCommand( | 86 menu.ExecuteCommand( |
| 86 RecentTabsSubMenuModel::GetFirstRecentTabsCommandId(), 0); | 87 RecentTabsSubMenuModel::GetFirstRecentTabsCommandId(), 0); |
| 87 AwaitTabsReady(&queue, 2); | 88 AwaitTabsReady(&queue, 2); |
| 88 | 89 |
| 89 // There should be 3 restored tabs in the new browser. | 90 // There should be 3 restored tabs in the new browser. |
| 90 EXPECT_EQ(2u, active_browser_list->size()); | 91 EXPECT_EQ(2u, active_browser_list->size()); |
| 91 browser = active_browser_list->get(1); | 92 browser = active_browser_list->get(1); |
| 92 EXPECT_EQ(3, browser->tab_strip_model()->count()); | 93 EXPECT_EQ(3, browser->tab_strip_model()->count()); |
| 94 // For the two test tabs we've just received "READY" DOM message. | |
| 95 // But there won't be such message from the "about:blank" tab. | |
| 96 // And it is possible that TabLoader hasn't loaded it yet. | |
| 97 // Thus we should wait for "load stop" event before we will perform | |
| 98 // CheckVisbility on "about:blank". | |
| 99 { | |
| 100 const auto* about_blank = browser->tab_strip_model()->GetWebContentsAt(0); | |
|
sky
2017/03/02 19:12:05
about_blank_contents?
optional: mild preference fo
Michael K. (Yandex Team)
2017/03/03 08:26:37
Done.
| |
| 101 EXPECT_EQ("about:blank", about_blank->GetURL().spec()); | |
| 102 content::WindowedNotificationObserver load_stop_observer( | |
|
sky
2017/03/02 19:12:05
Move this into if?
Michael K. (Yandex Team)
2017/03/03 08:26:37
Done.
| |
| 103 content::NOTIFICATION_LOAD_STOP, | |
| 104 content::Source<content::NavigationController>( | |
| 105 &about_blank->GetController())); | |
| 106 if (about_blank->IsLoading() || about_blank->GetController().NeedsReload()) | |
| 107 load_stop_observer.Wait(); | |
| 108 } | |
| 93 | 109 |
| 94 // The middle tab only should have visible disposition. | 110 // The middle tab only should have visible disposition. |
| 95 CheckVisbility(browser->tab_strip_model(), 1); | 111 CheckVisbility(browser->tab_strip_model(), 1); |
| 96 } | 112 } |
| 97 | 113 |
| 98 IN_PROC_BROWSER_TEST_F(BrowserTabRestoreTest, DelegateRestoreTabDisposition) { | 114 IN_PROC_BROWSER_TEST_F(BrowserTabRestoreTest, DelegateRestoreTabDisposition) { |
| 99 // Create tabs. | 115 // Create tabs. |
| 100 CreateTestTabs(browser()); | 116 CreateTestTabs(browser()); |
| 101 EXPECT_EQ(3, browser()->tab_strip_model()->count()); | 117 EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
| 102 | 118 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 125 | 141 |
| 126 // Restore tabs using that delegated restore service. | 142 // Restore tabs using that delegated restore service. |
| 127 content::DOMMessageQueue queue; | 143 content::DOMMessageQueue queue; |
| 128 service->RestoreMostRecentEntry(context); | 144 service->RestoreMostRecentEntry(context); |
| 129 AwaitTabsReady(&queue, 2); | 145 AwaitTabsReady(&queue, 2); |
| 130 | 146 |
| 131 // There should be 3 restored tabs in the new browser. | 147 // There should be 3 restored tabs in the new browser. |
| 132 EXPECT_EQ(2u, active_browser_list->size()); | 148 EXPECT_EQ(2u, active_browser_list->size()); |
| 133 browser = active_browser_list->get(1); | 149 browser = active_browser_list->get(1); |
| 134 EXPECT_EQ(3, browser->tab_strip_model()->count()); | 150 EXPECT_EQ(3, browser->tab_strip_model()->count()); |
| 151 // The same as in RecentTabsMenuTabDisposition test case. | |
| 152 // See there for the explanation. | |
| 153 { | |
| 154 const auto* about_blank = browser->tab_strip_model()->GetWebContentsAt(0); | |
|
sky
2017/03/02 19:12:05
Similar comments as above.
Michael K. (Yandex Team)
2017/03/03 08:26:37
Done.
| |
| 155 EXPECT_EQ("about:blank", about_blank->GetURL().spec()); | |
| 156 content::WindowedNotificationObserver load_stop_observer( | |
| 157 content::NOTIFICATION_LOAD_STOP, | |
| 158 content::Source<content::NavigationController>( | |
| 159 &about_blank->GetController())); | |
| 160 if (about_blank->IsLoading() || about_blank->GetController().NeedsReload()) | |
| 161 load_stop_observer.Wait(); | |
| 162 } | |
| 135 | 163 |
| 136 // The middle tab only should have visible disposition. | 164 // The middle tab only should have visible disposition. |
| 137 CheckVisbility(browser->tab_strip_model(), 1); | 165 CheckVisbility(browser->tab_strip_model(), 1); |
| 138 } | 166 } |
| OLD | NEW |