Bug 1641960 - Introduce some Mac selection tests for inputs. r=morgan
authorEitan Isaacson <eitan@monotonous.org>
Fri, 29 May 2020 22:58:54 +0000
changeset 533090 ad89ceb0eb7d97f7b14b670e4f8475d9de16e473
parent 533089 8be3979560c8fd3b1fb65387d5e6bc4c1b1d96bf
child 533091 b8d9d72a25008e26738cc0a3d5b2681729915331
push id37462
push usermalexandru@mozilla.com
push dateSat, 30 May 2020 09:46:43 +0000
treeherdermozilla-central@8aaca63ec5c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmorgan
bugs1641960
milestone78.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 1641960 - Introduce some Mac selection tests for inputs. r=morgan Differential Revision: https://phabricator.services.mozilla.com/D77531
accessible/tests/browser/mac/browser.ini
accessible/tests/browser/mac/browser_input.js
--- a/accessible/tests/browser/mac/browser.ini
+++ b/accessible/tests/browser/mac/browser.ini
@@ -19,8 +19,9 @@ support-files =
 [browser_selectables.js]
 [browser_radio_position.js]
 [browser_toggle_radio_check.js]
 [browser_link.js]
 [browser_aria_haspopup.js]
 [browser_required.js]
 [browser_popupbutton.js]
 [browser_mathml.js]
+[browser_input.js]
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/mac/browser_input.js
@@ -0,0 +1,85 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * Input selection test
+ */
+addAccessibleTask(
+  `<input aria-label="Name" id="input" value="Elmer Fudd">`,
+  async (browser, accDoc) => {
+    let input = getNativeInterface(accDoc, "input");
+
+    is(input.getAttributeValue("AXDescription"), "Name", "Correct input label");
+    is(input.getAttributeValue("AXTitle"), "", "Correct input title");
+    is(
+      input.getAttributeValue("AXNumberOfCharacters"),
+      10,
+      "Correct length of value"
+    );
+
+    ok(input.attributeNames.includes("AXSelectedText"), "Has AXSelecetdText");
+    ok(
+      input.attributeNames.includes("AXSelectedTextRange"),
+      "Has AXSelecetdTextRange"
+    );
+
+    // XXX: Need to look into why we send so many AXSelectedTextChanged notifications.
+    let evt = Promise.all([
+      waitForMacEvent("AXFocusedUIElementChanged"),
+      waitForMacEvent("AXSelectedTextChanged"),
+      waitForMacEvent("AXSelectedTextChanged"),
+      waitForMacEvent("AXSelectedTextChanged"),
+    ]);
+    await SpecialPowers.spawn(browser, [], () => {
+      let elm = content.document.getElementById("input");
+      elm.focus();
+      elm.setSelectionRange(6, 9);
+    });
+    await evt;
+
+    is(
+      input.getAttributeValue("AXSelectedText"),
+      "Fud",
+      "Correct text is selected"
+    );
+
+    Assert.deepEqual(
+      input.getAttributeValue("AXSelectedTextRange"),
+      [6, 3],
+      "correct range selected"
+    );
+
+    ok(
+      input.isAttributeSettable("AXSelectedTextRange"),
+      "AXSelectedTextRange is settable"
+    );
+
+    evt = Promise.all([
+      waitForMacEvent("AXSelectedTextChanged"),
+      waitForMacEvent("AXSelectedTextChanged"),
+    ]);
+    input.setAttributeValue("AXSelectedTextRange", NSRange(1, 7));
+
+    Assert.deepEqual(
+      input.getAttributeValue("AXSelectedTextRange"),
+      [1, 7],
+      "correct range selected"
+    );
+
+    is(
+      input.getAttributeValue("AXSelectedText"),
+      "lmer Fu",
+      "Correct text is selected"
+    );
+
+    let domSelection = await SpecialPowers.spawn(browser, [], () => {
+      let elm = content.document.getElementById("input");
+      return [elm.selectionStart, elm.selectionEnd];
+    });
+
+    Assert.deepEqual(domSelection, [1, 8], "correct DOM selection");
+  }
+);