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