OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/constrained_window_tab_helper.h" | 7 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
9 #include "chrome/browser/ui/views/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
12 #include "views/accelerator.h" | 12 #include "ui/base/models/accelerator.h" |
13 #include "views/controls/textfield/textfield.h" | 13 #include "views/controls/textfield/textfield.h" |
14 #include "views/focus/focus_manager.h" | 14 #include "views/focus/focus_manager.h" |
15 #include "views/layout/fill_layout.h" | 15 #include "views/layout/fill_layout.h" |
16 #include "views/window/dialog_delegate.h" | 16 #include "views/window/dialog_delegate.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class TestConstrainedDialogContentsView | 20 class TestConstrainedDialogContentsView |
21 : public views::View, | 21 : public views::View, |
22 public base::SupportsWeakPtr<TestConstrainedDialogContentsView> { | 22 public base::SupportsWeakPtr<TestConstrainedDialogContentsView> { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 // Create a constrained dialog. It will attach itself to tab_contents. | 114 // Create a constrained dialog. It will attach itself to tab_contents. |
115 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); | 115 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); |
116 ConstrainedWindowViews* window1 = | 116 ConstrainedWindowViews* window1 = |
117 new ConstrainedWindowViews(tab_contents, test_dialog1.get()); | 117 new ConstrainedWindowViews(tab_contents, test_dialog1.get()); |
118 | 118 |
119 views::FocusManager* focus_manager = window1->GetFocusManager(); | 119 views::FocusManager* focus_manager = window1->GetFocusManager(); |
120 ASSERT_TRUE(focus_manager); | 120 ASSERT_TRUE(focus_manager); |
121 | 121 |
122 // old_target should be the OK button for test_dialog1. | 122 // old_target should be the OK button for test_dialog1. |
123 views::AcceleratorTarget* old_target = | 123 ui::AcceleratorTarget* old_target = |
124 focus_manager->GetCurrentTargetForAccelerator( | 124 focus_manager->GetCurrentTargetForAccelerator( |
125 views::Accelerator(ui::VKEY_RETURN, false, false, false)); | 125 ui::Accelerator(ui::VKEY_RETURN, false, false, false)); |
126 ASSERT_TRUE(old_target != NULL); | 126 ASSERT_TRUE(old_target != NULL); |
127 // test_dialog1's text field should be focused. | 127 // test_dialog1's text field should be focused. |
128 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 128 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
129 focus_manager->GetFocusedView()); | 129 focus_manager->GetFocusedView()); |
130 | 130 |
131 // Now create a second constrained dialog. This will also be attached to | 131 // Now create a second constrained dialog. This will also be attached to |
132 // tab_contents, but will remain hidden since the test_dialog1 is still | 132 // tab_contents, but will remain hidden since the test_dialog1 is still |
133 // showing. | 133 // showing. |
134 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); | 134 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); |
135 ConstrainedWindowViews* window2 = | 135 ConstrainedWindowViews* window2 = |
136 new ConstrainedWindowViews(tab_contents, test_dialog2.get()); | 136 new ConstrainedWindowViews(tab_contents, test_dialog2.get()); |
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 // new_target should be the same as old_target since test_dialog2 is still | 140 // new_target should be the same as old_target since test_dialog2 is still |
141 // hidden. | 141 // hidden. |
142 views::AcceleratorTarget* new_target = | 142 ui::AcceleratorTarget* new_target = |
143 focus_manager->GetCurrentTargetForAccelerator( | 143 focus_manager->GetCurrentTargetForAccelerator( |
144 views::Accelerator(ui::VKEY_RETURN, false, false, false)); | 144 ui::Accelerator(ui::VKEY_RETURN, false, false, false)); |
145 ASSERT_TRUE(new_target != NULL); | 145 ASSERT_TRUE(new_target != NULL); |
146 EXPECT_EQ(old_target, new_target); | 146 EXPECT_EQ(old_target, new_target); |
147 | 147 |
148 // test_dialog1's text field should still be the view that has focus. | 148 // test_dialog1's text field should still be the view that has focus. |
149 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 149 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
150 focus_manager->GetFocusedView()); | 150 focus_manager->GetFocusedView()); |
151 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); | 151 ASSERT_EQ(2u, constrained_window_helper->constrained_window_count()); |
152 | 152 |
153 // Now send a VKEY_RETURN to the browser. This should result in closing | 153 // Now send a VKEY_RETURN to the browser. This should result in closing |
154 // test_dialog1. | 154 // test_dialog1. |
155 EXPECT_TRUE(focus_manager->ProcessAccelerator( | 155 EXPECT_TRUE(focus_manager->ProcessAccelerator( |
156 views::Accelerator(ui::VKEY_RETURN, false, false, false))); | 156 ui::Accelerator(ui::VKEY_RETURN, false, false, false))); |
157 ui_test_utils::RunAllPendingInMessageLoop(); | 157 ui_test_utils::RunAllPendingInMessageLoop(); |
158 | 158 |
159 EXPECT_TRUE(test_dialog1->done()); | 159 EXPECT_TRUE(test_dialog1->done()); |
160 EXPECT_FALSE(test_dialog2->done()); | 160 EXPECT_FALSE(test_dialog2->done()); |
161 EXPECT_EQ(1u, constrained_window_helper->constrained_window_count()); | 161 EXPECT_EQ(1u, constrained_window_helper->constrained_window_count()); |
162 | 162 |
163 // test_dialog2 will be shown. Focus should be on test_dialog2's text field. | 163 // test_dialog2 will be shown. Focus should be on test_dialog2's text field. |
164 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), | 164 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), |
165 focus_manager->GetFocusedView()); | 165 focus_manager->GetFocusedView()); |
166 | 166 |
167 // Send another VKEY_RETURN, closing test_dialog2 | 167 // Send another VKEY_RETURN, closing test_dialog2 |
168 EXPECT_TRUE(focus_manager->ProcessAccelerator( | 168 EXPECT_TRUE(focus_manager->ProcessAccelerator( |
169 views::Accelerator(ui::VKEY_RETURN, false, false, false))); | 169 ui::Accelerator(ui::VKEY_RETURN, false, false, false))); |
170 ui_test_utils::RunAllPendingInMessageLoop(); | 170 ui_test_utils::RunAllPendingInMessageLoop(); |
171 EXPECT_TRUE(test_dialog2->done()); | 171 EXPECT_TRUE(test_dialog2->done()); |
172 EXPECT_EQ(0u, constrained_window_helper->constrained_window_count()); | 172 EXPECT_EQ(0u, constrained_window_helper->constrained_window_count()); |
173 } | 173 } |
OLD | NEW |