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

Unified 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: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/bubble/bubble_delegate_unittest.cc » ('j') | ui/views/test/test_widget_observer.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/constrained_window_views_browsertest.cc
diff --git a/chrome/browser/ui/views/constrained_window_views_browsertest.cc b/chrome/browser/ui/views/constrained_window_views_browsertest.cc
index 470566cc430a3dbf2612473648a82fa0d29b8317..81acfa4c70c5a6885a1d6439be5d7fc3c4598b87 100644
--- a/chrome/browser/ui/views/constrained_window_views_browsertest.cc
+++ b/chrome/browser/ui/views/constrained_window_views_browsertest.cc
@@ -14,14 +14,22 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/native_web_keyboard_event.h"
+#include "content/public/browser/render_view_host.h"
#include "ipc/ipc_message.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/layout/fill_layout.h"
+#include "ui/views/test/test_widget_observer.h"
#include "ui/views/window/dialog_delegate.h"
#include "ui/web_dialogs/test/test_web_dialog_delegate.h"
+#if defined(USE_AURA) && defined(USE_X11)
+#include <X11/Xlib.h>
+#include "ui/base/x/x11_util.h"
+#endif
+
namespace {
class TestConstrainedDialogContentsView
@@ -250,36 +258,104 @@ IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest, TabSwitchTest) {
EXPECT_TRUE(test_dialog->done());
}
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11))
+
// Tests that backspace is not processed before it's sent to the web contents.
-// We do not run this test on Aura because key events are sent to the web
-// contents through a different code path that does not call
-// views::FocusManager::OnKeyEvent when ConstrainedWindow is focused.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest,
BackspaceSentToWebContent) {
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents != NULL);
- GURL url(chrome::kChromeUINewTabURL);
- ui_test_utils::NavigateToURL(browser(), url);
+ GURL new_tab_url(chrome::kChromeUINewTabURL);
+ ui_test_utils::NavigateToURL(browser(), new_tab_url);
+ GURL about_url(chrome::kChromeUIAboutURL);
+ ui_test_utils::NavigateToURL(browser(), about_url);
+
+ ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog(
+ browser()->profile(),
+ new ui::test::TestWebDialogDelegate(about_url),
+ NULL,
+ web_contents);
+
+#if defined(OS_WIN)
+ MSG native_key_event = { NULL, WM_KEYDOWN, ui::VKEY_BACK, 0 };
+#elif defined(USE_X11)
+ XEvent x_event;
+ ui::InitXKeyEventForTesting(
+ ui::ET_KEY_PRESSED, ui::VKEY_BACK, ui::EF_NONE, &x_event);
+ XEvent* native_key_event = &x_event;
+#endif
+
+#if defined(USE_AURA)
+ ui::KeyEvent key(native_key_event, false);
+ ui::KeyEvent* native_ui_key_event = &key;
+#else
+ MSG native_ui_key_event = native_key_event;
+#endif
+
+ content::RenderWidgetHost* render_widget_host =
+ cwdd->GetWebContents()->GetRenderViewHost();
+ render_widget_host->ForwardKeyboardEvent(
+ content::NativeWebKeyboardEvent(native_ui_key_event));
+
+ // Backspace is not processed as accelerator before it's sent to web contents.
+ EXPECT_EQ(about_url.spec(), web_contents->GetURL().spec());
+
+ content::RunAllPendingInMessageLoop();
+
+ // Backspace is processed as accelerator after it's sent to web contents.
+ EXPECT_EQ(new_tab_url.spec(), web_contents->GetURL().spec());
+}
+// Tests that escape closes the constrained window.
+IN_PROC_BROWSER_TEST_F(ConstrainedWindowViewTest,
+ EscapeCloseConstrainedWindow) {
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_TRUE(web_contents != NULL);
+
+ GURL new_tab_url(chrome::kChromeUINewTabURL);
+ ui_test_utils::NavigateToURL(browser(), new_tab_url);
ConstrainedWebDialogDelegate* cwdd = CreateConstrainedWebDialog(
browser()->profile(),
- new ui::test::TestWebDialogDelegate(url),
+ new ui::test::TestWebDialogDelegate(new_tab_url),
NULL,
web_contents);
ConstrainedWindowViews* cwv =
static_cast<ConstrainedWindowViews*>(cwdd->GetWindow());
+ views::test::TestWidgetObserver observer(cwv);
cwv->FocusConstrainedWindow();
- BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
- ui::KeyEvent key_event(ui::ET_KEY_PRESSED,
- ui::VKEY_BACK,
- ui::EF_NONE,
- false);
- bool not_consumed = browser_view->GetFocusManager()->OnKeyEvent(key_event);
- EXPECT_TRUE(not_consumed);
+#if defined(OS_WIN)
sky 2012/12/21 15:46:01 Can you refactor these ifdefs in some way to make
mazda 2013/01/07 22:41:14 Done.
+ MSG native_key_event = { NULL, WM_KEYDOWN, ui::VKEY_ESCAPE, 0 };
+#elif defined(USE_X11)
+ XEvent x_event;
+ ui::InitXKeyEventForTesting(
+ ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE, &x_event);
+ XEvent* native_key_event = &x_event;
+#endif
+
+#if defined(USE_AURA)
+ ui::KeyEvent key(native_key_event, false);
+ ui::KeyEvent* native_ui_key_event = &key;
+#else
+ MSG native_ui_key_event = native_key_event;
+#endif
+
+ content::RenderWidgetHost* render_widget_host =
+ cwdd->GetWebContents()->GetRenderViewHost();
+ render_widget_host->ForwardKeyboardEvent(
+ content::NativeWebKeyboardEvent(native_ui_key_event));
+
+ // Escape is not processed as accelerator before it's sent to web contents.
+ EXPECT_FALSE(observer.widget_closed());
+
+ content::RunAllPendingInMessageLoop();
+
+ // Escape is processed as accelerator after it's sent to web contents.
+ EXPECT_TRUE(observer.widget_closed());
}
-#endif // defined(OS_WIN) && !defined(USE_AURA)
+
+#endif // defined(OS_WIN) || (defined(USE_AURA) && defined(USE_X11))
« no previous file with comments | « no previous file | ui/views/bubble/bubble_delegate_unittest.cc » ('j') | ui/views/test/test_widget_observer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698