Bug 1402069 - Add a test string for the new localization API. r?pike,mossop
MozReview-Commit-ID: KhCW1n9LDka
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -117,19 +117,16 @@ var whitelist = [
// browser/extensions/pdfjs/content/web/viewer.js#7450
{file: "resource://pdf.js/web/debugger.js"},
// These are used in content processes. They are actually referenced.
{file: "resource://shield-recipe-client-content/shield-content-frame.js"},
{file: "resource://shield-recipe-client-content/shield-content-process.js"},
- // New L10n API that is not yet used in production
- {file: "chrome://global/content/l10n.js"},
-
// Starting from here, files in the whitelist are bugs that need fixing.
// Bug 1339424 (wontfix?)
{file: "chrome://browser/locale/taskbar.properties",
platforms: ["linux", "macosx"]},
// Bug 1316187
{file: "chrome://global/content/customizeToolbar.xul"},
// Bug 1343837
{file: "chrome://global/content/findUtils.js"},
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -1181,22 +1181,38 @@ var gMainPane = {
}
},
buildContentProcessCountMenuList() {
if (Services.appinfo.browserTabsRemoteAutostart) {
let processCountPref = document.getElementById("dom.ipc.processCount");
let defaultProcessCount = processCountPref.defaultValue;
let bundlePreferences = document.getElementById("bundlePreferences");
- let label = bundlePreferences.getFormattedString("defaultContentProcessCount",
- [defaultProcessCount]);
+
let contentProcessCount =
document.querySelector(`#contentProcessCount > menupopup >
menuitem[value="${defaultProcessCount}"]`);
- contentProcessCount.label = label;
+
+ // New localization API experiment (October 2017).
+ // See bug 1402061 for details.
+ //
+ // The `intl.l10n.fluent.disabled` pref can be used
+ // to opt-out of the experiment in case of any
+ // unforseen problems. The legacy API will then
+ // be used.
+ if (Services.prefs.getBoolPref("intl.l10n.fluent.disabled", false)) {
+ let label = bundlePreferences.getFormattedString("defaultContentProcessCount",
+ [defaultProcessCount]);
+ contentProcessCount.label = label;
+ } else {
+ document.l10n.setAttributes(
+ contentProcessCount,
+ "default-content-process-count",
+ { num: defaultProcessCount });
+ }
document.getElementById("limitContentProcess").disabled = false;
document.getElementById("contentProcessCount").disabled = false;
document.getElementById("contentProcessCountEnabledDescription").hidden = false;
document.getElementById("contentProcessCountDisabledDescription").hidden = true;
} else {
document.getElementById("limitContentProcess").disabled = true;
document.getElementById("contentProcessCount").disabled = true;
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -1,14 +1,17 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
<!-- General panel -->
+<link rel="localization" href="browser/preferences/main.ftl"/>
+<script type="text/javascript" src="chrome://global/content/l10n.js"></script>
+
<script type="application/javascript"
src="chrome://browser/content/preferences/in-content/main.js"/>
#ifdef MOZ_UPDATER
<script type="application/javascript" src="chrome://browser/content/aboutDialog-appUpdater.js"/>
#endif
<script type="application/javascript"
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -80,8 +80,9 @@ skip-if = e10s
support-files =
subdialog.xul
subdialog2.xul
[browser_telemetry.js]
# Skip this test on Android as FHR and Telemetry are separate systems there.
skip-if = !healthreport || !telemetry || (os == 'linux' && debug) || (os == 'android')
[browser_containers_name_input.js]
run-if = nightly_build # Containers is enabled only on Nightly
+[browser_fluent.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_fluent.js
@@ -0,0 +1,48 @@
+/* eslint-disable mozilla/no-cpows-in-tests */
+
+function whenMainPaneLoadedFinished() {
+ return new Promise(function(resolve, reject) {
+ const topic = "main-pane-loaded";
+ Services.obs.addObserver(function observer(aSubject) {
+ Services.obs.removeObserver(observer, topic);
+ resolve();
+ }, topic);
+ });
+}
+
+// Temporary test for an experimental new localization API.
+// See bug 1402069 for details.
+add_task(async function() {
+ // The string is used only when `browserTabsRemoteAutostart` is true
+ if (!Services.appinfo.browserTabsRemoteAutostart) {
+ ok(true, "fake test to avoid harness complaining");
+ return;
+ }
+
+ await Promise.all([
+ openPreferencesViaOpenPreferencesAPI("general", {leaveOpen: true}),
+ whenMainPaneLoadedFinished(),
+ ]);
+
+ let doc = gBrowser.contentDocument;
+ await doc.l10n.ready;
+
+ let processCountPref = doc.getElementById("dom.ipc.processCount");
+ let defaultProcessCount = processCountPref.defaultValue;
+
+ let [ msg ] = await doc.l10n.formatMessages([
+ ["default-content-process-count", { num: defaultProcessCount }]
+ ]);
+
+ let elem = doc.querySelector(
+ `#contentProcessCount > menupopup > menuitem[value="${defaultProcessCount}"]`);
+
+ Assert.deepEqual(msg, {
+ value: null,
+ attrs: [
+ ["label", elem.getAttribute("label")]
+ ]
+ });
+
+ await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -41,16 +41,17 @@
@APPNAME@/Contents/PkgInfo
@RESPATH@/firefox.icns
@RESPATH@/document.icns
@RESPATH@/@LPROJ_ROOT@.lproj/*
#endif
[@AB_CD@]
@RESPATH@/dictionaries/*
+@RESPATH@/browser/localization/*
#if defined(XP_WIN) || defined(XP_LINUX)
@RESPATH@/fonts/*
#endif
@RESPATH@/hyphenation/*
@RESPATH@/browser/@PREF_DIR@/firefox-l10n.js
#ifdef HAVE_MAKENSISU
@BINPATH@/uninstall/helper.exe
#endif
new file mode 100644
--- /dev/null
+++ b/browser/locales/en-US/browser/preferences/main.ftl
@@ -0,0 +1,4 @@
+// Variables:
+// $num - default value of the `dom.ipc.processCount` pref.
+default-content-process-count
+ .label = { $num } (default)
--- a/browser/locales/jar.mn
+++ b/browser/locales/jar.mn
@@ -2,16 +2,19 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Note: This file should only contain locale entries. All
# override and resource entries should go to browser/base/jar.mn to avoid
# having to create the same entry for each locale.
+[localization] @AB_CD@.jar:
+ browser (%browser/**/*.ftl)
+
@AB_CD@.jar:
% locale browser @AB_CD@ %locale/browser/
* locale/browser/bookmarks.html (generic/profile/bookmarks.html.in)
locale/browser/aboutDialog.dtd (%chrome/browser/aboutDialog.dtd)
locale/browser/aboutPrivateBrowsing.dtd (%chrome/browser/aboutPrivateBrowsing.dtd)
locale/browser/aboutPrivateBrowsing.properties (%chrome/browser/aboutPrivateBrowsing.properties)
locale/browser/aboutRobots.dtd (%chrome/browser/aboutRobots.dtd)
locale/browser/aboutHome.dtd (%chrome/browser/aboutHome.dtd)