Bug 1665751 Part 2: Factor out the Select All And Focus element sequence into a utility function for use by other test files, r=yzen DONTBUILD
authorMarco Zehe <mzehe@mozilla.com>
Mon, 21 Sep 2020 18:34:27 +0000
changeset 549568 ac97b9243102a1e12d633f8b4f676eb8536ed01f
parent 549567 f624682db6472038fa953c7c750dd370126c9f46
child 549569 9d74ce5f7e0476e7bcde908d0cb495a145364026
push id126864
push usermzehe@mozilla.com
push dateTue, 22 Sep 2020 03:26:50 +0000
treeherderautoland@9d74ce5f7e04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen
bugs1665751
milestone83.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 1665751 Part 2: Factor out the Select All And Focus element sequence into a utility function for use by other test files, r=yzen DONTBUILD Differential Revision: https://phabricator.services.mozilla.com/D90859
accessible/tests/mochitest/promisified-events.js
accessible/tests/mochitest/textselection/test_userinput.html
--- a/accessible/tests/mochitest/promisified-events.js
+++ b/accessible/tests/mochitest/promisified-events.js
@@ -232,8 +232,27 @@ async function waitForEvents(events, mes
   }
 
   return results.map(([event]) => event);
 }
 
 function waitForOrderedEvents(events, message) {
   return waitForEvents(events, message, true);
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// Utility functions ported from events.js.
+
+/**
+ * This function selects all text in the passed-in element if it has an editor,
+ * before setting focus to it. This simulates behavio with the keyboard when
+ * tabbing to the element. This does explicitly what synthFocus did implicitly.
+ * This should be called only if you really want this behavior.
+ * @param  {string}  id  The element ID to focus
+ */
+function selectAllTextAndFocus(id) {
+  const elem = getNode(id);
+  if (elem.editor) {
+    elem.selectionStart = elem.selectionEnd = elem.value.length;
+  }
+
+  elem.focus();
+}
--- a/accessible/tests/mochitest/textselection/test_userinput.html
+++ b/accessible/tests/mochitest/textselection/test_userinput.html
@@ -13,23 +13,19 @@
           src="../common.js"></script>
   <script type="application/javascript"
           src="../promisified-events.js"></script>
 
   <script type="application/javascript">
     async function doTests() {
       // Tab to 't2' and then tab out of it: it must not have any selection.
       info("Select all text in t1 and focus it");
-      const t1 = getNode("t1");
-      let focused = waitForEvent(EVENT_FOCUS, t1);
-      // Simulate tabbing to it by selecting all text before focusing it.
-      if (t1.editor) {
-        t1.selectionStart = t1.selectionEnd = t1.value.length;
-      }
-      t1.focus();
+      let focused = waitForEvent(EVENT_FOCUS, "t1");
+      // Simulate tabbing to t1 by selecting all text before focusing it.
+      selectAllTextAndFocus("t1");
       await focused;
 
       info("Tab to t2");
       const t2 = getNode("t2");
       focused = waitForEvent(EVENT_FOCUS, t2);
       synthesizeKey("VK_TAB");
       await focused;