Bug 1327946 - Remove conditional moz-user-focus on identity block from urlbar. r=Gijs, a=lizzard
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 24 Jan 2017 11:42:09 +0100
changeset 378063 a8eefd5c63efa9ed822399b161a702cdae2cf4f8
parent 378062 5ae7001fbd3f6441525f70a8c4c2db12c5ce5b00
child 378064 0e1d4619f4c6e18f9add95dce45a6969f7310a00
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, lizzard
bugs1327946
milestone53.0a2
Bug 1327946 - Remove conditional moz-user-focus on identity block from urlbar. r=Gijs, a=lizzard 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',
 ]