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

Side by Side Diff: chrome/browser/ui/webui/chromeos/keyboard_overlay_ui_browsertest.cc

Issue 2814003002: Add test to check all current accelerators having keyboard overlay. (Closed)
Patch Set: Fix for the comments in patch 3. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(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:
xiyuan 2017/04/12 22:34:23 nit: ctor and dtor e.g. TestWebUIMessageHandler(
Lei Zhang 2017/04/12 22:40:10 Yes, add them. I'm not 100% certain, but I believe
wutao 2017/04/12 22:53:30 Done.
wutao 2017/04/12 22:53:30 Acknowledged.
20 void HandleDidPaint(const base::ListValue*) {}
21
22 void RegisterMessages() override {
xiyuan 2017/04/12 22:34:23 nit: add a comment for interface impl // content
wutao 2017/04/12 22:53:30 Done.
23 web_ui()->RegisterMessageCallback(
24 "didPaint", base::Bind(&TestWebUIMessageHandler::HandleDidPaint,
25 base::Unretained(this)));
26 }
27 };
xiyuan 2017/04/12 22:34:23 nit: Add a private section. Move HandleDidPaint th
wutao 2017/04/12 22:53:30 Done.
28
29 } // namespace
30
31 using KeyboradOverlayUIBrowserTest = InProcessBrowserTest;
Lei Zhang 2017/04/12 22:40:10 Typo
wutao 2017/04/12 22:53:30 Thank you, fixed.
32
33 IN_PROC_BROWSER_TEST_F(KeyboradOverlayUIBrowserTest,
34 ShouldHaveKeyboardOverlay) {
35 ui_test_utils::NavigateToURL(browser(),
36 GURL(chrome::kChromeUIKeyboardOverlayURL));
37 content::WebContents* web_contents =
38 browser()->tab_strip_model()->GetActiveWebContents();
39 web_contents->GetWebUI()->AddMessageHandler(
40 base::MakeUnique<TestWebUIMessageHandler>());
41
42 bool is_display_ui_scaling_enabled;
43 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
44 web_contents,
45 "domAutomationController.send(isDisplayUIScalingEnabled());",
46 &is_display_ui_scaling_enabled));
47
48 for (size_t i = 0; i < ash::kAcceleratorDataLength; ++i) {
49 const ash::AcceleratorData entry = ash::kAcceleratorData[i];
Lei Zhang 2017/04/12 22:40:10 Use a const ref.
wutao 2017/04/12 22:53:30 Done.
50 // Skip some accelerators in this test:
51 // 1. If the accelerator has no modifier, i.e. ui::EF_NONE, or for "Caps
52 // Lock", such as ui::VKEY_MENU and ui::VKEY_LWIN, the logic to show it on
53 // the keyboard overlay is not by the mapping of
54 // keyboardOverlayData['shortcut'], so it can not be tested by this test.
55 // 2. If it has debug modifiers: ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN |
56 // ui::EF_SHIFT_DOWN
57 if (entry.keycode == ui::VKEY_MENU ||
58 entry.keycode == ui::VKEY_LWIN ||
59 entry.modifiers == ui::EF_NONE ||
60 entry.modifiers ==
61 (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN)) {
62 continue;
63 }
64
65 std::string shortcut;
66 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
67 web_contents,
68 "domAutomationController.send("
69 " (function(number) {"
70 " if (!!KEYCODE_TO_LABEL[number]) {"
71 " return KEYCODE_TO_LABEL[number];"
72 " } else {"
73 " return 'NONE';"
74 " }"
75 " })(" + std::to_string(static_cast<unsigned int>(entry.keycode)) + ")"
76 ");",
77 &shortcut));
78 if (shortcut == "NONE") {
79 shortcut = base::ToLowerASCII(
80 static_cast<char>(LocatedToNonLocatedKeyboardCode(entry.keycode)));
81 }
82
83 // The order of the "if" conditions should not be changed because the
84 // modifiers are expected to be alphabetical sorted in the generated
85 // shortcut.
86 if (entry.modifiers & ui::EF_ALT_DOWN)
87 shortcut.append("<>ALT");
88 if (entry.modifiers & ui::EF_CONTROL_DOWN)
89 shortcut.append("<>CTRL");
90 if (entry.modifiers & ui::EF_COMMAND_DOWN)
91 shortcut.append("<>SEARCH");
92 if (entry.modifiers & ui::EF_SHIFT_DOWN)
93 shortcut.append("<>SHIFT");
94
95 if (!is_display_ui_scaling_enabled) {
96 if (shortcut == "-<>CTRL<>SHIFT" || shortcut == "+<>CTRL<>SHIFT" ||
97 shortcut == "0<>CTRL<>SHIFT")
98 continue;
99 }
100
101 bool contains;
102 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
103 web_contents,
104 "domAutomationController.send("
105 " !!keyboardOverlayData['shortcut']['" + shortcut + "']"
106 ");",
107 &contains));
108 ASSERT_TRUE(contains) << "Please add the new accelerators to keyboard "
109 "overlay. Add one entry '" +
110 shortcut +
111 "' in the 'shortcut' section"
112 " at the bottom of the file of "
113 "'/chrome/browser/resources/chromeos/"
114 "keyboard_overlay_data.js'. Please keep it in "
115 "alphabetical order.";
116 }
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698