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