OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/accelerators/accelerator_table.h" |
| 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 8 #include "chrome/common/url_constants.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_ui_message_handler.h" |
| 13 #include "content/public/test/browser_test_utils.h" |
| 14 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 class TestWebUIMessageHandler : public content::WebUIMessageHandler { |
| 19 public: |
| 20 TestWebUIMessageHandler() = default; |
| 21 ~TestWebUIMessageHandler() override = default; |
| 22 |
| 23 // content::WebUIMessageHandler: |
| 24 void RegisterMessages() override { |
| 25 web_ui()->RegisterMessageCallback( |
| 26 "didPaint", base::Bind(&TestWebUIMessageHandler::HandleDidPaint, |
| 27 base::Unretained(this))); |
| 28 } |
| 29 |
| 30 private: |
| 31 void HandleDidPaint(const base::ListValue*) {} |
| 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(TestWebUIMessageHandler); |
| 34 }; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 using KeyboardOverlayUIBrowserTest = InProcessBrowserTest; |
| 39 |
| 40 IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest, |
| 41 ShouldHaveKeyboardOverlay) { |
| 42 ui_test_utils::NavigateToURL(browser(), |
| 43 GURL(chrome::kChromeUIKeyboardOverlayURL)); |
| 44 content::WebContents* web_contents = |
| 45 browser()->tab_strip_model()->GetActiveWebContents(); |
| 46 web_contents->GetWebUI()->AddMessageHandler( |
| 47 base::MakeUnique<TestWebUIMessageHandler>()); |
| 48 |
| 49 bool is_display_ui_scaling_enabled; |
| 50 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 51 web_contents, |
| 52 "domAutomationController.send(isDisplayUIScalingEnabled());", |
| 53 &is_display_ui_scaling_enabled)); |
| 54 |
| 55 for (size_t i = 0; i < ash::kAcceleratorDataLength; ++i) { |
| 56 const ash::AcceleratorData& entry = ash::kAcceleratorData[i]; |
| 57 // Skip some accelerators in this test: |
| 58 // 1. If the accelerator has no modifier, i.e. ui::EF_NONE, or for "Caps |
| 59 // Lock", such as ui::VKEY_MENU and ui::VKEY_LWIN, the logic to show it on |
| 60 // the keyboard overlay is not by the mapping of |
| 61 // keyboardOverlayData['shortcut'], so it can not be tested by this test. |
| 62 // 2. If it has debug modifiers: ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | |
| 63 // ui::EF_SHIFT_DOWN |
| 64 if (entry.keycode == ui::VKEY_MENU || |
| 65 entry.keycode == ui::VKEY_LWIN || |
| 66 entry.modifiers == ui::EF_NONE || |
| 67 entry.modifiers == |
| 68 (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN)) { |
| 69 continue; |
| 70 } |
| 71 |
| 72 std::string shortcut; |
| 73 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 74 web_contents, |
| 75 "domAutomationController.send(" |
| 76 " (function(number) {" |
| 77 " if (!!KEYCODE_TO_LABEL[number]) {" |
| 78 " return KEYCODE_TO_LABEL[number];" |
| 79 " } else {" |
| 80 " return 'NONE';" |
| 81 " }" |
| 82 " })(" + std::to_string(static_cast<unsigned int>(entry.keycode)) + ")" |
| 83 ");", |
| 84 &shortcut)); |
| 85 if (shortcut == "NONE") { |
| 86 shortcut = base::ToLowerASCII( |
| 87 static_cast<char>(LocatedToNonLocatedKeyboardCode(entry.keycode))); |
| 88 } |
| 89 |
| 90 // The order of the "if" conditions should not be changed because the |
| 91 // modifiers are expected to be alphabetical sorted in the generated |
| 92 // shortcut. |
| 93 if (entry.modifiers & ui::EF_ALT_DOWN) |
| 94 shortcut.append("<>ALT"); |
| 95 if (entry.modifiers & ui::EF_CONTROL_DOWN) |
| 96 shortcut.append("<>CTRL"); |
| 97 if (entry.modifiers & ui::EF_COMMAND_DOWN) |
| 98 shortcut.append("<>SEARCH"); |
| 99 if (entry.modifiers & ui::EF_SHIFT_DOWN) |
| 100 shortcut.append("<>SHIFT"); |
| 101 |
| 102 if (!is_display_ui_scaling_enabled) { |
| 103 if (shortcut == "-<>CTRL<>SHIFT" || shortcut == "+<>CTRL<>SHIFT" || |
| 104 shortcut == "0<>CTRL<>SHIFT") |
| 105 continue; |
| 106 } |
| 107 |
| 108 bool contains; |
| 109 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 110 web_contents, |
| 111 "domAutomationController.send(" |
| 112 " !!keyboardOverlayData['shortcut']['" + shortcut + "']" |
| 113 ");", |
| 114 &contains)); |
| 115 ASSERT_TRUE(contains) << "Please add the new accelerators to keyboard " |
| 116 "overlay. Add one entry '" + |
| 117 shortcut + |
| 118 "' in the 'shortcut' section" |
| 119 " at the bottom of the file of " |
| 120 "'/chrome/browser/resources/chromeos/" |
| 121 "keyboard_overlay_data.js'. Please keep it in " |
| 122 "alphabetical order."; |
| 123 } |
| 124 } |
OLD | NEW |