Bug 1430697 - Fix tests regression introduced in e140335f1237. r=me
MozReview-Commit-ID: HBXb2ECaTF9
--- a/intl/l10n/DOMLocalization.jsm
+++ b/intl/l10n/DOMLocalization.jsm
@@ -499,16 +499,33 @@ class DOMLocalization extends Localizati
}
}
}
/**
* Translate a DOM element or fragment asynchronously using this
* `DOMLocalization` object.
*
+ * Manually trigger the translation (or re-translation) of a DOM fragment.
+ * Use the `data-l10n-id` and `data-l10n-args` attributes to mark up the DOM
+ * with information about which translations to use.
+ *
+ * Returns a `Promise` that gets resolved once the translation is complete.
+ *
+ * @param {DOMFragment} frag - Element or DocumentFragment to be translated
+ * @returns {Promise}
+ */
+ translateFragment(frag) {
+ return this.translateElements(this.getTranslatables(frag));
+ }
+
+ /**
+ * Translate a list of DOM elements asynchronously using this
+ * `DOMLocalization` object.
+ *
* Manually trigger the translation (or re-translation) of a list of elements.
* Use the `data-l10n-id` and `data-l10n-args` attributes to mark up the DOM
* with information about which translations to use.
*
* Returns a `Promise` that gets resolved once the translation is complete.
*
* @param {Array<Element>} elements - List of elements to be translated
* @returns {Promise}
--- a/intl/l10n/test/chrome.ini
+++ b/intl/l10n/test/chrome.ini
@@ -1,11 +1,11 @@
[dom/test_domloc_getAttributes.html]
[dom/test_domloc_setAttributes.html]
-[dom/test_domloc_translateElement.html]
+[dom/test_domloc_translateElements.html]
[dom/test_domloc_translateFragment.html]
[dom/test_domloc_connectRoot.html]
[dom/test_domloc_disconnectRoot.html]
[dom/test_domloc_translateRoots.html]
[dom/test_domloc_mutations.html]
[dom/test_domloc_overlay.html]
[dom/test_domloc_overlay_repeated.html]
[dom/test_domloc_overlay_missing_children.html]
rename from intl/l10n/test/dom/test_domloc_translateElement.html
rename to intl/l10n/test/dom/test_domloc_translateElements.html
--- a/intl/l10n/test/dom/test_domloc_translateElement.html
+++ b/intl/l10n/test/dom/test_domloc_translateElements.html
@@ -1,13 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
- <title>Test DOMLocalization.prototype.translateElement</title>
+ <title>Test DOMLocalization.prototype.translateElements</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">
<script type="application/javascript">
"use strict";
const { DOMLocalization } =
Components.utils.import("resource://gre/modules/DOMLocalization.jsm", {});
const { MessageContext } =
Components.utils.import("resource://gre/modules/MessageContext.jsm", {});
@@ -26,20 +26,19 @@
window,
[],
mockGenerateMessages
);
const p1 = document.querySelectorAll('p')[0];
const link1 = document.querySelectorAll('a')[0];
- await domLoc.translateElement(p1);
+ await domLoc.translateElements([p1, link1]);
+
is(p1.textContent, "Hello World");
-
- await domLoc.translateElement(link1);
is(link1.getAttribute('title'), "Click me");
SimpleTest.finish();
};
</script>
</head>
<body>
<p data-l10n-id="title" />
--- a/intl/l10n/test/test_domlocalization.js
+++ b/intl/l10n/test/test_domlocalization.js
@@ -2,13 +2,14 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
const { DOMLocalization } =
Components.utils.import("resource://gre/modules/DOMLocalization.jsm", {});
add_task(function test_methods_presence() {
equal(typeof DOMLocalization.prototype.getAttributes, "function");
equal(typeof DOMLocalization.prototype.setAttributes, "function");
+ equal(typeof DOMLocalization.prototype.translateFragment, "function");
equal(typeof DOMLocalization.prototype.translateElements, "function");
equal(typeof DOMLocalization.prototype.connectRoot, "function");
equal(typeof DOMLocalization.prototype.disconnectRoot, "function");
equal(typeof DOMLocalization.prototype.translateRoots, "function");
});