Bug 1168042, content process access key tests, r=masayuki
authorNeil Deakin <neil@mozilla.com>
Fri, 18 Sep 2015 08:19:20 -0400
changeset 295835 d3cc0e12f418b59e74f112192a7d83cb948147dd
parent 295834 30333d9cbcb9aaa4c38e92cb3a299bc81954fe6a
child 295836 4f79f9bd1754849a235097d26a6bce60deccb27b
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1168042
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168042, content process access key tests, r=masayuki
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_accesskeys.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -274,16 +274,17 @@ skip-if = buildapp == "mulet" || e10s # 
 tags = mcb
 [browser_mixedContentFramesOnHttp.js]
 tags = mcb
 [browser_bug970746.js]
 [browser_bug1015721.js]
 skip-if = os == 'win' || e10s # Bug 1159268 - Need a content-process safe version of synthesizeWheel
 [browser_bug1064280_changeUrlInPinnedTab.js]
 [browser_bug1070778.js]
+[browser_accesskeys.js]
 [browser_canonizeURL.js]
 skip-if = e10s # Bug 1094510 - test hits the network in e10s mode only
 [browser_clipboard.js]
 [browser_contentAreaClick.js]
 [browser_contextSearchTabPosition.js]
 skip-if = os == "mac" || e10s # bug 967013; e10s: bug 1094761 - test hits the network in e10s, causing next test to crash
 [browser_ctrlTab.js]
 [browser_datareporting_notification.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_accesskeys.js
@@ -0,0 +1,82 @@
+add_task(function *() {
+  yield pushPrefs(["ui.key.contentAccess", 5], ["ui.key.chromeAccess", 5]);
+
+  const gPageURL1 = "data:text/html,<body><p>" +
+                    "<button id='button' accesskey='y'>Button</button>" +
+                    "<input id='checkbox' type='checkbox' accesskey='z'>Checkbox" +
+                    "</p></body>";
+  let tab1 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, gPageURL1);
+  tab1.linkedBrowser.messageManager.loadFrameScript("data:,(" + childHandleFocus.toString() + ")();", false);
+
+  Services.focus.clearFocus(window);
+
+  // Press an accesskey in the child document while the chrome is focused.
+  let focusedId = yield performAccessKey("y");
+  is(focusedId, "button", "button accesskey");
+
+  // Press an accesskey in the child document while the content document is focused.
+  focusedId = yield performAccessKey("z");
+  is(focusedId, "checkbox", "checkbox accesskey");
+
+  // Add an element with an accesskey to the chrome and press its accesskey while the chrome is focused.
+  let newButton = document.createElement("button");
+  newButton.id = "chromebutton";
+  newButton.setAttribute("accesskey", "z");
+  document.documentElement.appendChild(newButton);
+
+  Services.focus.clearFocus(window);
+
+  focusedId = yield performAccessKeyForChrome("z");
+  is(focusedId, "chromebutton", "chromebutton accesskey");
+
+  // Add a second tab and ensure that accesskey from the first tab is not used.
+  const gPageURL2 = "data:text/html,<body>" +
+                    "<button id='tab2button' accesskey='y'>Button in Tab 2</button>" +
+                    "</body>";
+  let tab2 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, gPageURL2);
+  tab2.linkedBrowser.messageManager.loadFrameScript("data:,(" + childHandleFocus.toString() + ")();", false);
+
+  Services.focus.clearFocus(window);
+
+  focusedId = yield performAccessKey("y");
+  is(focusedId, "tab2button", "button accesskey in tab2");
+
+  // Press the accesskey for the chrome element while the content document is focused.
+  focusedId = yield performAccessKeyForChrome("z");
+  is(focusedId, "chromebutton", "chromebutton accesskey");
+
+  newButton.parentNode.removeChild(newButton);
+
+  gBrowser.removeTab(tab1);
+  gBrowser.removeTab(tab2);
+});
+
+function childHandleFocus() {
+  content.document.body.firstChild.addEventListener("focus", function focused(event) {
+    let focusedElement = content.document.activeElement;
+    focusedElement.blur();
+    sendAsyncMessage("Test:FocusFromAccessKey", { focus: focusedElement.id })
+  }, true);
+}
+
+function performAccessKey(key)
+{
+  return new Promise(resolve => {
+    let mm = gBrowser.selectedBrowser.messageManager;
+    mm.addMessageListener("Test:FocusFromAccessKey", function listenForFocus(msg) {
+      mm.removeMessageListener("Test:FocusFromAccessKey", listenForFocus);
+      resolve(msg.data.focus);
+    });
+
+    EventUtils.synthesizeKey(key, { altKey: true, shiftKey: true });
+  });
+}
+
+// This version is used when a chrome elemnt is expected to be found for an accesskey.
+function* performAccessKeyForChrome(key, inChild)
+{
+  let waitFocusChangePromise = BrowserTestUtils.waitForEvent(document, "focus", true);
+  EventUtils.synthesizeKey(key, { altKey: true, shiftKey: true });
+  yield waitFocusChangePromise;
+  return document.activeElement.id;
+}