Bug 1527922 - fix test for keyboard navigation for devedition, take #3, r=aryx
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 15 Mar 2019 14:16:47 +0000
changeset 522047 8c0fb16248ee02f75908068d104948d3c92ca0c2
parent 522046 ce3d863f85ac9a88695b12a7ae891600277d7ef2
child 522048 7a0c015fcc50407349ec27b25ad0c002edca0f60
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaryx
bugs1527922
milestone67.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 1527922 - fix test for keyboard navigation for devedition, take #3, r=aryx Differential Revision: https://phabricator.services.mozilla.com/D23671
browser/base/content/test/keyboard/browser_toolbarKeyNav.js
--- a/browser/base/content/test/keyboard/browser_toolbarKeyNav.js
+++ b/browser/base/content/test/keyboard/browser_toolbarKeyNav.js
@@ -8,17 +8,20 @@
  * These tests assume the default browser configuration for toolbars unless
  * otherwise specified.
  */
 
 const PERMISSIONS_PAGE = "https://example.com/browser/browser/base/content/test/permissions/permissions.html";
 
 // The DevEdition has the DevTools button in the toolbar by default. Remove it
 // to prevent branch-specific rules what button should be focused.
-CustomizableUI.removeWidgetFromArea("developer-button");
+function resetToolbarWithoutDevEditionButtons() {
+  CustomizableUI.reset();
+  CustomizableUI.removeWidgetFromArea("developer-button");
+}
 
 async function expectFocusAfterKey(aKey, aFocus, aAncestorOk = false) {
   let res = aKey.match(/^(Shift\+)?(?:(.)|(.+))$/);
   let shift = Boolean(res[1]);
   let key;
   if (res[2]) {
     key = res[2]; // Character.
   } else {
@@ -32,19 +35,21 @@ async function expectFocusAfterKey(aKey,
   } else {
     expected = aFocus;
     if (aFocus == gURLBar.inputField) {
       friendlyExpected = "URL bar input";
     } else if (aFocus == gBrowser.selectedBrowser) {
       friendlyExpected = "Web document";
     }
   }
+  info("Listening on item " + (expected.id || expected.className));
   let focused = BrowserTestUtils.waitForEvent(expected, "focus", aAncestorOk);
   EventUtils.synthesizeKey(key, {shiftKey: shift});
-  await focused;
+  let receivedEvent = await focused;
+  info("Got focus on item: " + (receivedEvent.target.id || receivedEvent.target.className));
   ok(true, friendlyExpected + " focused after " + aKey + " pressed");
 }
 
 function startFromUrlBar() {
   gURLBar.focus();
   is(document.activeElement, gURLBar.inputField,
      "URL bar focused for start of test");
 }
@@ -64,23 +69,24 @@ function withNewBlankTab(taskFn) {
     // Therefore, explicitly disable the reload command.
     // We disable the command (rather than disabling the button directly) so the
     // button will be updated correctly for future page loads.
     document.getElementById("Browser:Reload").setAttribute("disabled", "true");
     await taskFn();
   });
 }
 
-add_task(async function setPref() {
+add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({
     set: [
       ["browser.toolbars.keyboard_navigation", true],
       ["accessibility.tabfocus", 7],
     ],
   });
+  resetToolbarWithoutDevEditionButtons();
 });
 
 // Test tab stops with no page loaded.
 add_task(async function testTabStopsNoPage() {
   await withNewBlankTab(async function() {
     startFromUrlBar();
     await expectFocusAfterKey("Shift+Tab", "home-button");
     await expectFocusAfterKey("Shift+Tab", "tabbrowser-tabs", true);
@@ -144,17 +150,17 @@ add_task(async function testTabStopsWith
 add_task(async function testTabStopNoButtons() {
   await withNewBlankTab(async function() {
     // The Back, Forward and Reload buttons are all currently disabled.
     // The Home button is the only other button at that tab stop.
     CustomizableUI.removeWidgetFromArea("home-button");
     startFromUrlBar();
     await expectFocusAfterKey("Shift+Tab", "tabbrowser-tabs", true);
     await expectFocusAfterKey("Tab", gURLBar.inputField);
-    CustomizableUI.reset();
+    resetToolbarWithoutDevEditionButtons();
     // Make sure the button is reachable now that it has been re-added.
     await expectFocusAfterKey("Shift+Tab", "home-button", true);
   });
 });
 
 // Test that right/left arrows move through toolbarbuttons.
 // This also verifies that:
 // 1. Right/left arrows do nothing when at the edges; and
@@ -223,18 +229,16 @@ add_task(async function testArrowsOverfl
     startFromUrlBar();
     await expectFocusAfterKey("Tab", "library-button");
     await expectFocusAfterKey("ArrowRight", "sidebar-button");
     await expectFocusAfterKey("ArrowRight", "nav-bar-overflow-button");
     await expectFocusAfterKey("ArrowRight", "PanelUI-menu-button");
     await expectFocusAfterKey("ArrowLeft", "nav-bar-overflow-button");
     // Make sure the button is not reachable once it is invisible again.
     await expectFocusAfterKey("ArrowRight", "PanelUI-menu-button");
-    CustomizableUI.reset();
+    resetToolbarWithoutDevEditionButtons();
     // Flush layout so its invisibility can be detected.
     document.getElementById("nav-bar-overflow-button").clientWidth;
     await expectFocusAfterKey("ArrowLeft", "sidebar-button");
   });
 });
 
-registerCleanupFunction(async function resetToolbar() {
-  await CustomizableUI.reset();
-});
+registerCleanupFunction(() => CustomizableUI.reset());