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 "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.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/constrained_window_tab_helper.h" | 9 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 browser()->tab_strip_model()->GetActiveWebContents(); | 111 browser()->tab_strip_model()->GetActiveWebContents(); |
112 ASSERT_TRUE(web_contents != NULL); | 112 ASSERT_TRUE(web_contents != NULL); |
113 ConstrainedWindowTabHelper* constrained_window_helper = | 113 ConstrainedWindowTabHelper* constrained_window_helper = |
114 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 114 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
115 ASSERT_TRUE(constrained_window_helper != NULL); | 115 ASSERT_TRUE(constrained_window_helper != NULL); |
116 | 116 |
117 // Create a constrained dialog. It will attach itself to tab_contents. | 117 // Create a constrained dialog. It will attach itself to tab_contents. |
118 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); | 118 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); |
119 ConstrainedWindowViews* window1 = new ConstrainedWindowViews( | 119 ConstrainedWindowViews* window1 = new ConstrainedWindowViews( |
120 web_contents, test_dialog1.get(), false, | 120 web_contents, test_dialog1.get(), false, |
121 ConstrainedWindowViews::DEFAULT_INSETS); | 121 ConstrainedWindowViews::FRAME_LAYOUT_FULL); |
122 | 122 |
123 views::FocusManager* focus_manager = window1->GetFocusManager(); | 123 views::FocusManager* focus_manager = window1->GetFocusManager(); |
124 ASSERT_TRUE(focus_manager); | 124 ASSERT_TRUE(focus_manager); |
125 | 125 |
126 // test_dialog1's text field should be focused. | 126 // test_dialog1's text field should be focused. |
127 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 127 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
128 focus_manager->GetFocusedView()); | 128 focus_manager->GetFocusedView()); |
129 | 129 |
130 // Now create a second constrained dialog. This will also be attached to | 130 // Now create a second constrained dialog. This will also be attached to |
131 // tab_contents, but will remain hidden since the test_dialog1 is still | 131 // tab_contents, but will remain hidden since the test_dialog1 is still |
132 // showing. | 132 // showing. |
133 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); | 133 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); |
134 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( | 134 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( |
135 web_contents, test_dialog2.get(), false, | 135 web_contents, test_dialog2.get(), false, |
136 ConstrainedWindowViews::DEFAULT_INSETS); | 136 ConstrainedWindowViews::FRAME_LAYOUT_FULL); |
137 // Should be the same focus_manager. | 137 // Should be the same focus_manager. |
138 ASSERT_EQ(focus_manager, window2->GetFocusManager()); | 138 ASSERT_EQ(focus_manager, window2->GetFocusManager()); |
139 | 139 |
140 // test_dialog1's text field should still be the view that has focus. | 140 // test_dialog1's text field should still be the view that has focus. |
141 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 141 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
142 focus_manager->GetFocusedView()); | 142 focus_manager->GetFocusedView()); |
143 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); | 143 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); |
144 | 144 |
145 // Now send a VKEY_RETURN to the browser. This should result in closing | 145 // Now send a VKEY_RETURN to the browser. This should result in closing |
146 // test_dialog1. | 146 // test_dialog1. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 browser()->tab_strip_model()->GetActiveWebContents(); | 187 browser()->tab_strip_model()->GetActiveWebContents(); |
188 ASSERT_TRUE(web_contents != NULL); | 188 ASSERT_TRUE(web_contents != NULL); |
189 ConstrainedWindowTabHelper* constrained_window_helper = | 189 ConstrainedWindowTabHelper* constrained_window_helper = |
190 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 190 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
191 ASSERT_TRUE(constrained_window_helper != NULL); | 191 ASSERT_TRUE(constrained_window_helper != NULL); |
192 | 192 |
193 // Create a constrained dialog. It will attach itself to tab_contents. | 193 // Create a constrained dialog. It will attach itself to tab_contents. |
194 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); | 194 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); |
195 new ConstrainedWindowViews( | 195 new ConstrainedWindowViews( |
196 web_contents, test_dialog.get(), true, | 196 web_contents, test_dialog.get(), true, |
197 ConstrainedWindowViews::DEFAULT_INSETS); | 197 ConstrainedWindowViews::FRAME_LAYOUT_FULL); |
198 | 198 |
199 bool closed = | 199 bool closed = |
200 browser()->tab_strip_model()->CloseTabContentsAt( | 200 browser()->tab_strip_model()->CloseTabContentsAt( |
201 browser()->tab_strip_model()->active_index(), | 201 browser()->tab_strip_model()->active_index(), |
202 TabStripModel::CLOSE_NONE); | 202 TabStripModel::CLOSE_NONE); |
203 EXPECT_TRUE(closed); | 203 EXPECT_TRUE(closed); |
204 content::RunAllPendingInMessageLoop(); | 204 content::RunAllPendingInMessageLoop(); |
205 EXPECT_TRUE(test_dialog->done()); | 205 EXPECT_TRUE(test_dialog->done()); |
206 } | 206 } |
207 | 207 |
208 // Tests that the constrained window is hidden when an other tab is selected and | 208 // Tests that the constrained window is hidden when an other tab is selected and |
209 // shown when its tab is selected again. | 209 // shown when its tab is selected again. |
210 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabSwitchTest) { | 210 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabSwitchTest) { |
211 content::WebContents* web_contents = | 211 content::WebContents* web_contents = |
212 browser()->tab_strip_model()->GetActiveWebContents(); | 212 browser()->tab_strip_model()->GetActiveWebContents(); |
213 ASSERT_TRUE(web_contents != NULL); | 213 ASSERT_TRUE(web_contents != NULL); |
214 | 214 |
215 // Create a constrained dialog. It will attach itself to tab_contents. | 215 // Create a constrained dialog. It will attach itself to tab_contents. |
216 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); | 216 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); |
217 ConstrainedWindowViews* window = new ConstrainedWindowViews( | 217 ConstrainedWindowViews* window = new ConstrainedWindowViews( |
218 web_contents, test_dialog.get(), true, | 218 web_contents, test_dialog.get(), true, |
219 ConstrainedWindowViews::DEFAULT_INSETS); | 219 ConstrainedWindowViews::FRAME_LAYOUT_FULL); |
220 EXPECT_TRUE(window->IsVisible()); | 220 EXPECT_TRUE(window->IsVisible()); |
221 | 221 |
222 // Open a new tab. The constrained window should hide itself. | 222 // Open a new tab. The constrained window should hide itself. |
223 browser()->tab_strip_model()->AppendWebContents( | 223 browser()->tab_strip_model()->AppendWebContents( |
224 content::WebContents::Create( | 224 content::WebContents::Create( |
225 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL), | 225 browser()->profile(), NULL, MSG_ROUTING_NONE, NULL), |
226 true); | 226 true); |
227 EXPECT_FALSE(window->IsVisible()); | 227 EXPECT_FALSE(window->IsVisible()); |
228 | 228 |
229 // Close the new tab. The constrained window should show itself again. | 229 // Close the new tab. The constrained window should show itself again. |
230 bool closed = | 230 bool closed = |
231 browser()->tab_strip_model()->CloseTabContentsAt( | 231 browser()->tab_strip_model()->CloseTabContentsAt( |
232 browser()->tab_strip_model()->active_index(), | 232 browser()->tab_strip_model()->active_index(), |
233 TabStripModel::CLOSE_NONE); | 233 TabStripModel::CLOSE_NONE); |
234 EXPECT_TRUE(closed); | 234 EXPECT_TRUE(closed); |
235 EXPECT_TRUE(window->IsVisible()); | 235 EXPECT_TRUE(window->IsVisible()); |
236 | 236 |
237 // Close the original tab. | 237 // Close the original tab. |
238 browser()->tab_strip_model()->CloseTabContentsAt( | 238 browser()->tab_strip_model()->CloseTabContentsAt( |
239 browser()->tab_strip_model()->active_index(), | 239 browser()->tab_strip_model()->active_index(), |
240 TabStripModel::CLOSE_NONE); | 240 TabStripModel::CLOSE_NONE); |
241 content::RunAllPendingInMessageLoop(); | 241 content::RunAllPendingInMessageLoop(); |
242 EXPECT_TRUE(test_dialog->done()); | 242 EXPECT_TRUE(test_dialog->done()); |
243 } | 243 } |
OLD | NEW |