Bug 1546432 - Add basic Mutations tests. r=smaug
authorZibi Braniecki <zbraniecki@mozilla.com>
Tue, 21 May 2019 19:22:29 +0000
changeset 475237 53386b4a7e83865eb8a1206c1c096f978a9a4b31
parent 475236 8444c891fa21bf91717021fc2a6c09ca1fa8ef06
child 475238 7eaaa8f90abd04fd6bedfd8e0dbd8fcba5027c0a
push id36058
push useraciure@mozilla.com
push dateFri, 24 May 2019 03:53:25 +0000
treeherdermozilla-central@c87317c41902 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1546432
milestone69.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 1546432 - Add basic Mutations tests. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D31553
dom/l10n/tests/mochitest/chrome.ini
dom/l10n/tests/mochitest/mutations/test_append_content_post_dcl.html
dom/l10n/tests/mochitest/mutations/test_append_content_pre_dcl.html
dom/l10n/tests/mochitest/mutations/test_append_fragment_post_dcl.html
dom/l10n/tests/mochitest/mutations/test_pause_observing.html
dom/l10n/tests/mochitest/mutations/test_set_attributes.html
--- a/dom/l10n/tests/mochitest/chrome.ini
+++ b/dom/l10n/tests/mochitest/chrome.ini
@@ -1,5 +1,11 @@
 [test_domoverlays_attributes.html]
 [test_domoverlays_functional_children.html]
 [test_domoverlays_text_children.html]
 [test_domoverlays_extra_text_markup.html]
 [test_domoverlays.xul]
+
+[mutations/test_append_content_post_dcl.html]
+[mutations/test_append_content_pre_dcl.html]
+[mutations/test_append_fragment_post_dcl.html]
+[mutations/test_set_attributes.html]
+[mutations/test_pause_observing.html]
new file mode 100644
--- /dev/null
+++ b/dom/l10n/tests/mochitest/mutations/test_append_content_post_dcl.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test L10n Mutations for ContentAppended after DOMContentLoaded</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
+  <script type="application/javascript">
+  "use strict";
+  SimpleTest.waitForExplicitFinish();
+
+  document.addEventListener("DOMContentLoaded", function() {
+    let elem = document.createElement("div");
+    document.l10n.setAttributes(elem, "crash-reports-title");
+    is(elem.textContent.length, 0);
+    let verifyL10n = () => {
+      if (elem.textContent.length > 0) {
+        window.removeEventListener("MozAfterPaint", verifyL10n);
+        SimpleTest.finish();
+      }
+    };
+    window.addEventListener("MozAfterPaint", verifyL10n);
+    document.body.appendChild(elem);
+  });
+  </script>
+</head>
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/l10n/tests/mochitest/mutations/test_append_content_pre_dcl.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test L10n Mutations for ContentAppended before DOMContentLoaded</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
+</head>
+<body>
+  <script type="application/javascript">
+  "use strict";
+  SimpleTest.waitForExplicitFinish();
+
+  let elem = document.createElement("div");
+  document.l10n.setAttributes(elem, "crash-reports-title");
+  is(elem.textContent.length, 0);
+  let verifyL10n = () => {
+    if (elem.textContent.length > 0) {
+      window.removeEventListener("MozAfterPaint", verifyL10n);
+      SimpleTest.finish();
+    }
+  };
+  window.addEventListener("MozAfterPaint", verifyL10n);
+  document.body.appendChild(elem);
+  </script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/l10n/tests/mochitest/mutations/test_append_fragment_post_dcl.html
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test L10n Mutations for appending a fragment after DOMContentLoaded</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
+  <script type="application/javascript">
+  "use strict";
+  SimpleTest.waitForExplicitFinish();
+
+  document.addEventListener("DOMContentLoaded", function() {
+    let frag = document.createDocumentFragment();
+    let elem = document.createElement("div");
+    document.l10n.setAttributes(elem, "crash-reports-title");
+    frag.appendChild(elem);
+
+    let elem2 = document.createElement("div");
+    document.l10n.setAttributes(elem2, "crash-reports-title");
+    frag.appendChild(elem2);
+
+    is(elem.textContent.length, 0);
+    is(elem2.textContent.length, 0);
+
+    let verifyL10n = () => {
+      if (elem.textContent.length > 0 && elem2.textContent.length > 0) {
+        window.removeEventListener("MozAfterPaint", verifyL10n);
+        SimpleTest.finish();
+      }
+    };
+    window.addEventListener("MozAfterPaint", verifyL10n);
+    document.body.appendChild(frag);
+  });
+  </script>
+</head>
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/l10n/tests/mochitest/mutations/test_pause_observing.html
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test L10n Mutations for Pause/Resume Observing</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
+  <script type="application/javascript">
+  "use strict";
+  SimpleTest.waitForExplicitFinish();
+
+  document.addEventListener("DOMContentLoaded", function() {
+    let elem1 = document.createElement("div");
+    let elem2 = document.createElement("div");
+    let elem3 = document.createElement("div");
+    is(elem1.textContent.length, 0);
+    is(elem2.textContent.length, 0);
+    is(elem3.textContent.length, 0);
+
+    document.l10n.setAttributes(elem1, "crash-reports-title");
+    document.l10n.setAttributes(elem2, "crash-reports-title");
+    document.l10n.setAttributes(elem3, "crash-reports-title");
+
+    let verifyL10n = () => {
+      if (elem1.textContent.length > 0 &&
+          elem2.textContent.length == 0 &&
+          elem3.textContent.length > 0) {
+        window.removeEventListener("MozAfterPaint", verifyL10n);
+        SimpleTest.finish();
+      }
+    };
+    window.addEventListener("MozAfterPaint", verifyL10n);
+    document.body.appendChild(elem1);
+    document.l10n.pauseObserving();
+    document.body.appendChild(elem2);
+    document.l10n.resumeObserving();
+    document.body.appendChild(elem3);
+  });
+  </script>
+</head>
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/l10n/tests/mochitest/mutations/test_set_attributes.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test L10n Mutations for AttributeChange after DOMContentLoaded</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
+  <link rel="localization" href="toolkit/about/aboutConfig.ftl"/>
+  <script type="application/javascript">
+  "use strict";
+  SimpleTest.waitForExplicitFinish();
+
+  document.addEventListener("DOMContentLoaded", async function() {
+    await document.l10n.ready;
+    let elem = document.getElementById("elem1");
+    let elem2 = document.getElementById("elem2");
+    is(elem.textContent.length, 0);
+    is(elem2.textContent.includes("Type 1"), true);
+    document.l10n.setAttributes(elem, "crash-reports-title");
+    elem2.setAttribute("data-l10n-args", JSON.stringify({type: "Type 2"}));
+
+    let verifyL10n = () => {
+      if (elem.textContent.length > 0 && elem2.textContent.includes("Type 2")) {
+        window.removeEventListener("MozAfterPaint", verifyL10n);
+        SimpleTest.finish();
+      }
+    };
+    window.addEventListener("MozAfterPaint", verifyL10n);
+  });
+  </script>
+</head>
+<body>
+  <div id="elem1"></div>
+  <div id="elem2" data-l10n-id="config-new-title" data-l10n-args='{"type":"Type 1"}'></div>
+</body>
+</html>