Bug 1581206 - Reconvert browser_bug629172.js to mochitest. r=Ehsan, a=test-only
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 20 Sep 2019 14:56:47 +0000
changeset 555418 1ca02c38c072472cfbb6409b84a6e9d12da50b70
parent 555417 1136a9e1a53453b39f9197aa9864d6d4d9ab4094
child 555419 cb53769d4ecc7d0a3fbd447bcf7bf2e465b2496a
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, test-only
bugs1581206, 629172
milestone70.0
Bug 1581206 - Reconvert browser_bug629172.js to mochitest. r=Ehsan, a=test-only Currently, we can use chrome process's shortcut key with `EventUtils.synthesizeKey()` with enabling `"test.events.async.enabled"` pref. So, we should reconvert it to a mochitest for making it more stable. Oddly, when I try to run this test as test-verify on macOS, it permanently fails rendering resizer of `<textarea>` elements immediately after creation. Therefore, this patch disables this test in test-verify on macOS. Differential Revision: https://phabricator.services.mozilla.com/D46578
editor/libeditor/tests/browser.ini
editor/libeditor/tests/browser_bug629172.js
editor/libeditor/tests/bug629172.html
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug629172.html
--- a/editor/libeditor/tests/browser.ini
+++ b/editor/libeditor/tests/browser.ini
@@ -1,8 +1,5 @@
 [browser_bug527935.js]
 skip-if = toolkit == 'android'
 support-files =
   bug527935.html
   bug527935_2.html
-[browser_bug629172.js]
-skip-if = toolkit == 'android' || debug && ((os == 'mac') || (os == 'win' && os_version == '10.0' && bits == 64)) # Bug 1446282
-support-files = bug629172.html
deleted file mode 100644
--- a/editor/libeditor/tests/bug629172.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
-<style>
-textarea { resize: none }
-</style>
-</head>
-<body>
-<div id="content">
-<textarea id="ltr-ref" style="display: none">test.</textarea>
-<textarea id="rtl-ref" style="display: none; direction: rtl">test.</textarea>
-</div
-</body>
-</html>
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -127,16 +127,18 @@ skip-if = toolkit == 'android'
 skip-if = toolkit == 'android'
 [test_bug612128.html]
 [test_bug612447.html]
 [test_bug620906.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_bug622371.html]
 skip-if = toolkit == 'android' #bug 957797
 [test_bug625452.html]
+[test_bug629172.html]
+skip-if = toolkit == 'android' || (verify && (os == 'mac')) # Due to resizer rendring issue of macOS
 [test_bug629845.html]
 [test_bug635636.html]
 skip-if = os == 'android'
 [test_bug636465.html]
 skip-if = os == 'android'
 [test_bug638596.html]
 [test_bug641466.html]
 [test_bug645914.html]
rename from editor/libeditor/tests/browser_bug629172.js
rename to editor/libeditor/tests/test_bug629172.html
--- a/editor/libeditor/tests/browser_bug629172.js
+++ b/editor/libeditor/tests/test_bug629172.html
@@ -1,145 +1,106 @@
-add_task(async function() {
-  await new Promise(resolve => waitForFocus(resolve, window));
-
-  const kPageURL =
-    "http://example.org/browser/editor/libeditor/tests/bug629172.html";
-  await BrowserTestUtils.withNewTab(
-    {
-      gBrowser,
-      url: kPageURL,
-    },
-    async function(browser) {
-      await ContentTask.spawn(browser, {}, async function() {
-        var window = content.window.wrappedJSObject;
-        var document = window.document;
-
-        // Note: Using the with keyword, we would have been able to write this as:
-        //
-        // with (window) {
-        //   Screenshots = {};
-        //   // so on
-        // }
-        //
-        // However, browser-chrome tests are somehow forced to run in strict mode,
-        // which doesn't permit the usage of the with keyword, turning the following
-        // into the ugliest test you've ever seen.  :(
-        var LTRRef = document.getElementById("ltr-ref");
-        var RTLRef = document.getElementById("rtl-ref");
-        window.Screenshots = {};
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=629172
+-->
+<head>
+  <title>Test for Bug 629172</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629172">Mozilla Bug 629172</a>
+<p id="display"></p>
+<div id="content">
+<textarea id="ltr-ref" style="display: none">test.</textarea>
+<textarea id="rtl-ref" style="display: none; direction: rtl">test.</textarea>
+</div>
+<pre id="test">
+<script type="application/javascript">
 
-        // generate the reference screenshots
-        LTRRef.style.display = "";
-        document.body.clientWidth;
-        window.Screenshots.ltr = window.snapshotWindow(window);
-        LTRRef.remove();
-        RTLRef.style.display = "";
-        document.body.clientWidth;
-        window.Screenshots.rtl = window.snapshotWindow(window);
-        RTLRef.remove();
-        window.Screenshots.get = function(dir) {
-          return this[dir];
-        };
-      });
+/** Test for Bug 629172 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["test.events.async.enabled", true]],
+  });
+
+  let LTRRef = document.getElementById("ltr-ref");
+  let RTLRef = document.getElementById("rtl-ref");
+  let ReferenceScreenshots = {};
 
-      function simulateCtrlShiftX(aBrowser) {
-        // In e10s, the keypress event will be dispatched to the content process,
-        // but in non-e10s it is handled by the browser UI code and hence won't
-        // reach the web page.  As a result, we need to observe the event in
-        // the content process only in e10s mode.
-        if (gMultiProcessBrowser) {
-          return EventUtils.synthesizeAndWaitKey("x", {
-            accelKey: true,
-            shiftKey: true,
-          });
-        }
-        EventUtils.synthesizeKey("x", { accelKey: true, shiftKey: true });
-        return Promise.resolve();
-      }
+  // generate the reference screenshots
+  LTRRef.style.display = "";
+  document.body.clientWidth;
+  ReferenceScreenshots.ltr = snapshotWindow(window);
+  LTRRef.remove();
+  RTLRef.style.display = "";
+  document.body.clientWidth;
+  ReferenceScreenshots.rtl = snapshotWindow(window);
+  RTLRef.remove();
 
-      async function testDirection(initDir, aBrowser) {
-        await ContentTask.spawn(aBrowser, { initialDir: initDir }, function({
-          initialDir,
-        }) {
-          var window = content.window.wrappedJSObject;
-          var document = window.document;
+  async function testDirection(initialDir) {
+    function revertDir(aDir) {
+      return aDir == "rtl" ? "ltr" : "rtl";
+    }
 
-          var t = (window.t = document.createElement("textarea"));
-          t.setAttribute("dir", initialDir);
-          t.value = "test.";
-          window.inputEventCount = 0;
-          t.oninput = function() {
-            window.inputEventCount++;
-          };
-          document.getElementById("content").appendChild(t);
-          document.body.clientWidth;
-          var s1 = window.snapshotWindow(window);
-          window.ok = ok; // for assertSnapshots
-          window.assertSnapshots(
-            s1,
-            window.Screenshots.get(initialDir),
-            true,
-            /* fuzz = */ null,
-            "Textarea before switching the direction from " + initialDir,
-            "Reference " + initialDir + " textarea"
-          );
-          t.focus();
-          is(window.inputEventCount, 0, "input event count must be 0 before");
-        });
-        await simulateCtrlShiftX(aBrowser);
-        await ContentTask.spawn(aBrowser, { initialDir: initDir }, function({
-          initialDir,
-        }) {
-          var window = content.window.wrappedJSObject;
-          var expectedDir = initialDir == "ltr" ? "rtl" : "ltr";
-          is(
-            window.t.getAttribute("dir"),
-            expectedDir,
-            "The dir attribute must be correctly updated"
-          );
-          is(window.inputEventCount, 1, "input event count must be 1 after");
-          window.t.blur();
-          var s2 = window.snapshotWindow(window);
-          window.ok = ok; // for assertSnapshots
-          window.assertSnapshots(
-            s2,
-            window.Screenshots.get(expectedDir),
-            true,
-            /* fuzz = */ null,
-            "Textarea after switching the direction from " + initialDir,
-            "Reference " + expectedDir + " textarea"
-          );
-          window.t.focus();
-          is(window.inputEventCount, 1, "input event count must be 1 before");
-        });
-        await simulateCtrlShiftX(aBrowser);
-        await ContentTask.spawn(aBrowser, { initialDir: initDir }, function({
-          initialDir,
-        }) {
-          var window = content.window.wrappedJSObject;
+    function promiseFormatSetBlockTextDirectionInputEvent(aElement) {
+      return new Promise(resolve => {
+        function handler(aEvent) {
+          if (aEvent.inputType !== "formatSetBlockTextDirection") {
+            ok(false, `Unexpected input event received: inputType="${aEvent.inputType}"`);
+          } else {
+            aElement.removeEventListener("input", handler, true);
+            SimpleTest.executeSoon(resolve);
+          }
+        }
+        aElement.addEventListener("input", handler, true);
+      });
+    }
 
-          is(window.inputEventCount, 2, "input event count must be 2 after");
-          is(
-            window.t.getAttribute("dir"),
-            initialDir == "ltr" ? "ltr" : "rtl",
-            "The dir attribute must be correctly updated"
-          );
-          window.t.blur();
-          var s3 = window.snapshotWindow(window);
-          window.ok = ok; // for assertSnapshots
-          window.assertSnapshots(
-            s3,
-            window.Screenshots.get(initialDir),
-            true,
-            /* fuzz = */ null,
-            "Textarea after switching back the direction to " + initialDir,
-            "Reference " + initialDir + " textarea"
-          );
-          window.t.remove();
-        });
-      }
+    let textarea = document.createElement("textarea");
+    textarea.setAttribute("dir", initialDir);
+    textarea.value = "test.";
+    document.getElementById("content").appendChild(textarea);
+    document.body.clientWidth;
+    assertSnapshots(snapshotWindow(window), ReferenceScreenshots[initialDir],
+                    /* expectEqual = */ true, /* fuzz = */ null,
+                    `<textarea dir="${initialDir}"> before Accel+Shift+X`,
+                    `<textarea dir="${initialDir}">`);
+    textarea.focus();
+    let waitForInputEvent = promiseFormatSetBlockTextDirectionInputEvent(textarea);
+    synthesizeKey("X", {accelKey: true, shiftKey: true});
+    await waitForInputEvent;
+    is(textarea.getAttribute("dir"), revertDir(initialDir),
+       "The dir attribute must be correctly updated with first Accel+Shift+X");
+    textarea.blur();
+    assertSnapshots(snapshotWindow(window), ReferenceScreenshots[revertDir(initialDir)],
+                    /* expectEqual = */ true, /* fuzz = */ null,
+                    `<textarea dir="${initialDir}"> after first Accel+Shift+X`,
+                    `<textarea dir="${revertDir(initialDir)}">`);
+    textarea.focus();
+    waitForInputEvent = promiseFormatSetBlockTextDirectionInputEvent(textarea);
+    synthesizeKey("X", {accelKey: true, shiftKey: true});
+    await waitForInputEvent;
+    is(textarea.getAttribute("dir"), initialDir,
+       "The dir attribute must be correctly recovered with second Accel+Shift+X");
+    textarea.blur();
+    assertSnapshots(snapshotWindow(window), ReferenceScreenshots[initialDir],
+                    /* expectEqual = */ true, /* fuzz = */ null,
+                    `<textarea dir="${initialDir}"> after second Accel+Shift+X`,
+                    `<textarea dir="${initialDir}">`);
+    textarea.remove();
+  }
 
-      await testDirection("ltr", browser);
-      await testDirection("rtl", browser);
-    }
-  );
+  await testDirection("ltr");
+  await testDirection("rtl");
+
+  SimpleTest.finish();
 });
+
+</script>
+</pre>
+</body>
+</html>