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

Unified 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: Fix nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/chromeos/keyboard_overlay_ui_browsertest.cc
diff --git a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui_browsertest.cc b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui_browsertest.cc
index 99eedb3ccfacedf44f3a6eb2530d9fdf0b049d44..9e1161f0714f91b75da926637680bc8557ac9592 100644
--- a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui_browsertest.cc
@@ -33,92 +33,141 @@ class TestWebUIMessageHandler : public content::WebUIMessageHandler {
DISALLOW_COPY_AND_ASSIGN(TestWebUIMessageHandler);
};
-} // namespace
-
-using KeyboardOverlayUIBrowserTest = InProcessBrowserTest;
-
-IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest,
- ShouldHaveKeyboardOverlay) {
- ui_test_utils::NavigateToURL(browser(),
+content::WebContents* StartKeyboardOverlayUI(Browser* browser) {
+ ui_test_utils::NavigateToURL(browser,
GURL(chrome::kChromeUIKeyboardOverlayURL));
content::WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
+ browser->tab_strip_model()->GetActiveWebContents();
web_contents->GetWebUI()->AddMessageHandler(
base::MakeUnique<TestWebUIMessageHandler>());
+ return web_contents;
+}
+bool IsDisplayUIScalingEnabled(content::WebContents* web_contents) {
bool is_display_ui_scaling_enabled;
- ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
web_contents,
"domAutomationController.send(isDisplayUIScalingEnabled());",
&is_display_ui_scaling_enabled));
+ return is_display_ui_scaling_enabled;
+}
+
+// Skip some accelerators in the tests:
+// 1. If the accelerator has no modifier, i.e. ui::EF_NONE, or for "Caps
+// Lock", such as ui::VKEY_MENU and ui::VKEY_LWIN, the logic to show it on
+// the keyboard overlay is not by the mapping of
+// keyboardOverlayData['shortcut'], so it can not be tested by this test.
+// 2. If it has debug modifiers: ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN |
+// ui::EF_SHIFT_DOWN
+bool ShouldSkip(const ash::AcceleratorData& accelerator) {
+ return accelerator.keycode == ui::VKEY_MENU ||
+ accelerator.keycode == ui::VKEY_LWIN ||
+ accelerator.modifiers == ui::EF_NONE ||
+ accelerator.modifiers ==
+ (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN);
+}
+std::string KeyboardCodeToLabel(const ash::AcceleratorData& accelerator,
+ content::WebContents* web_contents) {
+ std::string label;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString(
+ web_contents,
+ "domAutomationController.send("
+ " (function(number) {"
+ " if (!!KEYCODE_TO_LABEL[number]) {"
+ " return KEYCODE_TO_LABEL[number];"
+ " } else {"
+ " return 'NONE';"
+ " }"
+ " })(" +
+ std::to_string(static_cast<unsigned int>(accelerator.keycode)) +
+ " )"
+ ");",
+ &label));
+ if (label == "NONE") {
+ label = base::ToLowerASCII(static_cast<char>(
+ LocatedToNonLocatedKeyboardCode(accelerator.keycode)));
+ }
+ return label;
+}
+
+std::string GenerateShortcutKey(const ash::AcceleratorData& accelerator,
+ content::WebContents* web_contents) {
+ std::string shortcut = KeyboardCodeToLabel(accelerator, web_contents);
+ // The order of the "if" conditions should not be changed because the
+ // modifiers are expected to be alphabetical sorted in the generated
+ // shortcut.
+ if (accelerator.modifiers & ui::EF_ALT_DOWN)
+ shortcut.append("<>ALT");
+ if (accelerator.modifiers & ui::EF_CONTROL_DOWN)
+ shortcut.append("<>CTRL");
+ if (accelerator.modifiers & ui::EF_COMMAND_DOWN)
+ shortcut.append("<>SEARCH");
+ if (accelerator.modifiers & ui::EF_SHIFT_DOWN)
+ shortcut.append("<>SHIFT");
+ return shortcut;
+}
+
+bool ContainsShortcut(const std::string& shortcut,
+ content::WebContents* web_contents) {
+ bool contains;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ web_contents,
+ "domAutomationController.send("
+ " !!keyboardOverlayData['shortcut']['" + shortcut + "']"
+ ");",
+ &contains));
+ return contains;
+}
+
+} // namespace
+
+using KeyboardOverlayUIBrowserTest = InProcessBrowserTest;
+
+IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest,
+ AcceleratorsShouldHaveKeyboardOverlay) {
+ content::WebContents* const web_contents = StartKeyboardOverlayUI(browser());
+ const bool is_display_ui_scaling_enabled =
+ IsDisplayUIScalingEnabled(web_contents);
for (size_t i = 0; i < ash::kAcceleratorDataLength; ++i) {
const ash::AcceleratorData& entry = ash::kAcceleratorData[i];
- // Skip some accelerators in this test:
- // 1. If the accelerator has no modifier, i.e. ui::EF_NONE, or for "Caps
- // Lock", such as ui::VKEY_MENU and ui::VKEY_LWIN, the logic to show it on
- // the keyboard overlay is not by the mapping of
- // keyboardOverlayData['shortcut'], so it can not be tested by this test.
- // 2. If it has debug modifiers: ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN |
- // ui::EF_SHIFT_DOWN
- if (entry.keycode == ui::VKEY_MENU ||
- entry.keycode == ui::VKEY_LWIN ||
- entry.modifiers == ui::EF_NONE ||
- entry.modifiers ==
- (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN)) {
+ if (ShouldSkip(entry))
continue;
- }
-
- std::string shortcut;
- ASSERT_TRUE(content::ExecuteScriptAndExtractString(
- web_contents,
- "domAutomationController.send("
- " (function(number) {"
- " if (!!KEYCODE_TO_LABEL[number]) {"
- " return KEYCODE_TO_LABEL[number];"
- " } else {"
- " return 'NONE';"
- " }"
- " })(" + std::to_string(static_cast<unsigned int>(entry.keycode)) + ")"
- ");",
- &shortcut));
- if (shortcut == "NONE") {
- shortcut = base::ToLowerASCII(
- static_cast<char>(LocatedToNonLocatedKeyboardCode(entry.keycode)));
- }
-
- // The order of the "if" conditions should not be changed because the
- // modifiers are expected to be alphabetical sorted in the generated
- // shortcut.
- if (entry.modifiers & ui::EF_ALT_DOWN)
- shortcut.append("<>ALT");
- if (entry.modifiers & ui::EF_CONTROL_DOWN)
- shortcut.append("<>CTRL");
- if (entry.modifiers & ui::EF_COMMAND_DOWN)
- shortcut.append("<>SEARCH");
- if (entry.modifiers & ui::EF_SHIFT_DOWN)
- shortcut.append("<>SHIFT");
+ const std::string shortcut = GenerateShortcutKey(entry, web_contents);
if (!is_display_ui_scaling_enabled) {
if (shortcut == "-<>CTRL<>SHIFT" || shortcut == "+<>CTRL<>SHIFT" ||
- shortcut == "0<>CTRL<>SHIFT")
+ shortcut == "0<>CTRL<>SHIFT") {
continue;
+ }
}
- bool contains;
- ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
- web_contents,
- "domAutomationController.send("
- " !!keyboardOverlayData['shortcut']['" + shortcut + "']"
- ");",
- &contains));
- ASSERT_TRUE(contains) << "Please add the new accelerators to keyboard "
- "overlay. Add one entry '" +
- shortcut +
- "' in the 'shortcut' section"
- " at the bottom of the file of "
- "'/chrome/browser/resources/chromeos/"
- "keyboard_overlay_data.js'. Please keep it in "
- "alphabetical order.";
+ EXPECT_TRUE(ContainsShortcut(shortcut, web_contents))
+ << "Please add the new accelerators to keyboard "
+ "overlay. Add one entry '" +
+ shortcut +
+ "' in the 'shortcut' section"
+ " at the bottom of the file of "
+ "'/chrome/browser/resources/chromeos/"
+ "keyboard_overlay_data.js'. Please keep it in "
+ "alphabetical order.";
+ }
+}
+
+IN_PROC_BROWSER_TEST_F(KeyboardOverlayUIBrowserTest,
+ DeprecatedAcceleratorsShouldNotHaveKeyboardOverlay) {
+ content::WebContents* const web_contents = StartKeyboardOverlayUI(browser());
+ for (size_t i = 0; i < ash::kDeprecatedAcceleratorsLength; ++i) {
+ const ash::AcceleratorData& entry = ash::kDeprecatedAccelerators[i];
+ if (ShouldSkip(entry))
+ continue;
+
+ const std::string shortcut = GenerateShortcutKey(entry, web_contents);
+ EXPECT_FALSE(ContainsShortcut(shortcut, web_contents))
+ << "Please remove the deprecated accelerator '" + shortcut +
+ "' from the 'shortcut' section"
+ " at the bottom of the file of "
+ "'/chrome/browser/resources/chromeos/"
+ "keyboard_overlay_data.js'.";
}
}
« 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