Bug 1524539 - Finish porting browser_autocomplete_a11y_label.js to QuantumBar. r=Jamie
authorDão Gottwald <dao@mozilla.com>
Sun, 12 May 2019 23:42:38 +0000
changeset 532431 37b9048629cfd3197b289f9c5d396116b6a0eb1f
parent 532430 04b9eaf2e4391fa9e0cc9b70b875b4c7628b8c82
child 532432 705cbeee6d09d365ed81c72e56e4c1a772477de1
push id11268
push usercsabou@mozilla.com
push dateTue, 14 May 2019 15:24:22 +0000
treeherdermozilla-beta@5fb7fcd568d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1524539
milestone68.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 1524539 - Finish porting browser_autocomplete_a11y_label.js to QuantumBar. r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D29811
browser/components/urlbar/tests/browser/browser.ini
browser/components/urlbar/tests/browser/browser_autocomplete_a11y_label.js
--- a/browser/components/urlbar/tests/browser/browser.ini
+++ b/browser/components/urlbar/tests/browser/browser.ini
@@ -8,18 +8,20 @@ tags=quantumbar
 support-files =
   dummy_page.html
   head.js
   head-common.js
 
 [browser_action_searchengine.js]
 [browser_action_searchengine_alias.js]
 [browser_autocomplete_a11y_label.js]
-skip-if = true # Bug 1524539 - need to fix a11y. When removing this line, uncomment the next (or fix it!).
-# skip-if = (verify && !debug && (os == 'win'))
+skip-if = (verify && !debug && (os == 'win'))
+support-files =
+  searchSuggestionEngine.xml
+  searchSuggestionEngine.sjs
 [browser_autocomplete_autoselect.js]
 [browser_autocomplete_cursor.js]
 [browser_autocomplete_edit_completed.js]
 [browser_autocomplete_enter_race.js]
 [browser_autocomplete_no_title.js]
 [browser_autocomplete_readline_navigation.js]
 skip-if = os != "mac" # Mac only feature
 [browser_autocomplete_tag_star_visibility.js]
--- a/browser/components/urlbar/tests/browser/browser_autocomplete_a11y_label.js
+++ b/browser/components/urlbar/tests/browser/browser_autocomplete_a11y_label.js
@@ -4,29 +4,70 @@
 /**
  * This test ensures that we produce good labels for a11y purposes.
  */
 
 const SUGGEST_ALL_PREF = "browser.search.suggest.enabled";
 const SUGGEST_URLBAR_PREF = "browser.urlbar.suggest.searches";
 const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
 
+async function getResultText(element) {
+  await initAccessibilityService();
+  await BrowserTestUtils.waitForCondition(() => accService.getAccessibleFor(element));
+  let accessible = accService.getAccessibleFor(element);
+  return accessible.name;
+}
+
+let accService;
+async function initAccessibilityService() {
+  if (accService) {
+    return;
+  }
+  accService = Cc["@mozilla.org/accessibilityService;1"].getService(
+    Ci.nsIAccessibilityService);
+  if (Services.appinfo.accessibilityEnabled) {
+    return;
+  }
+
+  async function promiseInitOrShutdown(init = true) {
+    await new Promise(resolve => {
+      let observe = (subject, topic, data) => {
+        Services.obs.removeObserver(observe, "a11y-init-or-shutdown");
+        // "1" indicates that the accessibility service is initialized.
+        if (data === (init ? "1" : "0")) {
+          resolve();
+        }
+      };
+      Services.obs.addObserver(observe, "a11y-init-or-shutdown");
+    });
+  }
+  await promiseInitOrShutdown(true);
+  registerCleanupFunction(async () => {
+    accService = null;
+    await promiseInitOrShutdown(false);
+  });
+}
+
 add_task(async function switchToTab() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:about");
 
   await promiseAutocompleteResultPopup("% about");
   let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
   Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
     "Should have a switch tab result");
 
-  // XXX Bug 1524539. This fails on QuantumBar because we're producing different
-  // outputs. Once we confirm accessibilty is ok with the new format, we
-  // should update and have this test running on QuantumBar.
   let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, 1);
-  is(element.label, "about:about about:about Tab", "Result a11y label should be: <title> <url> Tab");
+  is(await getResultText(element),
+     UrlbarPrefs.get("quantumbar") ?
+       // The extra spaces are here due to bug 1550644.
+       "about : about— Switch to Tab" :
+       "about:about about:about Tab",
+     UrlbarPrefs.get("quantumbar") ?
+       "Result a11y label should be: <title>— Switch to Tab" :
+       "Result a11y label should be: <title> <url> Tab");
 
   await UrlbarTestUtils.promisePopupClose(window);
   gBrowser.removeTab(tab);
 });
 
 add_task(async function searchSuggestions() {
   let engine = await SearchTestUtils.promiseNewSearchEngine(
     getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
@@ -47,27 +88,37 @@ add_task(async function searchSuggestion
   // by earlier tests.
   Assert.greaterOrEqual(length, 3,
     "Should get at least heuristic result + two search suggestions");
   // The first expected search is the search term itself since the heuristic
   // result will come before the search suggestions.
   let expectedSearches = [
     "foo",
     "foofoo",
-    "foobar",
+    // The extra spaces is here due to bug 1550644.
+    UrlbarPrefs.get("quantumbar") ? "foo bar " : "foobar",
   ];
   for (let i = 0; i < length; i++) {
     let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
     if (result.type === UrlbarUtils.RESULT_TYPE.SEARCH) {
       Assert.greaterOrEqual(expectedSearches.length, 0,
         "Should still have expected searches remaining");
       let suggestion = expectedSearches.shift();
-      // XXX Bug 1524539. This fails on QuantumBar because we're producing different
-      // outputs. Once we confirm accessibilty is ok with the new format, we
-      // should update and have this test running on QuantumBar.
       let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, i);
-      Assert.equal(element.label,
-        suggestion + " browser_searchSuggestionEngine searchSuggestionEngine.xml Search",
-        "Result label should be: <search term> <engine name> Search");
+      let selected = element.hasAttribute("selected");
+      if (!selected) {
+        // Simulate the result being selected so we see the expanded text.
+        element.toggleAttribute("selected", true);
+      }
+      Assert.equal(await getResultText(element),
+        UrlbarPrefs.get("quantumbar") ?
+          suggestion + "— Search with browser_searchSuggestionEngine searchSuggestionEngine.xml" :
+          suggestion + " browser_searchSuggestionEngine searchSuggestionEngine.xml Search",
+        UrlbarPrefs.get("quantumbar") ?
+          "Result label should be: <search term>— Search with <engine name>" :
+          "Result label should be: <search term> <engine name> Search");
+      if (!selected) {
+        element.toggleAttribute("selected", false);
+      }
     }
   }
   Assert.ok(expectedSearches.length == 0);
 });