Bug 1435530 - part 1: Add automated tests to check Alt + D works as Ctrl + L when Alt is content access key's modifier r=enndeakin+6102 a=test-only
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 05 Feb 2018 18:01:25 +0900
changeset 454824 544407b1ac2f2d4cb579a7b558693b63707ff5ec
parent 454823 22be9d71d70b5c79486843468fc3766415e30c4f
child 454825 30d165841f3da737624edb48dbfe87442c916f96
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin, test-only
bugs1435530
milestone59.0
Bug 1435530 - part 1: Add automated tests to check Alt + D works as Ctrl + L when Alt is content access key's modifier r=enndeakin+6102 a=test-only MozReview-Commit-ID: FG5sRJfTvue
dom/events/moz.build
dom/events/test/browser.ini
dom/events/test/browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js
--- a/dom/events/moz.build
+++ b/dom/events/moz.build
@@ -2,16 +2,20 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "DOM: Events")
 
+BROWSER_CHROME_MANIFESTS += [
+  'test/browser.ini',
+]
+
 MOCHITEST_MANIFESTS += [
     'test/mochitest.ini',
     'test/pointerevents/mochitest.ini',
     'test/pointerevents/pointerlock/mochitest.ini',
 ]
 
 MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
 
new file mode 100644
--- /dev/null
+++ b/dom/events/test/browser.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+
+[browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js]
+skip-if = os != 'linux' && os != 'win' // Alt + D is defined only on Linux and Windows
new file mode 100644
--- /dev/null
+++ b/dom/events/test/browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js
@@ -0,0 +1,77 @@
+add_task(async function() {
+  // Even if modifier of a shortcut key same as modifier of content access key,
+  // the shortcut key should be executed if (remote) content doesn't handle it.
+  // This test uses existing shortcut key declaration on Linux and Windows.
+  // If you remove or change Alt + D, you need to keep check this with changing
+  // the pref or result check.
+
+  await new Promise(resolve => {
+    SpecialPowers.pushPrefEnv({"set": [["ui.key.generalAccessKey", -1],
+                                       ["ui.key.chromeAccess",  0 /* disabled */],
+                                       ["ui.key.contentAccess", 4 /* Alt */],
+                                       ["browser.search.widget.inNavBar", true]]},
+                              resolve);
+  });
+
+  const kTestPage = "data:text/html,<body>simple web page</body>";
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestPage);
+
+  let searchBar = BrowserSearch.searchBar;
+  searchBar.focus();
+
+  function promiseURLBarHasFocus() {
+    return new Promise(resolve => {
+      if (gURLBar.focused) {
+        ok(true, "The URL bar already has focus");
+        resolve();
+        return;
+      }
+      info("Waiting focus event...");
+      gURLBar.addEventListener("focus", () => {
+        ok(true, "The URL bar gets focus");
+        resolve();
+      }, {once: true});
+    });
+  }
+
+  function promiseURLBarSelectsAllText() {
+    return new Promise(resolve => {
+      function isAllTextSelected() {
+        return gURLBar.inputField.selectionStart === 0 &&
+               gURLBar.inputField.selectionEnd === gURLBar.inputField.value.length;
+      }
+      if (isAllTextSelected()) {
+        ok(true, "All text of the URL bar is already selected");
+        isnot(gURLBar.inputField.value, "", "The URL bar should have non-empty text");
+        resolve();
+        return;
+      }
+      info("Waiting selectionchange event...");
+      gURLBar.addEventListener("selectionchange", () => {
+        ok(isAllTextSelected(), "All text of the URL bar should be selected");
+        isnot(gURLBar.inputField.value, "", "The URL bar should have non-empty text");
+        resolve();
+      }, {once: true});
+    });
+  }
+
+  // Alt + D is a shortcut key to move focus to the URL bar and selects its text.
+  info("Pressing Alt + D in the search bar...");
+  EventUtils.synthesizeKey("d", {code: "KeyD", altKey: true});
+
+  await promiseURLBarHasFocus();
+  await promiseURLBarSelectsAllText();
+
+  // Alt + D in the URL bar should select all text in it.
+  await gURLBar.focus();
+  await promiseURLBarHasFocus();
+  gURLBar.inputField.selectionStart = gURLBar.inputField.selectionEnd =
+    gURLBar.inputField.value.length;
+
+  info("Pressing Alt + D in the URL bar...");
+  EventUtils.synthesizeKey("d", {code: "KeyD", altKey: true});
+  await promiseURLBarHasFocus();
+  await promiseURLBarSelectsAllText();
+
+  gBrowser.removeCurrentTab();
+});