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

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

Issue 2815213003: Add test to check deprecated accelerator do not have keyboard overlay. (Closed)
Patch Set: 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 "ash/accelerators/accelerator_table.h" 5 #include "ash/accelerators/accelerator_table.h"
6 #include "chrome/browser/ui/browser.h" 6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" 7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/common/url_constants.h" 8 #include "chrome/common/url_constants.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
(...skipping 15 matching lines...) Expand all
26 "didPaint", base::Bind(&TestWebUIMessageHandler::HandleDidPaint, 26 "didPaint", base::Bind(&TestWebUIMessageHandler::HandleDidPaint,
27 base::Unretained(this))); 27 base::Unretained(this)));
28 } 28 }
29 29
30 private: 30 private:
31 void HandleDidPaint(const base::ListValue*) {} 31 void HandleDidPaint(const base::ListValue*) {}
32 32
33 DISALLOW_COPY_AND_ASSIGN(TestWebUIMessageHandler); 33 DISALLOW_COPY_AND_ASSIGN(TestWebUIMessageHandler);
34 }; 34 };
35 35
36 } // namespace 36 content::WebContents* StartKeyboardOverlayUI(Browser* browser) {
37 ui_test_utils::NavigateToURL(browser,
xiyuan 2017/04/13 06:56:21 2-space indent here and other function body lines.
wutao 2017/04/13 16:24:03 Done.
38 GURL(chrome::kChromeUIKeyboardOverlayURL));
39 content::WebContents* web_contents =
40 browser->tab_strip_model()->GetActiveWebContents();
41 web_contents->GetWebUI()->AddMessageHandler(
42 base::MakeUnique<TestWebUIMessageHandler>());
43 return web_contents;
44 }
37 45
38 using KeyboardOverlayUIBrowserTest = InProcessBrowserTest; 46 bool IsDisplayUIScalingEnabled(content::WebContents* web_contents) {
47 bool is_display_ui_scaling_enabled;
48 CHECK(content::ExecuteScriptAndExtractBool(
xiyuan 2017/04/13 06:56:21 CHECK() should be avoided. Can we use EXPECT_TRUE(
wutao 2017/04/13 16:24:03 Done.
49 web_contents,
50 "domAutomationController.send(isDisplayUIScalingEnabled());",
51 &is_display_ui_scaling_enabled));
52 return is_display_ui_scaling_enabled;
53 }
39 54
40 IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest, 55 bool ShouldSkip(const ash::AcceleratorData& accelerator) {
41 ShouldHaveKeyboardOverlay) { 56 // Skip some accelerators in the tests:
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 57 // 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 58 // 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 59 // the keyboard overlay is not by the mapping of
61 // keyboardOverlayData['shortcut'], so it can not be tested by this test. 60 // 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 | 61 // 2. If it has debug modifiers: ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN |
63 // ui::EF_SHIFT_DOWN 62 // ui::EF_SHIFT_DOWN
xiyuan 2017/04/13 06:56:21 Move the comments out of body and make it a commen
wutao 2017/04/13 16:24:03 Done.
64 if (entry.keycode == ui::VKEY_MENU || 63 if (accelerator.keycode == ui::VKEY_MENU ||
65 entry.keycode == ui::VKEY_LWIN || 64 accelerator.keycode == ui::VKEY_LWIN ||
66 entry.modifiers == ui::EF_NONE || 65 accelerator.modifiers == ui::EF_NONE ||
67 entry.modifiers == 66 accelerator.modifiers ==
68 (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN)) { 67 (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN)) {
69 continue; 68 return true;
70 } 69 }
70 return false;
xiyuan 2017/04/13 06:56:21 nit: Get rid of the "if" and put conditions in ret
wutao 2017/04/13 16:24:03 Done.
71 }
71 72
72 std::string shortcut; 73 std::string KeyboardCodeToLabel(const ash::AcceleratorData& accelerator,
73 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 74 content::WebContents* web_contents) {
75 std::string label;
76 CHECK(content::ExecuteScriptAndExtractString(
xiyuan 2017/04/13 06:56:21 EXPECT_TRUE ?
wutao 2017/04/13 16:24:03 Done.
74 web_contents, 77 web_contents,
75 "domAutomationController.send(" 78 "domAutomationController.send("
76 " (function(number) {" 79 " (function(number) {"
77 " if (!!KEYCODE_TO_LABEL[number]) {" 80 " if (!!KEYCODE_TO_LABEL[number]) {"
78 " return KEYCODE_TO_LABEL[number];" 81 " return KEYCODE_TO_LABEL[number];"
79 " } else {" 82 " } else {"
80 " return 'NONE';" 83 " return 'NONE';"
81 " }" 84 " }"
82 " })(" + std::to_string(static_cast<unsigned int>(entry.keycode)) + ")" 85 " })(" +
86 std::to_string(static_cast<unsigned int>(accelerator.keycode)) +
87 " )"
83 ");", 88 ");",
84 &shortcut)); 89 &label));
85 if (shortcut == "NONE") { 90 if (label == "NONE") {
86 shortcut = base::ToLowerASCII( 91 label = base::ToLowerASCII(static_cast<char>(
87 static_cast<char>(LocatedToNonLocatedKeyboardCode(entry.keycode))); 92 LocatedToNonLocatedKeyboardCode(accelerator.keycode)));
88 } 93 }
94 return label;
95 }
89 96
97 std::string GenerateShortcutKey(const ash::AcceleratorData& accelerator,
98 content::WebContents* web_contents) {
99 std::string shortcut = KeyboardCodeToLabel(accelerator, web_contents);
90 // The order of the "if" conditions should not be changed because the 100 // The order of the "if" conditions should not be changed because the
91 // modifiers are expected to be alphabetical sorted in the generated 101 // modifiers are expected to be alphabetical sorted in the generated
92 // shortcut. 102 // shortcut.
93 if (entry.modifiers & ui::EF_ALT_DOWN) 103 if (accelerator.modifiers & ui::EF_ALT_DOWN)
94 shortcut.append("<>ALT"); 104 shortcut.append("<>ALT");
95 if (entry.modifiers & ui::EF_CONTROL_DOWN) 105 if (accelerator.modifiers & ui::EF_CONTROL_DOWN)
96 shortcut.append("<>CTRL"); 106 shortcut.append("<>CTRL");
97 if (entry.modifiers & ui::EF_COMMAND_DOWN) 107 if (accelerator.modifiers & ui::EF_COMMAND_DOWN)
98 shortcut.append("<>SEARCH"); 108 shortcut.append("<>SEARCH");
99 if (entry.modifiers & ui::EF_SHIFT_DOWN) 109 if (accelerator.modifiers & ui::EF_SHIFT_DOWN)
100 shortcut.append("<>SHIFT"); 110 shortcut.append("<>SHIFT");
111 return shortcut;
112 }
101 113
114 bool ContainsShortcut(const std::string& shortcut,
115 content::WebContents* web_contents) {
116 bool contains;
117 CHECK(content::ExecuteScriptAndExtractBool(
xiyuan 2017/04/13 06:56:22 EXPECT_TRUE ?
wutao 2017/04/13 16:24:03 Done.
118 web_contents,
119 "domAutomationController.send("
120 " !!keyboardOverlayData['shortcut']['" + shortcut + "']"
121 ");",
122 &contains));
123 return contains;
124 }
125
126 } // namespace
127
128 using KeyboardOverlayUIBrowserTest = InProcessBrowserTest;
129
130 IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest,
131 AcceleratorsShouldHaveKeyboardOverlay) {
132 content::WebContents* web_contents = StartKeyboardOverlayUI(browser());
xiyuan 2017/04/13 06:56:22 nit: content::WebContents* const web_contents
wutao 2017/04/13 16:24:03 Done.
133 bool is_display_ui_scaling_enabled = IsDisplayUIScalingEnabled(web_contents);
xiyuan 2017/04/13 06:56:21 nit: const bool
wutao 2017/04/13 16:24:03 Done.
134 for (size_t i = 0; i < ash::kAcceleratorDataLength; ++i) {
135 const ash::AcceleratorData& entry = ash::kAcceleratorData[i];
136 if (ShouldSkip(entry))
137 continue;
138
139 std::string shortcut = GenerateShortcutKey(entry, web_contents);
xiyuan 2017/04/13 06:56:21 nit: const std::string
wutao 2017/04/13 16:24:03 Done.
102 if (!is_display_ui_scaling_enabled) { 140 if (!is_display_ui_scaling_enabled) {
103 if (shortcut == "-<>CTRL<>SHIFT" || shortcut == "+<>CTRL<>SHIFT" || 141 if (shortcut == "-<>CTRL<>SHIFT" || shortcut == "+<>CTRL<>SHIFT" ||
104 shortcut == "0<>CTRL<>SHIFT") 142 shortcut == "0<>CTRL<>SHIFT")
105 continue; 143 continue;
xiyuan 2017/04/13 06:56:21 nit: wrap with {} since condition is more than 1 l
wutao 2017/04/13 16:24:03 Done.
106 } 144 }
107 145
108 bool contains; 146 bool contains = ContainsShortcut(shortcut, web_contents);
xiyuan 2017/04/13 06:56:22 This can be removed and inlined with ASSERT_TRUE
wutao 2017/04/13 16:24:03 Done.
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 " 147 ASSERT_TRUE(contains) << "Please add the new accelerators to keyboard "
xiyuan 2017/04/13 06:56:21 ASSERT_TRUE -> EXPECT_TRUE so that the test can li
wutao 2017/04/13 16:24:03 Done.
116 "overlay. Add one entry '" + 148 "overlay. Add one entry '" +
117 shortcut + 149 shortcut +
118 "' in the 'shortcut' section" 150 "' in the 'shortcut' section"
119 " at the bottom of the file of " 151 " at the bottom of the file of "
120 "'/chrome/browser/resources/chromeos/" 152 "'/chrome/browser/resources/chromeos/"
121 "keyboard_overlay_data.js'. Please keep it in " 153 "keyboard_overlay_data.js'. Please keep it in "
122 "alphabetical order."; 154 "alphabetical order.";
123 } 155 }
124 } 156 }
157
158 IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest,
159 DeprecatedAcceleratorsShouldNotHaveKeyboardOverlay) {
160 content::WebContents* web_contents = StartKeyboardOverlayUI(browser());
161 for (size_t i = 0; i < ash::kDeprecatedAcceleratorsLength; ++i) {
162 const ash::AcceleratorData& entry = ash::kDeprecatedAccelerators[i];
163 if (ShouldSkip(entry))
164 continue;
xiyuan 2017/04/13 06:56:21 wrong indent.
wutao 2017/04/13 16:24:03 Done.
165
166 std::string shortcut = GenerateShortcutKey(entry, web_contents);
167 bool contains = ContainsShortcut(shortcut, web_contents);
xiyuan 2017/04/13 06:56:21 nit: Get rid of |shortcut| and |contains| and inli
wutao 2017/04/13 16:24:02 I need |shortcut| to print out some info for the o
168 ASSERT_FALSE(contains) << "Please remove the deprecated accelerator '" +
xiyuan 2017/04/13 06:56:22 ASSERT_FALSE -> EXPECT_FALSE to list all bad ones.
wutao 2017/04/13 16:24:03 Done.
169 shortcut +
170 "' from the 'shortcut' section"
171 " at the bottom of the file of "
172 "'/chrome/browser/resources/chromeos/"
173 "keyboard_overlay_data.js'.";
174 }
175 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698