Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/ui/views/constrained_window_views_browsertest.cc

Issue 11633052: Rename platform-independent ConstrainedWindow types to WebContentsModalDialog types (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use gtk_widget_get_toplevel for GetNativeWindow Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/browser/ui/views/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h" 11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
13 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 13 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
18 #include "ui/base/accelerators/accelerator.h" 18 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/views/controls/textfield/textfield.h" 19 #include "ui/views/controls/textfield/textfield.h"
20 #include "ui/views/focus/focus_manager.h" 20 #include "ui/views/focus/focus_manager.h"
21 #include "ui/views/layout/fill_layout.h" 21 #include "ui/views/layout/fill_layout.h"
22 #include "ui/views/window/dialog_delegate.h" 22 #include "ui/views/window/dialog_delegate.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Tests the following: 115 // Tests the following:
116 // 116 //
117 // *) Initially focused view in a constrained dialog receives focus reliably. 117 // *) Initially focused view in a constrained dialog receives focus reliably.
118 // 118 //
119 // *) Constrained windows that are queued don't register themselves as 119 // *) Constrained windows that are queued don't register themselves as
120 // accelerator targets until they are displayed. 120 // accelerator targets until they are displayed.
121 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) { 121 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, FocusTest) {
122 content::WebContents* web_contents = 122 content::WebContents* web_contents =
123 browser()->tab_strip_model()->GetActiveWebContents(); 123 browser()->tab_strip_model()->GetActiveWebContents();
124 ASSERT_TRUE(web_contents != NULL); 124 ASSERT_TRUE(web_contents != NULL);
125 ConstrainedWindowTabHelper* constrained_window_helper = 125 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
126 ConstrainedWindowTabHelper::FromWebContents(web_contents); 126 WebContentsModalDialogManager::FromWebContents(web_contents);
127 ASSERT_TRUE(constrained_window_helper != NULL); 127 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL);
128 128
129 // Create a constrained dialog. It will attach itself to web_contents. 129 // Create a constrained dialog. It will attach itself to web_contents.
130 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); 130 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog);
131 ConstrainedWindowViews* window1 = new ConstrainedWindowViews( 131 ConstrainedWindowViews* window1 = new ConstrainedWindowViews(
132 web_contents, test_dialog1.get()); 132 web_contents, test_dialog1.get());
133 133
134 views::FocusManager* focus_manager = window1->GetFocusManager(); 134 views::FocusManager* focus_manager = window1->GetFocusManager();
135 ASSERT_TRUE(focus_manager); 135 ASSERT_TRUE(focus_manager);
136 136
137 // test_dialog1's text field should be focused. 137 // test_dialog1's text field should be focused.
138 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), 138 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(),
139 focus_manager->GetFocusedView()); 139 focus_manager->GetFocusedView());
140 140
141 // Now create a second constrained dialog. This will also be attached to 141 // Now create a second constrained dialog. This will also be attached to
142 // web_contents, but will remain hidden since the test_dialog1 is still 142 // web_contents, but will remain hidden since the test_dialog1 is still
143 // showing. 143 // showing.
144 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); 144 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog);
145 ConstrainedWindowViews* window2 = new ConstrainedWindowViews( 145 ConstrainedWindowViews* window2 = new ConstrainedWindowViews(
146 web_contents, test_dialog2.get()); 146 web_contents, test_dialog2.get());
147 // Should be the same focus_manager. 147 // Should be the same focus_manager.
148 ASSERT_EQ(focus_manager, window2->GetFocusManager()); 148 ASSERT_EQ(focus_manager, window2->GetFocusManager());
149 149
150 // test_dialog1's text field should still be the view that has focus. 150 // test_dialog1's text field should still be the view that has focus.
151 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), 151 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(),
152 focus_manager->GetFocusedView()); 152 focus_manager->GetFocusedView());
153 ASSERT_EQ(2u, constrained_window_helper->dialog_count()); 153 ASSERT_EQ(2u, web_contents_modal_dialog_manager->dialog_count());
154 154
155 // Now send a VKEY_RETURN to the browser. This should result in closing 155 // Now send a VKEY_RETURN to the browser. This should result in closing
156 // test_dialog1. 156 // test_dialog1.
157 EXPECT_TRUE(focus_manager->ProcessAccelerator( 157 EXPECT_TRUE(focus_manager->ProcessAccelerator(
158 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); 158 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)));
159 content::RunAllPendingInMessageLoop(); 159 content::RunAllPendingInMessageLoop();
160 160
161 EXPECT_TRUE(test_dialog1->done()); 161 EXPECT_TRUE(test_dialog1->done());
162 EXPECT_FALSE(test_dialog2->done()); 162 EXPECT_FALSE(test_dialog2->done());
163 EXPECT_EQ(1u, constrained_window_helper->dialog_count()); 163 EXPECT_EQ(1u, web_contents_modal_dialog_manager->dialog_count());
164 164
165 // test_dialog2 will be shown. Focus should be on test_dialog2's text field. 165 // test_dialog2 will be shown. Focus should be on test_dialog2's text field.
166 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), 166 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(),
167 focus_manager->GetFocusedView()); 167 focus_manager->GetFocusedView());
168 168
169 int tab_with_constrained_window = browser()->active_index(); 169 int tab_with_constrained_window = browser()->active_index();
170 170
171 // Create a new tab. 171 // Create a new tab.
172 chrome::NewTab(browser()); 172 chrome::NewTab(browser());
173 173
174 // The constrained dialog should no longer be selected. 174 // The constrained dialog should no longer be selected.
175 EXPECT_NE(test_dialog2->GetInitiallyFocusedView(), 175 EXPECT_NE(test_dialog2->GetInitiallyFocusedView(),
176 focus_manager->GetFocusedView()); 176 focus_manager->GetFocusedView());
177 177
178 browser()->tab_strip_model()->ActivateTabAt(tab_with_constrained_window, 178 browser()->tab_strip_model()->ActivateTabAt(tab_with_constrained_window,
179 false); 179 false);
180 180
181 // Activating the previous tab should bring focus to the constrained window. 181 // Activating the previous tab should bring focus to the constrained window.
182 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(), 182 EXPECT_EQ(test_dialog2->GetInitiallyFocusedView(),
183 focus_manager->GetFocusedView()); 183 focus_manager->GetFocusedView());
184 184
185 // Send another VKEY_RETURN, closing test_dialog2 185 // Send another VKEY_RETURN, closing test_dialog2
186 EXPECT_TRUE(focus_manager->ProcessAccelerator( 186 EXPECT_TRUE(focus_manager->ProcessAccelerator(
187 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE))); 187 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)));
188 content::RunAllPendingInMessageLoop(); 188 content::RunAllPendingInMessageLoop();
189 EXPECT_TRUE(test_dialog2->done()); 189 EXPECT_TRUE(test_dialog2->done());
190 EXPECT_EQ(0u, constrained_window_helper->dialog_count()); 190 EXPECT_EQ(0u, web_contents_modal_dialog_manager->dialog_count());
191 } 191 }
192 192
193 // Tests that the constrained window is closed properly when its tab is 193 // Tests that the constrained window is closed properly when its tab is
194 // closed. 194 // closed.
195 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) { 195 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabCloseTest) {
196 content::WebContents* web_contents = 196 content::WebContents* web_contents =
197 browser()->tab_strip_model()->GetActiveWebContents(); 197 browser()->tab_strip_model()->GetActiveWebContents();
198 ASSERT_TRUE(web_contents != NULL); 198 ASSERT_TRUE(web_contents != NULL);
199 ConstrainedWindowTabHelper* constrained_window_helper = 199 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
200 ConstrainedWindowTabHelper::FromWebContents(web_contents); 200 WebContentsModalDialogManager::FromWebContents(web_contents);
201 ASSERT_TRUE(constrained_window_helper != NULL); 201 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL);
202 202
203 // Create a constrained dialog. It will attach itself to web_contents. 203 // Create a constrained dialog. It will attach itself to web_contents.
204 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); 204 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog);
205 new ConstrainedWindowViews( 205 new ConstrainedWindowViews(
206 web_contents, test_dialog.get()); 206 web_contents, test_dialog.get());
207 207
208 bool closed = 208 bool closed =
209 browser()->tab_strip_model()->CloseWebContentsAt( 209 browser()->tab_strip_model()->CloseWebContentsAt(
210 browser()->tab_strip_model()->active_index(), 210 browser()->tab_strip_model()->active_index(),
211 TabStripModel::CLOSE_NONE); 211 TabStripModel::CLOSE_NONE);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 browser()->tab_strip_model()->active_index(), 247 browser()->tab_strip_model()->active_index(),
248 TabStripModel::CLOSE_NONE); 248 TabStripModel::CLOSE_NONE);
249 content::RunAllPendingInMessageLoop(); 249 content::RunAllPendingInMessageLoop();
250 EXPECT_TRUE(test_dialog->done()); 250 EXPECT_TRUE(test_dialog->done());
251 } 251 }
252 252
253 #if defined(OS_WIN) && !defined(USE_AURA) 253 #if defined(OS_WIN) && !defined(USE_AURA)
254 // Tests that backspace is not processed before it's sent to the web contents. 254 // Tests that backspace is not processed before it's sent to the web contents.
255 // We do not run this test on Aura because key events are sent to the web 255 // We do not run this test on Aura because key events are sent to the web
256 // contents through a different code path that does not call 256 // contents through a different code path that does not call
257 // views::FocusManager::OnKeyEvent when ConstrainedWindow is focused. 257 // views::FocusManager::OnKeyEvent when WebContentsModalDialog is focused.
258 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, 258 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest,
259 BackspaceSentToWebContent) { 259 BackspaceSentToWebContent) {
260 content::WebContents* web_contents = 260 content::WebContents* web_contents =
261 browser()->tab_strip_model()->GetActiveWebContents(); 261 browser()->tab_strip_model()->GetActiveWebContents();
262 ASSERT_TRUE(web_contents != NULL); 262 ASSERT_TRUE(web_contents != NULL);
263 263
264 GURL url(chrome::kChromeUINewTabURL); 264 GURL url(chrome::kChromeUINewTabURL);
265 ui_test_utils::NavigateToURL(browser(), url); 265 ui_test_utils::NavigateToURL(browser(), url);
266 266
267 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog( 267 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog(
268 browser()->profile(), 268 browser()->profile(),
269 new ui::test::TestWebDialogDelegate(url), 269 new ui::test::TestWebDialogDelegate(url),
270 NULL, 270 NULL,
271 web_contents); 271 web_contents);
272 272
273 ConstrainedWindowViews* cwv = 273 ConstrainedWindowViews* cwv =
274 static_cast<ConstrainedWindowViews*>(cwdd->GetWindow()); 274 static_cast<ConstrainedWindowViews*>(cwdd->GetWindow());
275 cwv->FocusWebContentsModalDialog(); 275 cwv->FocusWebContentsModalDialog();
276 276
277 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 277 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
278 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, 278 ui::KeyEvent key_event(ui::ET_KEY_PRESSED,
279 ui::VKEY_BACK, 279 ui::VKEY_BACK,
280 ui::EF_NONE, 280 ui::EF_NONE,
281 false); 281 false);
282 bool not_consumed = browser_view->GetFocusManager()->OnKeyEvent(key_event); 282 bool not_consumed = browser_view->GetFocusManager()->OnKeyEvent(key_event);
283 EXPECT_TRUE(not_consumed); 283 EXPECT_TRUE(not_consumed);
284 } 284 }
285 #endif // defined(OS_WIN) && !defined(USE_AURA) 285 #endif // defined(OS_WIN) && !defined(USE_AURA)
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/constrained_window_views.cc ('k') | chrome/browser/ui/views/ssl_client_certificate_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698