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/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/browser_commands.h" | 7 #include "chrome/browser/ui/browser_commands.h" |
8 #include "chrome/browser/ui/browser_tabstrip.h" | 8 #include "chrome/browser/ui/browser_tabstrip.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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // accelerator targets until they are displayed. | 107 // accelerator targets until they are displayed. |
108 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) { | 108 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) { |
109 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 109 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
110 ASSERT_TRUE(web_contents != NULL); | 110 ASSERT_TRUE(web_contents != NULL); |
111 ConstrainedWindowTabHelper* constrained_window_helper = | 111 ConstrainedWindowTabHelper* constrained_window_helper = |
112 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 112 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
113 ASSERT_TRUE(constrained_window_helper != NULL); | 113 ASSERT_TRUE(constrained_window_helper != NULL); |
114 | 114 |
115 // Create a constrained dialog. It will attach itself to tab_contents. | 115 // Create a constrained dialog. It will attach itself to tab_contents. |
116 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); | 116 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); |
117 ConstrainedWindowViews* window1 = new ConstrainedWindowViews( | 117 ConstrainedWindowViews* window1 = |
118 web_contents, test_dialog1.get(), false, | 118 new ConstrainedWindowViews(web_contents, test_dialog1.get(), false); |
119 ConstrainedWindowViews::DEFAULT_INSETS); | |
120 | 119 |
121 views::FocusManager* focus_manager = window1->GetFocusManager(); | 120 views::FocusManager* focus_manager = window1->GetFocusManager(); |
122 ASSERT_TRUE(focus_manager); | 121 ASSERT_TRUE(focus_manager); |
123 | 122 |
124 // test_dialog1's text field should be focused. | 123 // test_dialog1's text field should be focused. |
125 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 124 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
126 focus_manager->GetFocusedView()); | 125 focus_manager->GetFocusedView()); |
127 | 126 |
128 // Now create a second constrained dialog. This will also be attached to | 127 // Now create a second constrained dialog. This will also be attached to |
129 // tab_contents, but will remain hidden since the test_dialog1 is still | 128 // tab_contents, but will remain hidden since the test_dialog1 is still |
130 // showing. | 129 // showing. |
131 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); | 130 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); |
132 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( | 131 ConstrainedWindowViews* window2 = |
133 web_contents, test_dialog2.get(), false, | 132 new ConstrainedWindowViews(web_contents, test_dialog2.get(), false); |
134 ConstrainedWindowViews::DEFAULT_INSETS); | |
135 // Should be the same focus_manager. | 133 // Should be the same focus_manager. |
136 ASSERT_EQ(focus_manager, window2->GetFocusManager()); | 134 ASSERT_EQ(focus_manager, window2->GetFocusManager()); |
137 | 135 |
138 // test_dialog1's text field should still be the view that has focus. | 136 // test_dialog1's text field should still be the view that has focus. |
139 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 137 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
140 focus_manager->GetFocusedView()); | 138 focus_manager->GetFocusedView()); |
141 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); | 139 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); |
142 | 140 |
143 // Now send a VKEY_RETURN to the browser. This should result in closing | 141 // Now send a VKEY_RETURN to the browser. This should result in closing |
144 // test_dialog1. | 142 // test_dialog1. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // closed. | 179 // closed. |
182 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) { | 180 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) { |
183 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 181 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
184 ASSERT_TRUE(web_contents != NULL); | 182 ASSERT_TRUE(web_contents != NULL); |
185 ConstrainedWindowTabHelper* constrained_window_helper = | 183 ConstrainedWindowTabHelper* constrained_window_helper = |
186 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 184 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
187 ASSERT_TRUE(constrained_window_helper != NULL); | 185 ASSERT_TRUE(constrained_window_helper != NULL); |
188 | 186 |
189 // Create a constrained dialog. It will attach itself to tab_contents. | 187 // Create a constrained dialog. It will attach itself to tab_contents. |
190 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); | 188 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); |
191 ConstrainedWindowViews* window = new ConstrainedWindowViews( | 189 ConstrainedWindowViews* window = |
192 web_contents, test_dialog.get(), true, | 190 new ConstrainedWindowViews(web_contents, test_dialog.get(), true); |
193 ConstrainedWindowViews::DEFAULT_INSETS); | |
194 | 191 |
195 bool closed = | 192 bool closed = |
196 browser()->tab_strip_model()->CloseTabContentsAt( | 193 browser()->tab_strip_model()->CloseTabContentsAt( |
197 browser()->tab_strip_model()->active_index(), | 194 browser()->tab_strip_model()->active_index(), |
198 TabStripModel::CLOSE_NONE); | 195 TabStripModel::CLOSE_NONE); |
199 EXPECT_TRUE(closed); | 196 EXPECT_TRUE(closed); |
200 content::RunAllPendingInMessageLoop(); | 197 content::RunAllPendingInMessageLoop(); |
201 EXPECT_TRUE(test_dialog->done()); | 198 EXPECT_TRUE(test_dialog->done()); |
202 } | 199 } |
OLD | NEW |