| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/interactive_test_utils.h" | 20 #include "chrome/test/base/interactive_test_utils.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/render_widget_host.h" |
| 24 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 27 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 28 #include "ui/events/keycodes/keyboard_codes.h" | 31 #include "ui/events/keycodes/keyboard_codes.h" |
| 29 | 32 |
| 30 // TODO(kbr): remove: http://crbug.com/222296 | 33 // TODO(kbr): remove: http://crbug.com/222296 |
| 31 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
| 32 #import "base/mac/mac_util.h" | 35 #import "base/mac/mac_util.h" |
| 33 #endif | 36 #endif |
| 34 | 37 |
| 35 using content::NavigationController; | 38 using content::NavigationController; |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); | 812 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); |
| 810 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 813 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 811 | 814 |
| 812 int tab_index = browser()->tab_strip_model()->active_index(); | 815 int tab_index = browser()->tab_strip_model()->active_index(); |
| 813 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); | 816 ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); |
| 814 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageUp)); | 817 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageUp)); |
| 815 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageDown)); | 818 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestPageDown)); |
| 816 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"")); | 819 EXPECT_NO_FATAL_FAILURE(CheckTextBoxValue(tab_index, L"A", L"")); |
| 817 } | 820 } |
| 818 | 821 |
| 822 class TestInputEventObserver |
| 823 : public content::RenderWidgetHost::InputEventObserver { |
| 824 public: |
| 825 explicit TestInputEventObserver(content::RenderWidgetHost* host) |
| 826 : host_(host), is_browser_shortcut_(false) { |
| 827 host_->AddInputEventObserver(this); |
| 828 } |
| 829 |
| 830 ~TestInputEventObserver() override { host_->RemoveInputEventObserver(this); } |
| 831 |
| 832 bool is_browser_shortcut() { return is_browser_shortcut_; } |
| 833 |
| 834 private: |
| 835 void OnInputEvent(const blink::WebInputEvent& event) override { |
| 836 LOG(ERROR) << "OnInputEvent"; |
| 837 // LOG(ERROR) << " > type " << event.GetType(); |
| 838 // const blink::WebKeyboardEvent& key_event = |
| 839 // static_cast<const blink::WebKeyboardEvent&>(event); |
| 840 // LOG(ERROR) << "key_event.is_browser_shortcut " << |
| 841 // key_event.is_browser_shortcut; LOG(ERROR) << "key_event.windows_key_code |
| 842 // " << key_event.windows_key_code; LOG(ERROR) << "key_event.dom_code " << |
| 843 // key_event.dom_code; LOG(ERROR) << "key_event.dom_key " << |
| 844 // key_event.dom_key; LOG(ERROR) << "key_event.text[0] " << |
| 845 // key_event.text[0] << " " |
| 846 // << (key_event.text[0] ? ((char)key_event.text[0]) : ' '); |
| 847 // LOG(ERROR) << "is_modifier " << |
| 848 // ui::KeycodeConverter::IsDomKeyForModifier(key_event.dom_key); |
| 849 if (event.GetType() != blink::WebInputEvent::kRawKeyDown) |
| 850 return; |
| 851 const blink::WebKeyboardEvent& key_event = |
| 852 static_cast<const blink::WebKeyboardEvent&>(event); |
| 853 if (ui::KeycodeConverter::IsDomKeyForModifier(key_event.dom_key)) |
| 854 return; |
| 855 LOG(ERROR) << "^^^"; |
| 856 is_browser_shortcut_ = key_event.is_browser_shortcut; |
| 857 }; |
| 858 |
| 859 content::RenderWidgetHost* host_; |
| 860 bool is_browser_shortcut_; |
| 861 |
| 862 DISALLOW_COPY_AND_ASSIGN(TestInputEventObserver); |
| 863 }; |
| 864 |
| 865 // Tests to make sure that the |is_browser_shortcut| value is properly set on |
| 866 // input events. |
| 867 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, InputBrowserShortcut) { |
| 868 content::WebContents* web_contents = |
| 869 browser()->tab_strip_model()->GetActiveWebContents(); |
| 870 content::RenderWidgetHost* widget_host = |
| 871 web_contents->GetRenderViewHost()->GetWidget(); |
| 872 TestInputEventObserver observer(widget_host); |
| 873 |
| 874 #if defined(OS_MACOSX) |
| 875 bool command = true; |
| 876 bool control = false; |
| 877 #else |
| 878 bool command = false; |
| 879 bool control = true; |
| 880 #endif |
| 881 |
| 882 // Control/Command+G is not a browser shortcut and shouldn't have the "browser |
| 883 // shortcut" bit set. |
| 884 // ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_G, control, |
| 885 // /*shift=*/false, /*alt=*/false, command)); |
| 886 // EXPECT_FALSE(observer.is_browser_shortcut()); |
| 887 |
| 888 // Control/Command+R is a browser shortcut and should have the "browser |
| 889 // shortcut" bit set. |
| 890 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_R, control, |
| 891 /*shift=*/false, /*alt=*/false, command)); |
| 892 EXPECT_TRUE(observer.is_browser_shortcut()); |
| 893 } |
| 894 |
| 819 // AltKey is enabled only on Windows. See crbug.com/114537. | 895 // AltKey is enabled only on Windows. See crbug.com/114537. |
| 820 #if defined(OS_WIN) | 896 #if defined(OS_WIN) |
| 821 // If this flakes, disable and log details in http://crbug.com/523255. | 897 // If this flakes, disable and log details in http://crbug.com/523255. |
| 822 // TODO(sky): remove comment if proves stable and reenable other tests. | 898 // TODO(sky): remove comment if proves stable and reenable other tests. |
| 823 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { | 899 IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { |
| 824 static const KeyEventTestData kTestAltKey = { | 900 static const KeyEventTestData kTestAltKey = { |
| 825 ui::VKEY_MENU, false, false, false, false, | 901 ui::VKEY_MENU, false, false, false, false, |
| 826 false, false, false, false, 2, | 902 false, false, false, false, 2, |
| 827 { "D 18 0 false false true false", | 903 { "D 18 0 false false true false", |
| 828 "U 18 0 false false true false" } | 904 "U 18 0 false false true false" } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); | 941 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); |
| 866 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 942 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 867 | 943 |
| 868 // Ctrl+Alt should have no effect. | 944 // Ctrl+Alt should have no effect. |
| 869 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); | 945 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); |
| 870 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 946 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 871 } | 947 } |
| 872 #endif | 948 #endif |
| 873 | 949 |
| 874 } // namespace | 950 } // namespace |
| OLD | NEW |