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 content::WebContents* about_blank_contents = |
| 101 browser->tab_strip_model()->GetWebContentsAt(0); |
| 102 EXPECT_EQ("about:blank", about_blank_contents->GetURL().spec()); |
| 103 if (about_blank_contents->IsLoading() || |
| 104 about_blank_contents->GetController().NeedsReload()) { |
| 105 content::WindowedNotificationObserver load_stop_observer( |
| 106 content::NOTIFICATION_LOAD_STOP, |
| 107 content::Source<content::NavigationController>( |
| 108 &about_blank_contents->GetController())); |
| 109 load_stop_observer.Wait(); |
| 110 } |
| 111 } |
93 | 112 |
94 // The middle tab only should have visible disposition. | 113 // The middle tab only should have visible disposition. |
95 CheckVisbility(browser->tab_strip_model(), 1); | 114 CheckVisbility(browser->tab_strip_model(), 1); |
96 } | 115 } |
97 | 116 |
98 IN_PROC_BROWSER_TEST_F(BrowserTabRestoreTest, DelegateRestoreTabDisposition) { | 117 IN_PROC_BROWSER_TEST_F(BrowserTabRestoreTest, DelegateRestoreTabDisposition) { |
99 // Create tabs. | 118 // Create tabs. |
100 CreateTestTabs(browser()); | 119 CreateTestTabs(browser()); |
101 EXPECT_EQ(3, browser()->tab_strip_model()->count()); | 120 EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
102 | 121 |
(...skipping 22 matching lines...) Expand all Loading... |
125 | 144 |
126 // Restore tabs using that delegated restore service. | 145 // Restore tabs using that delegated restore service. |
127 content::DOMMessageQueue queue; | 146 content::DOMMessageQueue queue; |
128 service->RestoreMostRecentEntry(context); | 147 service->RestoreMostRecentEntry(context); |
129 AwaitTabsReady(&queue, 2); | 148 AwaitTabsReady(&queue, 2); |
130 | 149 |
131 // There should be 3 restored tabs in the new browser. | 150 // There should be 3 restored tabs in the new browser. |
132 EXPECT_EQ(2u, active_browser_list->size()); | 151 EXPECT_EQ(2u, active_browser_list->size()); |
133 browser = active_browser_list->get(1); | 152 browser = active_browser_list->get(1); |
134 EXPECT_EQ(3, browser->tab_strip_model()->count()); | 153 EXPECT_EQ(3, browser->tab_strip_model()->count()); |
| 154 // The same as in RecentTabsMenuTabDisposition test case. |
| 155 // See there for the explanation. |
| 156 { |
| 157 const content::WebContents* about_blank_contents = |
| 158 browser->tab_strip_model()->GetWebContentsAt(0); |
| 159 EXPECT_EQ("about:blank", about_blank_contents->GetURL().spec()); |
| 160 if (about_blank_contents->IsLoading() || |
| 161 about_blank_contents->GetController().NeedsReload()) { |
| 162 content::WindowedNotificationObserver load_stop_observer( |
| 163 content::NOTIFICATION_LOAD_STOP, |
| 164 content::Source<content::NavigationController>( |
| 165 &about_blank_contents->GetController())); |
| 166 load_stop_observer.Wait(); |
| 167 } |
| 168 } |
135 | 169 |
136 // The middle tab only should have visible disposition. | 170 // The middle tab only should have visible disposition. |
137 CheckVisbility(browser->tab_strip_model(), 1); | 171 CheckVisbility(browser->tab_strip_model(), 1); |
138 } | 172 } |
OLD | NEW |