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/platform_util.h" | 6 #include "chrome/browser/platform_util.h" |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/views/constrained_window_views.h" | 12 #include "chrome/browser/ui/views/constrained_window_views.h" |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
14 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 14 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/web_modal/web_contents_modal_dialog_host.h" | 18 #include "components/web_modal/web_contents_modal_dialog_host.h" |
19 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 19 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
20 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 20 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
21 #include "content/public/browser/native_web_keyboard_event.h" | 21 #include "content/public/browser/native_web_keyboard_event.h" |
22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
23 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/browser/web_contents_view.h" | |
26 #include "ipc/ipc_message.h" | 25 #include "ipc/ipc_message.h" |
27 #include "ui/base/accelerators/accelerator.h" | 26 #include "ui/base/accelerators/accelerator.h" |
28 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
29 #include "ui/views/focus/focus_manager.h" | 28 #include "ui/views/focus/focus_manager.h" |
30 #include "ui/views/layout/fill_layout.h" | 29 #include "ui/views/layout/fill_layout.h" |
31 #include "ui/views/test/test_widget_observer.h" | 30 #include "ui/views/test/test_widget_observer.h" |
32 #include "ui/views/window/dialog_delegate.h" | 31 #include "ui/views/window/dialog_delegate.h" |
33 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" | 32 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" |
34 | 33 |
35 #if defined(USE_AURA) && defined(USE_X11) | 34 #if defined(USE_AURA) && defined(USE_X11) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 WebContentsModalDialogManager::FromWebContents(web_contents); | 150 WebContentsModalDialogManager::FromWebContents(web_contents); |
152 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL); | 151 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL); |
153 WebContentsModalDialogManagerDelegate* modal_delegate = | 152 WebContentsModalDialogManagerDelegate* modal_delegate = |
154 web_contents_modal_dialog_manager->delegate(); | 153 web_contents_modal_dialog_manager->delegate(); |
155 ASSERT_TRUE(modal_delegate != NULL); | 154 ASSERT_TRUE(modal_delegate != NULL); |
156 | 155 |
157 // Create a constrained dialog. It will attach itself to web_contents. | 156 // Create a constrained dialog. It will attach itself to web_contents. |
158 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); | 157 scoped_ptr<TestConstrainedDialog> test_dialog1(new TestConstrainedDialog); |
159 views::Widget* window1 = views::Widget::CreateWindowAsFramelessChild( | 158 views::Widget* window1 = views::Widget::CreateWindowAsFramelessChild( |
160 test_dialog1.get(), | 159 test_dialog1.get(), |
161 web_contents->GetView()->GetNativeView(), | |
162 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 160 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
163 web_contents_modal_dialog_manager->ShowDialog(window1->GetNativeView()); | 161 web_contents_modal_dialog_manager->ShowDialog(window1->GetNativeView()); |
164 | 162 |
165 views::FocusManager* focus_manager = window1->GetFocusManager(); | 163 views::FocusManager* focus_manager = window1->GetFocusManager(); |
166 ASSERT_TRUE(focus_manager); | 164 ASSERT_TRUE(focus_manager); |
167 | 165 |
168 // test_dialog1's text field should be focused. | 166 // test_dialog1's text field should be focused. |
169 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 167 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
170 focus_manager->GetFocusedView()); | 168 focus_manager->GetFocusedView()); |
171 | 169 |
172 // Now create a second constrained dialog. This will also be attached to | 170 // Now create a second constrained dialog. This will also be attached to |
173 // web_contents, but will remain hidden since the test_dialog1 is still | 171 // web_contents, but will remain hidden since the test_dialog1 is still |
174 // showing. | 172 // showing. |
175 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); | 173 scoped_ptr<TestConstrainedDialog> test_dialog2(new TestConstrainedDialog); |
176 views::Widget* window2 = views::Widget::CreateWindowAsFramelessChild( | 174 views::Widget* window2 = views::Widget::CreateWindowAsFramelessChild( |
177 test_dialog2.get(), | 175 test_dialog2.get(), |
178 web_contents->GetView()->GetNativeView(), | |
179 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 176 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
180 web_contents_modal_dialog_manager->ShowDialog(window2->GetNativeView()); | 177 web_contents_modal_dialog_manager->ShowDialog(window2->GetNativeView()); |
181 // Should be the same focus_manager. | 178 // Should be the same focus_manager. |
182 ASSERT_EQ(focus_manager, window2->GetFocusManager()); | 179 ASSERT_EQ(focus_manager, window2->GetFocusManager()); |
183 | 180 |
184 // test_dialog1's text field should still be the view that has focus. | 181 // test_dialog1's text field should still be the view that has focus. |
185 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), | 182 EXPECT_EQ(test_dialog1->GetInitiallyFocusedView(), |
186 focus_manager->GetFocusedView()); | 183 focus_manager->GetFocusedView()); |
187 ASSERT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 184 ASSERT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
188 | 185 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 WebContentsModalDialogManager::FromWebContents(web_contents); | 239 WebContentsModalDialogManager::FromWebContents(web_contents); |
243 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL); | 240 ASSERT_TRUE(web_contents_modal_dialog_manager != NULL); |
244 WebContentsModalDialogManagerDelegate* modal_delegate = | 241 WebContentsModalDialogManagerDelegate* modal_delegate = |
245 web_contents_modal_dialog_manager->delegate(); | 242 web_contents_modal_dialog_manager->delegate(); |
246 ASSERT_TRUE(modal_delegate != NULL); | 243 ASSERT_TRUE(modal_delegate != NULL); |
247 | 244 |
248 // Create a constrained dialog. It will attach itself to web_contents. | 245 // Create a constrained dialog. It will attach itself to web_contents. |
249 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); | 246 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); |
250 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( | 247 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( |
251 test_dialog.get(), | 248 test_dialog.get(), |
252 web_contents->GetView()->GetNativeView(), | |
253 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 249 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
254 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); | 250 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); |
255 | 251 |
256 bool closed = | 252 bool closed = |
257 browser()->tab_strip_model()->CloseWebContentsAt( | 253 browser()->tab_strip_model()->CloseWebContentsAt( |
258 browser()->tab_strip_model()->active_index(), | 254 browser()->tab_strip_model()->active_index(), |
259 TabStripModel::CLOSE_NONE); | 255 TabStripModel::CLOSE_NONE); |
260 EXPECT_TRUE(closed); | 256 EXPECT_TRUE(closed); |
261 content::RunAllPendingInMessageLoop(); | 257 content::RunAllPendingInMessageLoop(); |
262 EXPECT_TRUE(test_dialog->done()); | 258 EXPECT_TRUE(test_dialog->done()); |
(...skipping 15 matching lines...) Expand all Loading... |
278 | 274 |
279 // Create a constrained dialog. It will attach itself to web_contents. | 275 // Create a constrained dialog. It will attach itself to web_contents. |
280 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); | 276 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); |
281 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 277 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
282 WebContentsModalDialogManager::FromWebContents(web_contents); | 278 WebContentsModalDialogManager::FromWebContents(web_contents); |
283 WebContentsModalDialogManagerDelegate* modal_delegate = | 279 WebContentsModalDialogManagerDelegate* modal_delegate = |
284 web_contents_modal_dialog_manager->delegate(); | 280 web_contents_modal_dialog_manager->delegate(); |
285 ASSERT_TRUE(modal_delegate != NULL); | 281 ASSERT_TRUE(modal_delegate != NULL); |
286 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( | 282 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( |
287 test_dialog.get(), | 283 test_dialog.get(), |
288 web_contents->GetView()->GetNativeView(), | |
289 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 284 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
290 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); | 285 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); |
291 EXPECT_TRUE(window->IsVisible()); | 286 EXPECT_TRUE(window->IsVisible()); |
292 | 287 |
293 // Open a new tab. The constrained window should hide itself. | 288 // Open a new tab. The constrained window should hide itself. |
294 browser()->tab_strip_model()->AppendWebContents( | 289 browser()->tab_strip_model()->AppendWebContents( |
295 content::WebContents::Create( | 290 content::WebContents::Create( |
296 content::WebContents::CreateParams(browser()->profile())), | 291 content::WebContents::CreateParams(browser()->profile())), |
297 true); | 292 true); |
298 EXPECT_FALSE(window->IsVisible()); | 293 EXPECT_FALSE(window->IsVisible()); |
(...skipping 30 matching lines...) Expand all Loading... |
329 | 324 |
330 // Create a constrained dialog. It will attach itself to web_contents. | 325 // Create a constrained dialog. It will attach itself to web_contents. |
331 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); | 326 scoped_ptr<TestConstrainedDialog> test_dialog(new TestConstrainedDialog); |
332 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 327 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
333 WebContentsModalDialogManager::FromWebContents(web_contents); | 328 WebContentsModalDialogManager::FromWebContents(web_contents); |
334 WebContentsModalDialogManagerDelegate* modal_delegate = | 329 WebContentsModalDialogManagerDelegate* modal_delegate = |
335 web_contents_modal_dialog_manager->delegate(); | 330 web_contents_modal_dialog_manager->delegate(); |
336 ASSERT_TRUE(modal_delegate != NULL); | 331 ASSERT_TRUE(modal_delegate != NULL); |
337 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( | 332 views::Widget* window = views::Widget::CreateWindowAsFramelessChild( |
338 test_dialog.get(), | 333 test_dialog.get(), |
339 web_contents->GetView()->GetNativeView(), | |
340 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 334 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
341 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); | 335 web_contents_modal_dialog_manager->ShowDialog(window->GetNativeView()); |
342 EXPECT_TRUE(window->IsVisible()); | 336 EXPECT_TRUE(window->IsVisible()); |
343 | 337 |
344 // Detach the web contents from the second browser's tab strip. | 338 // Detach the web contents from the second browser's tab strip. |
345 browser2->tab_strip_model()->DetachWebContentsAt( | 339 browser2->tab_strip_model()->DetachWebContentsAt( |
346 browser2->tab_strip_model()->GetIndexOfWebContents(web_contents)); | 340 browser2->tab_strip_model()->GetIndexOfWebContents(web_contents)); |
347 | 341 |
348 // Append the web contents to the first browser. | 342 // Append the web contents to the first browser. |
349 browser()->tab_strip_model()->AppendWebContents(web_contents, true); | 343 browser()->tab_strip_model()->AppendWebContents(web_contents, true); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Escape is not processed as accelerator before it's sent to web contents. | 463 // Escape is not processed as accelerator before it's sent to web contents. |
470 EXPECT_FALSE(observer.widget_closed()); | 464 EXPECT_FALSE(observer.widget_closed()); |
471 | 465 |
472 content::RunAllPendingInMessageLoop(); | 466 content::RunAllPendingInMessageLoop(); |
473 | 467 |
474 // Escape is processed as accelerator after it's sent to web contents. | 468 // Escape is processed as accelerator after it's sent to web contents. |
475 EXPECT_TRUE(observer.widget_closed()); | 469 EXPECT_TRUE(observer.widget_closed()); |
476 } | 470 } |
477 | 471 |
478 #endif // defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11)) | 472 #endif // defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11)) |
OLD | NEW |