Bug 1446671 - Convert mochitest/textcaret/test_browserui.xul test into a browser test. r=yzen, gijs
☠☠ backed out by 66b410a96377 ☠ ☠
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 11 Apr 2018 16:13:30 -0400
changeset 412910 11a9cb8e82005c66878a623aee55426babf63f65
parent 412909 1eb0c09430e905f717da3248029e7af888a0c2df
child 412911 82693b15029f44e8fa44cdb8bc7c968054624630
push id33824
push userebalazs@mozilla.com
push dateThu, 12 Apr 2018 09:39:57 +0000
treeherdermozilla-central@246c614e1605 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen, gijs
bugs1446671
milestone61.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 1446671 - Convert mochitest/textcaret/test_browserui.xul test into a browser test. r=yzen, gijs
accessible/tests/browser/events/browser.ini
accessible/tests/browser/events/browser_test_textcaret.js
accessible/tests/mochitest/textcaret/a11y.ini
accessible/tests/mochitest/textcaret/test_browserui.xul
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/accessible/tests/browser/events/browser.ini
+++ b/accessible/tests/browser/events/browser.ini
@@ -2,10 +2,11 @@
 support-files =
   head.js
   !/accessible/tests/browser/events.js
   !/accessible/tests/browser/shared-head.js
   !/accessible/tests/mochitest/*.js
 
 [browser_test_docload.js]
 skip-if = e10s
+[browser_test_textcaret.js]
 [browser_test_focus_browserui.js]
 [browser_test_focus_dialog.js]
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/events/browser_test_textcaret.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Caret move events checker.
+ */
+function caretMoveChecker(target, caretOffset) {
+  return function(event) {
+    let cmEvent = event.QueryInterface(nsIAccessibleCaretMoveEvent);
+    return cmEvent.accessible == getAccessible(target) && cmEvent.caretOffset == caretOffset;
+  };
+}
+
+async function checkURLBarCaretEvents() {
+  let url = "about:mozilla";
+
+  let onDocLoad = waitForEvent(
+    EVENT_DOCUMENT_LOAD_COMPLETE,
+    event => {
+      try { return event.accessible.QueryInterface(nsIAccessibleDocument).URL == url; }
+      catch(e) { return false; }
+    }
+  );
+  let [ newWin ] = await Promise.all([
+    BrowserTestUtils.openNewBrowserWindow({ url }),
+    onDocLoad
+  ]);
+
+  let urlbarInputEl = newWin.document.getElementById("urlbar").inputField;
+  let urlbarInput = getAccessible(urlbarInputEl, [ nsIAccessibleText ]);
+
+  let onCaretMove = waitForEvents([
+    [ EVENT_TEXT_CARET_MOVED, caretMoveChecker(urlbarInput, url.length) ],
+    [ EVENT_FOCUS, urlbarInput ]
+  ]);
+
+  urlbarInput.caretOffset = -1;
+  await onCaretMove;
+  ok(true, "Caret move in URL bar #1");
+
+  onCaretMove = waitForEvent(
+    EVENT_TEXT_CARET_MOVED, caretMoveChecker(urlbarInput, 0)
+  );
+
+  urlbarInput.caretOffset = 0;
+  await onCaretMove;
+  ok(true, "Caret move in URL bar #2");
+
+  await BrowserTestUtils.closeWindow(newWin);
+}
+
+add_task(checkURLBarCaretEvents);
--- a/accessible/tests/mochitest/textcaret/a11y.ini
+++ b/accessible/tests/mochitest/textcaret/a11y.ini
@@ -1,6 +1,5 @@
 [DEFAULT]
 support-files =
   !/accessible/tests/mochitest/*.js
 
-[test_browserui.xul]
 [test_general.html]
deleted file mode 100644
--- a/accessible/tests/mochitest/textcaret/test_browserui.xul
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
-                 type="text/css"?>
-
-<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        title="Accessibility Caret Offset Test.">
-
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
-
-  <script type="application/javascript"
-          src="../common.js"></script>
-  <script type="application/javascript"
-          src="../role.js"></script>
-  <script type="application/javascript"
-          src="../states.js"></script>
-  <script type="application/javascript"
-          src="../events.js"></script>
-  <script type="application/javascript"
-          src="../browser.js"></script>
-
-  <script type="application/javascript">
-  <![CDATA[
-
-    ////////////////////////////////////////////////////////////////////////////
-    // Tests
-
-    gA11yEventDumpToConsole = true; // debug
-    //enableLogging("tree,verbose");
-
-    var gQueue = null;
-    function doTests()
-    {
-      gQueue = new eventQueue();
-      gQueue.push(new setCaretOffset(urlbarInput(), -1, urlbarInput()));
-      gQueue.push(new setCaretOffset(urlbarInput(), 0));
-      gQueue.onFinish = function()
-      {
-        closeBrowserWindow();
-      }
-
-      gQueue.invoke();
-    }
-
-    SimpleTest.waitForExplicitFinish();
-    openBrowserWindow(doTests, "about:mozilla");
-  ]]>
-  </script>
-
-  <vbox flex="1" style="overflow: auto;">
-  <body xmlns="http://www.w3.org/1999/xhtml">
-    <a target="_blank"
-       href="https://bugzilla.mozilla.org/show_bug.cgi?id=723833"
-       title="IAccessibleText::setCaretOffset on location or search bar causes focus to jump">
-      Bug 723833
-    </a>
-    <p id="display"></p>
-    <div id="content" style="display: none">
-    </div>
-    <pre id="test">
-    </pre>
-  </body>
-  </vbox>
-</window>
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -695,16 +695,20 @@ var BrowserTestUtils = {
       features += ",top=" + options.top;
     }
 
     if (options.hasOwnProperty("remote")) {
       let remoteState = options.remote ? "remote" : "non-remote";
       features += `,${remoteState}`;
     }
 
+    if (options.url) {
+      argString.data = options.url;
+    }
+
     let win = Services.ww.openWindow(
       opener, Services.prefs.getCharPref("browser.chromeURL"), "_blank",
       features, argString);
 
     // Wait for browser-delayed-startup-finished notification, it indicates
     // that the window has loaded completely and is ready to be used for
     // testing.
     let startupPromise =