Bug 1446671 - convert mochitest/textcaret/test_browserui.xul test into a browser test, r=yzen, gijs
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 11 Apr 2018 16:13:30 -0400
changeset 467703 725ba91eecc190ef12642b354bee2203c1c59455
parent 467702 66a52ced217dda7eed86130861f8c41e2adbeb4e
child 467704 33d4420119d61139f2cb7ced1cd73ba72efe8cc2
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [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,57 @@
+/* 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 =