Bug 1327946 - Remove conditional moz-user-focus on identity block from urlbar. r=Gijs draft
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 24 Jan 2017 11:42:09 +0100
changeset 467196 5968118ed303ed6a49163a8d81cbe5fcb59861e3
parent 466730 a338e596b1d9f37186aaeddcfaa572ae043e578d
child 543635 9c9718b2ad1e011a78e3ae7cbb39aae6a594d296
push id43121
push userbmo:jhofmann@mozilla.com
push dateFri, 27 Jan 2017 10:29:11 +0000
reviewersGijs
bugs1327946
milestone54.0a1
Bug 1327946 - Remove conditional moz-user-focus on identity block from urlbar. r=Gijs MozReview-Commit-ID: 9F39TeDIGUf
browser/base/content/browser.css
browser/base/content/browser.xul
browser/base/content/test/siteIdentity/browser.ini
browser/base/content/test/siteIdentity/browser_identityBlock_focus.js
browser/base/content/test/siteIdentity/head.js
browser/base/moz.build
--- a/browser/base/content/browser.css
+++ b/browser/base/content/browser.css
@@ -560,18 +560,23 @@ toolbar:not(#TabsToolbar) > #personal-bo
 }
 
 #urlbar[pageproxystate="invalid"] > #identity-box > #blocked-permissions-container,
 #urlbar[pageproxystate="invalid"] > #identity-box > #notification-popup-box,
 #urlbar[pageproxystate="invalid"] > #identity-box > #identity-icon-labels {
   visibility: collapse;
 }
 
+#identity-box {
+  -moz-user-focus: normal;
+}
+
 #urlbar[pageproxystate="invalid"] > #identity-box {
   pointer-events: none;
+  -moz-user-focus: ignore;
 }
 
 #identity-icon-labels {
   max-width: 18em;
 }
 @media (max-width: 700px) {
   #urlbar-container {
     min-width: 45ch;
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -684,23 +684,19 @@
                      tabscrolling="true"
                      showcommentcolumn="true"
                      showimagecolumn="true"
                      enablehistory="true"
                      maxrows="10"
                      newlines="stripsurroundingwhitespace"
                      ontextentered="this.handleCommand(param);"
                      ontextreverted="return this.handleRevert();"
-                     pageproxystate="invalid"
-                     onfocus="document.getElementById('identity-box').style.MozUserFocus= 'normal'"
-                     onblur="setTimeout(() => { document.getElementById('identity-box').style.MozUserFocus = ''; }, 0);">
+                     pageproxystate="invalid">
               <!-- Use onclick instead of normal popup= syntax since the popup
-                   code fires onmousedown, and hence eats our favicon drag events.
-                   We only add the identity-box button to the tab order when the location bar
-                   has focus, otherwise pressing F6 focuses it instead of the location bar -->
+                   code fires onmousedown, and hence eats our favicon drag events. -->
               <box id="identity-box" role="button"
                    align="center"
                    aria-label="&urlbar.viewSiteInfo.label;"
                    onclick="gIdentityHandler.handleIdentityButtonEvent(event);"
                    onkeypress="gIdentityHandler.handleIdentityButtonEvent(event);"
                    ondragstart="gIdentityHandler.onDragStart(event);">
                 <image id="identity-icon"
                        consumeanchor="identity-box"
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/siteIdentity/browser.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+support-files =
+  head.js
+
+[browser_identityBlock_focus.js]
+skip-if = os == 'mac' # Bug 1334418 (try only)
+support-files = ../general/permissions.html
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/siteIdentity/browser_identityBlock_focus.js
@@ -0,0 +1,62 @@
+/* Tests that the identity block can be reached via keyboard
+ * shortcuts and that it has the correct tab order.
+ */
+
+const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
+const PERMISSIONS_PAGE = TEST_PATH + "permissions.html";
+
+function synthesizeKeyAndWaitForFocus(element, keyCode, options) {
+  let focused = BrowserTestUtils.waitForEvent(element, "focus");
+  EventUtils.synthesizeKey(keyCode, options);
+  return focused;
+}
+
+// Checks that the identity block is the next element after the urlbar
+// to be focused if there are no active notification anchors.
+add_task(function* testWithoutNotifications() {
+  yield BrowserTestUtils.withNewTab("https://example.com", function*() {
+    yield synthesizeKeyAndWaitForFocus(gURLBar, "l", {accelKey: true})
+    is(document.activeElement, gURLBar.inputField, "urlbar should be focused");
+    yield synthesizeKeyAndWaitForFocus(gIdentityHandler._identityBox, "VK_TAB", {shiftKey: true})
+    is(document.activeElement, gIdentityHandler._identityBox,
+       "identity block should be focused");
+  });
+});
+
+// Checks that when there is a notification anchor, it will receive
+// focus before the identity block.
+add_task(function* testWithoutNotifications() {
+
+  yield BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, function*(browser) {
+    let popupshown = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
+    // Request a permission;
+    BrowserTestUtils.synthesizeMouseAtCenter("#geo", {}, browser);
+    yield popupshown;
+
+    yield synthesizeKeyAndWaitForFocus(gURLBar, "l", {accelKey: true})
+    is(document.activeElement, gURLBar.inputField, "urlbar should be focused");
+    let geoIcon = document.getElementById("geo-notification-icon");
+    yield synthesizeKeyAndWaitForFocus(geoIcon, "VK_TAB", {shiftKey: true})
+    is(document.activeElement, geoIcon, "notification anchor should be focused");
+    yield synthesizeKeyAndWaitForFocus(gIdentityHandler._identityBox, "VK_TAB", {shiftKey: true})
+    is(document.activeElement, gIdentityHandler._identityBox,
+       "identity block should be focused");
+  });
+});
+
+// Checks that with invalid pageproxystate the identity block is ignored.
+add_task(function* testInvalidPageProxyState() {
+  yield BrowserTestUtils.withNewTab("about:blank", function*(browser) {
+    // Loading about:blank will automatically focus the urlbar, which, however, can
+    // race with the test code. So we only send the shortcut if the urlbar isn't focused yet.
+    if (document.activeElement != gURLBar.inputField) {
+      yield synthesizeKeyAndWaitForFocus(gURLBar, "l", {accelKey: true})
+    }
+    is(document.activeElement, gURLBar.inputField, "urlbar should be focused");
+    yield synthesizeKeyAndWaitForFocus(gBrowser.getTabForBrowser(browser), "VK_TAB", {shiftKey: true})
+    isnot(document.activeElement, gIdentityHandler._identityBox,
+          "identity block should not be focused");
+    // Restore focus to the url bar.
+    gURLBar.focus();
+  });
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/siteIdentity/head.js
@@ -0,0 +1,6 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Promise",
+  "resource://gre/modules/Promise.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+  "resource://gre/modules/Task.jsm");
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -17,16 +17,17 @@ MOCHITEST_CHROME_MANIFESTS += [
 BROWSER_CHROME_MANIFESTS += [
     'content/test/alerts/browser.ini',
     'content/test/captivePortal/browser.ini',
     'content/test/general/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/plugins/browser.ini',
     'content/test/popupNotifications/browser.ini',
     'content/test/referrer/browser.ini',
+    'content/test/siteIdentity/browser.ini',
     'content/test/social/browser.ini',
     'content/test/tabcrashed/browser.ini',
     'content/test/tabPrompts/browser.ini',
     'content/test/tabs/browser.ini',
     'content/test/urlbar/browser.ini',
     'content/test/webrtc/browser.ini',
 ]