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

Unified Diff: chrome/browser/browser_keyevents_browsertest.cc

Issue 2874313002: Fix is_browser_shortcut; add a test.
Patch Set: SendKeyPressSync Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/browser_window_cocoa.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_keyevents_browsertest.cc
diff --git a/chrome/browser/browser_keyevents_browsertest.cc b/chrome/browser/browser_keyevents_browsertest.cc
index b89162d4f0cc7f528769256ce15bd07299f57af0..bdf3a3b37ee240ea90c43036df3765d0cc55b0e7 100644
--- a/chrome/browser/browser_keyevents_browsertest.cc
+++ b/chrome/browser/browser_keyevents_browsertest.cc
@@ -21,10 +21,13 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_codes.h"
// TODO(kbr): remove: http://crbug.com/222296
@@ -816,6 +819,79 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_PageUpDownKeys) {
EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L""));
}
+class TestInputEventObserver
+ : public content::RenderWidgetHost::InputEventObserver {
+ public:
+ explicit TestInputEventObserver(content::RenderWidgetHost* host)
+ : host_(host), is_browser_shortcut_(false) {
+ host_->AddInputEventObserver(this);
+ }
+
+ ~TestInputEventObserver() override { host_->RemoveInputEventObserver(this); }
+
+ bool is_browser_shortcut() { return is_browser_shortcut_; }
+
+ private:
+ void OnInputEvent(const blink::WebInputEvent& event) override {
+ LOG(ERROR) << "OnInputEvent";
+ // LOG(ERROR) << " > type " << event.GetType();
+ // const blink::WebKeyboardEvent& key_event =
+ // static_cast<const blink::WebKeyboardEvent&>(event);
+ // LOG(ERROR) << "key_event.is_browser_shortcut " <<
+ // key_event.is_browser_shortcut; LOG(ERROR) << "key_event.windows_key_code
+ // " << key_event.windows_key_code; LOG(ERROR) << "key_event.dom_code " <<
+ // key_event.dom_code; LOG(ERROR) << "key_event.dom_key " <<
+ // key_event.dom_key; LOG(ERROR) << "key_event.text[0] " <<
+ // key_event.text[0] << " "
+ // << (key_event.text[0] ? ((char)key_event.text[0]) : ' ');
+ // LOG(ERROR) << "is_modifier " <<
+ // ui::KeycodeConverter::IsDomKeyForModifier(key_event.dom_key);
+ if (event.GetType() != blink::WebInputEvent::kRawKeyDown)
+ return;
+ const blink::WebKeyboardEvent& key_event =
+ static_cast<const blink::WebKeyboardEvent&>(event);
+ if (ui::KeycodeConverter::IsDomKeyForModifier(key_event.dom_key))
+ return;
+ LOG(ERROR) << "^^^";
+ is_browser_shortcut_ = key_event.is_browser_shortcut;
+ };
+
+ content::RenderWidgetHost* host_;
+ bool is_browser_shortcut_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestInputEventObserver);
+};
+
+// Tests to make sure that the |is_browser_shortcut| value is properly set on
+// input events.
+IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, InputBrowserShortcut) {
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ content::RenderWidgetHost* widget_host =
+ web_contents->GetRenderViewHost()->GetWidget();
+ TestInputEventObserver observer(widget_host);
+
+#if defined(OS_MACOSX)
+ bool command = true;
+ bool control = false;
+#else
+ bool command = false;
+ bool control = true;
+#endif
+
+ // Control/Command+G is not a browser shortcut and shouldn't have the "browser
+ // shortcut" bit set.
+ // ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_G, control,
+ // /*shift=*/false, /*alt=*/false, command));
+ // EXPECT_FALSE(observer.is_browser_shortcut());
+
+ // Control/Command+R is a browser shortcut and should have the "browser
+ // shortcut" bit set.
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_R, control,
+ /*shift=*/false, /*alt=*/false, command));
+ EXPECT_TRUE(observer.is_browser_shortcut());
+}
+
// AltKey is enabled only on Windows. See crbug.com/114537.
#if defined(OS_WIN)
// If this flakes, disable and log details in http://crbug.com/523255.
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/browser_window_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698