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/constrained_window_tab_helper.h" | 9 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 11 #include "chrome/browser/ui/views/constrained_window_views.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
13 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
14 #include "ui/views/controls/textfield/textfield.h" | 15 #include "ui/views/controls/textfield/textfield.h" |
15 #include "ui/views/focus/focus_manager.h" | 16 #include "ui/views/focus/focus_manager.h" |
16 #include "ui/views/layout/fill_layout.h" | 17 #include "ui/views/layout/fill_layout.h" |
17 #include "ui/views/window/dialog_delegate.h" | 18 #include "ui/views/window/dialog_delegate.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 99 } |
99 }; | 100 }; |
100 | 101 |
101 // Tests the following: | 102 // Tests the following: |
102 // | 103 // |
103 // *) Initially focused view in a constrained dialog receives focus reliably. | 104 // *) Initially focused view in a constrained dialog receives focus reliably. |
104 // | 105 // |
105 // *) Constrained windows that are queued don't register themselves as | 106 // *) Constrained windows that are queued don't register themselves as |
106 // accelerator targets until they are displayed. | 107 // accelerator targets until they are displayed. |
107 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) { | 108 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) { |
108 TabContents* tab_contents = browser()->GetActiveTabContents(); | 109 TabContents* tab_contents = chrome::GetActiveTabContents(browser()); |
109 ASSERT_TRUE(tab_contents != NULL); | 110 ASSERT_TRUE(tab_contents != NULL); |
110 ConstrainedWindowTabHelper* constrained_window_helper = | 111 ConstrainedWindowTabHelper* constrained_window_helper = |
111 tab_contents->constrained_window_tab_helper(); | 112 tab_contents->constrained_window_tab_helper(); |
112 ASSERT_TRUE(constrained_window_helper != NULL); | 113 ASSERT_TRUE(constrained_window_helper != NULL); |
113 | 114 |
114 // Create a constrained dialog. It will attach itself to tab_contents. | 115 // Create a constrained dialog. It will attach itself to tab_contents. |
115 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); | 116 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); |
116 ConstrainedWindowViews* window1 = | 117 ConstrainedWindowViews* window1 = |
117 new ConstrainedWindowViews(tab_contents, test_dialog1.get()); | 118 new ConstrainedWindowViews(tab_contents, test_dialog1.get()); |
118 | 119 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 154 |
154 int tab_with_constrained_window = browser()->active_index(); | 155 int tab_with_constrained_window = browser()->active_index(); |
155 | 156 |
156 // Create a new tab. | 157 // Create a new tab. |
157 chrome::NewTab(browser()); | 158 chrome::NewTab(browser()); |
158 | 159 |
159 // The constrained dialog should no longer be selected. | 160 // The constrained dialog should no longer be selected. |
160 EXPECT_NE(test_dialog2->GetInitiallyFocusedView(), | 161 EXPECT_NE(test_dialog2->GetInitiallyFocusedView(), |
161 focus_manager->GetFocusedView()); | 162 focus_manager->GetFocusedView()); |
162 | 163 |
163 browser()->ActivateTabAt(tab_with_constrained_window, false); | 164 chrome::ActivateTabAt(browser(), tab_with_constrained_window, false); |
164 | 165 |
165 // Activating the previous tab should bring focus to the constrained window. | 166 // Activating the previous tab should bring focus to the constrained window. |
166 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), | 167 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), |
167 focus_manager->GetFocusedView()); | 168 focus_manager->GetFocusedView()); |
168 | 169 |
169 // Send another VKEY_RETURN, closing test_dialog2 | 170 // Send another VKEY_RETURN, closing test_dialog2 |
170 EXPECT_TRUE(focus_manager->ProcessAccelerator( | 171 EXPECT_TRUE(focus_manager->ProcessAccelerator( |
171 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); | 172 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); |
172 ui_test_utils::RunAllPendingInMessageLoop(); | 173 ui_test_utils::RunAllPendingInMessageLoop(); |
173 EXPECT_TRUE(test_dialog2->done()); | 174 EXPECT_TRUE(test_dialog2->done()); |
174 EXPECT_EQ(0u, constrained_window_helper->constrained_window_count()); | 175 EXPECT_EQ(0u, constrained_window_helper->constrained_window_count()); |
175 } | 176 } |
OLD | NEW |