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

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 1. 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
« no previous file with comments | « chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/ui/webui/web_ui_test_handler.h"
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*));
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::WrapUnique(new TestWebUIMessageHandler));
xiyuan 2017/04/12 19:59:45 nit: base::MakeUnique<TestWebUIMessageHandler>()
wutao 2017/04/12 21:43:41 Done. I must copy it from an old code.
42
43
44 bool is_display_ui_scaling_enabled;
45 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
46 web_contents,
47 "domAutomationController.send(isDisplayUIScalingEnabled());",
48 &is_display_ui_scaling_enabled));
49
50 for (size_t i = 0; i < ash::kAcceleratorDataLength; ++i) {
51 const ash::AcceleratorData entry = ash::kAcceleratorData[i];
52 // Skip some accelerators in this test:
53 // 1. If the accelerator has no modifier, i.e. ui::EF_NONE, or for "Caps
54 // Lock", such as ui::VKEY_MENU and ui::VKEY_LWIN, the logic to show it on
55 // the keyboard overlay is not by the mapping of
56 // keyboardOverlayData['shortcut'], so it can not be tested by this test.
57 // 2. If it has debug modifiers: ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN |
58 // ui::EF_SHIFT_DOWN
59 if (!(entry.keycode ^ ui::VKEY_MENU) || !(entry.keycode ^ ui::VKEY_LWIN) ||
60 !(entry.modifiers ^ ui::EF_NONE) ||
61 !(entry.modifiers ^ ui::EF_CONTROL_DOWN ^ ui::EF_ALT_DOWN ^
62 ui::EF_SHIFT_DOWN)) {
xiyuan 2017/04/12 19:59:45 Thanks for the comment. The "if" is still hard to
wutao 2017/04/12 21:43:41 Changed to "==". Since ash::kDebugModifiers is not
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 = static_cast<char>(DomCodeToUsLayoutCharacter(
xiyuan 2017/04/12 19:59:45 Can we just do static_cast<char>(LocatedToNonLo
wutao 2017/04/12 21:43:41 That is great! Saved many unnecessary calls. Just
81 UsLayoutKeyboardCodeToDomCode(
82 LocatedToNonLocatedKeyboardCode(entry.keycode)),
83 false));
84 }
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 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698