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

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

Issue 11639012: Add tests to verify accelerators properly work on constrained window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments 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
« no previous file with comments | « no previous file | ui/views/bubble/bubble_delegate_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #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" 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 "content/public/browser/native_web_keyboard_event.h"
18 #include "content/public/browser/render_view_host.h"
17 #include "ipc/ipc_message.h" 19 #include "ipc/ipc_message.h"
18 #include "ui/base/accelerators/accelerator.h" 20 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/views/controls/textfield/textfield.h" 21 #include "ui/views/controls/textfield/textfield.h"
20 #include "ui/views/focus/focus_manager.h" 22 #include "ui/views/focus/focus_manager.h"
21 #include "ui/views/layout/fill_layout.h" 23 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/test/test_widget_observer.h"
22 #include "ui/views/window/dialog_delegate.h" 25 #include "ui/views/window/dialog_delegate.h"
23 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" 26 #include "ui/web_dialogs/test/test_web_dialog_delegate.h"
24 27
28 #if defined(USE_AURA) && defined(USE_X11)
29 #include <X11/Xlib.h>
30 #include "ui/base/x/x11_util.h"
31 #endif
32
25 namespace { 33 namespace {
26 34
27 class TestConstrainedDialogContentsView 35 class TestConstrainedDialogContentsView
28 : public views::View, 36 : public views::View,
29 public base::SupportsWeakPtr<TestConstrainedDialogContentsView> { 37 public base::SupportsWeakPtr<TestConstrainedDialogContentsView> {
30 public: 38 public:
31 TestConstrainedDialogContentsView() 39 TestConstrainedDialogContentsView()
32 : text_field_(new views::Textfield) { 40 : text_field_(new views::Textfield) {
33 SetLayoutManager(new views::FillLayout); 41 SetLayoutManager(new views::FillLayout);
34 AddChildView(text_field_); 42 AddChildView(text_field_);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 EXPECT_TRUE(window->IsVisible()); 251 EXPECT_TRUE(window->IsVisible());
244 252
245 // Close the original tab. 253 // Close the original tab.
246 browser()->tab_strip_model()->CloseWebContentsAt( 254 browser()->tab_strip_model()->CloseWebContentsAt(
247 browser()->tab_strip_model()->active_index(), 255 browser()->tab_strip_model()->active_index(),
248 TabStripModel::CLOSE_NONE); 256 TabStripModel::CLOSE_NONE);
249 content::RunAllPendingInMessageLoop(); 257 content::RunAllPendingInMessageLoop();
250 EXPECT_TRUE(test_dialog->done()); 258 EXPECT_TRUE(test_dialog->done());
251 } 259 }
252 260
253 #if defined(OS_WIN) && !defined(USE_AURA) 261 #if defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11))
262
263 // Forwards the key event which has |key_code| to the renderer.
264 void ForwardKeyEvent(content::RenderViewHost* host, ui::KeyboardCode key_code) {
265 #if defined(OS_WIN)
266 MSG native_key_event = { NULL, WM_KEYDOWN, key_code, 0 };
267 #elif defined(USE_X11)
268 XEvent x_event;
269 ui::InitXKeyEventForTesting(
270 ui::ET_KEY_PRESSED, key_code, ui::EF_NONE, &x_event);
271 XEvent* native_key_event = &x_event;
272 #endif
273
274 #if defined(USE_AURA)
275 ui::KeyEvent key(native_key_event, false);
276 ui::KeyEvent* native_ui_key_event = &key;
277 #elif defined(OS_WIN)
278 MSG native_ui_key_event = native_key_event;
279 #endif
280
281 host->ForwardKeyboardEvent(
282 content::NativeWebKeyboardEvent(native_ui_key_event));
283 }
284
254 // Tests that backspace is not processed before it's sent to the web contents. 285 // 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
256 // contents through a different code path that does not call
257 // views::FocusManager::OnKeyEvent when WebContentsModalDialog is focused.
258 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, 286 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest,
259 BackspaceSentToWebContent) { 287 BackspaceSentToWebContent) {
260 content::WebContents* web_contents = 288 content::WebContents* web_contents =
261 browser()->tab_strip_model()->GetActiveWebContents(); 289 browser()->tab_strip_model()->GetActiveWebContents();
262 ASSERT_TRUE(web_contents != NULL); 290 ASSERT_TRUE(web_contents != NULL);
263 291
264 GURL url(chrome::kChromeUINewTabURL); 292 GURL new_tab_url(chrome::kChromeUINewTabURL);
265 ui_test_utils::NavigateToURL(browser(), url); 293 ui_test_utils::NavigateToURL(browser(), new_tab_url);
294 GURL about_url(chrome::kChromeUIAboutURL);
295 ui_test_utils::NavigateToURL(browser(), about_url);
266 296
267 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog( 297 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog(
268 browser()->profile(), 298 browser()->profile(),
269 new ui::test::TestWebDialogDelegate(url), 299 new ui::test::TestWebDialogDelegate(about_url),
300 NULL,
301 web_contents);
302
303 content::RenderViewHost* render_view_host =
304 cwdd->GetWebContents()->GetRenderViewHost();
305 ForwardKeyEvent(render_view_host, ui::VKEY_BACK);
306
307 // Backspace is not processed as accelerator before it's sent to web contents.
308 EXPECT_EQ(about_url.spec(), web_contents->GetURL().spec());
309
310 content::RunAllPendingInMessageLoop();
311
312 // Backspace is processed as accelerator after it's sent to web contents.
313 EXPECT_EQ(new_tab_url.spec(), web_contents->GetURL().spec());
314 }
315
316 // Tests that escape closes the constrained window.
317 IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest,
318 EscapeCloseConstrainedWindow) {
319 content::WebContents* web_contents =
320 browser()->tab_strip_model()->GetActiveWebContents();
321 ASSERT_TRUE(web_contents != NULL);
322
323 GURL new_tab_url(chrome::kChromeUINewTabURL);
324 ui_test_utils::NavigateToURL(browser(), new_tab_url);
325 ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog(
326 browser()->profile(),
327 new ui::test::TestWebDialogDelegate(new_tab_url),
270 NULL, 328 NULL,
271 web_contents); 329 web_contents);
272 330
273 ConstrainedWindowViews* cwv = 331 ConstrainedWindowViews* cwv =
274 static_cast<ConstrainedWindowViews*>(cwdd->GetWindow()); 332 static_cast<ConstrainedWindowViews*>(cwdd->GetWindow());
333 views::test::TestWidgetObserver observer(cwv);
275 cwv->FocusWebContentsModalDialog(); 334 cwv->FocusWebContentsModalDialog();
276 335
277 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 336 content::RenderViewHost* render_view_host =
278 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, 337 cwdd->GetWebContents()->GetRenderViewHost();
279 ui::VKEY_BACK, 338 ForwardKeyEvent(render_view_host, ui::VKEY_ESCAPE);
280 ui::EF_NONE, 339
281 false); 340 // Escape is not processed as accelerator before it's sent to web contents.
282 bool not_consumed = browser_view->GetFocusManager()->OnKeyEvent(key_event); 341 EXPECT_FALSE(observer.widget_closed());
283 EXPECT_TRUE(not_consumed); 342
343 content::RunAllPendingInMessageLoop();
344
345 // Escape is processed as accelerator after it's sent to web contents.
346 EXPECT_TRUE(observer.widget_closed());
284 } 347 }
285 #endif // defined(OS_WIN) && !defined(USE_AURA) 348
349 #endif // defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11))
OLDNEW
« no previous file with comments | « no previous file | ui/views/bubble/bubble_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698