From a41077218e4b132fd93bd59522d861ec34ac67e0 Mon Sep 17 00:00:00 2001 From: Tim Nguyen Date: Mon, 21 Jan 2019 21:40:52 +0000 Subject: [PATCH] Bug 1520924 - Remove 'update' XBL binding and convert strings to Fluent. r=paolo,flod Differential Revision: https://phabricator.services.mozilla.com/D16982 --HG-- extra : moz-landing-system : lando --- .../tests/browser_advanced_update.js | 40 +++++++++--- .../bug_1520924_updateHistory.py | 64 +++++++++++++++++++ .../en-US/chrome/mozapps/update/updates.dtd | 3 - .../locales/en-US/toolkit/updates/history.ftl | 7 +- toolkit/mozapps/update/content/history.js | 40 +++++++++--- toolkit/mozapps/update/content/updates.css | 5 +- toolkit/mozapps/update/content/updates.xml | 50 --------------- 7 files changed, 136 insertions(+), 73 deletions(-) create mode 100644 python/l10n/fluent_migrations/bug_1520924_updateHistory.py diff --git a/browser/components/preferences/in-content/tests/browser_advanced_update.js b/browser/components/preferences/in-content/tests/browser_advanced_update.js index 5265de9f9d93..f255c1eae565 100644 --- a/browser/components/preferences/in-content/tests/browser_advanced_update.js +++ b/browser/components/preferences/in-content/tests/browser_advanced_update.js @@ -140,14 +140,38 @@ add_task(async function() { for (let i = 0; i < updates.length; ++i) { update = updates[i]; updateData = mockUpdateManager.getUpdateAt(i); - const l10nAttrs = frameDoc.l10n.getAttributes(update); - Assert.deepEqual(l10nAttrs, { - id: "update-full-name", - args: { name: updateData.name, buildID: updateData.buildID }, - }, "Wrong update name"); - is(update.installDate, formatInstallDate(updateData.installDate), "Wrong update installDate"); - is(update.detailsURL, updateData.detailsURL, "Wrong update detailsURL"); - is(update.status, updateData.statusText, "Wrong update status"); + + let testcases = [ + { + selector: ".update-name", + id: "update-full-build-name", + args: { name: updateData.name, buildID: updateData.buildID }, + }, + { + selector: ".update-installedOn-label", + id: "update-installed-on", + args: { date: formatInstallDate(updateData.installDate) }, + }, + { + selector: ".update-status-label", + id: "update-status", + args: { status: updateData.statusText }, + } + ]; + + for (let {selector, id, args} of testcases) { + const element = update.querySelector(selector); + const l10nAttrs = frameDoc.l10n.getAttributes(element); + Assert.deepEqual(l10nAttrs, { + id, + args, + }, "Wrong " + id); + } + + if (update.detailsURL) { + is(update.detailsURL, update.querySelector(".text-link").href, + "Wrong detailsURL"); + } } // Test the dialog window closes diff --git a/python/l10n/fluent_migrations/bug_1520924_updateHistory.py b/python/l10n/fluent_migrations/bug_1520924_updateHistory.py new file mode 100644 index 000000000000..14553f0c7d22 --- /dev/null +++ b/python/l10n/fluent_migrations/bug_1520924_updateHistory.py @@ -0,0 +1,64 @@ +# coding=utf8 + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +from __future__ import absolute_import +import fluent.syntax.ast as FTL +from fluent.migrate.helpers import transforms_from +from fluent.migrate.helpers import VARIABLE_REFERENCE +from fluent.migrate import COPY, CONCAT, REPLACE + + +def migrate(ctx): + """Bug 1520924 - Remove 'update' XBL binding and convert strings to Fluent, part {index}.""" + + ctx.add_transforms( + "toolkit/toolkit/updates/history.ftl", + "toolkit/toolkit/updates/history.ftl", + transforms_from( +""" +update-details = { COPY("toolkit/chrome/mozapps/update/updates.dtd", "update.details.label") } +""") +) + + ctx.add_transforms( + "toolkit/toolkit/updates/history.ftl", + "toolkit/toolkit/updates/history.ftl", + [ + FTL.Message( + id=FTL.Identifier("update-full-build-name"), + value=REPLACE( + "toolkit/chrome/mozapps/update/updates.properties", + "updateFullName", + { + "%1$S": VARIABLE_REFERENCE("name"), + "%2$S": VARIABLE_REFERENCE("buildID"), + }, + normalize_printf=True + ) + ), + FTL.Message( + id=FTL.Identifier("update-installed-on"), + value=CONCAT( + COPY( + "toolkit/chrome/mozapps/update/updates.dtd", + "update.installedOn.label" + ), + FTL.TextElement(" "), + VARIABLE_REFERENCE("date"), + ), + ), + FTL.Message( + id=FTL.Identifier("update-status"), + value=CONCAT( + COPY( + "toolkit/chrome/mozapps/update/updates.dtd", + "update.status.label" + ), + FTL.TextElement(" "), + VARIABLE_REFERENCE("status"), + ), + ), + ] +) diff --git a/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd b/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd index 1247776b4a47..593475523212 100644 --- a/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd +++ b/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd @@ -72,6 +72,3 @@ &brandShortName; now, continue working and restart later, or decline this update."> - - - diff --git a/toolkit/locales/en-US/toolkit/updates/history.ftl b/toolkit/locales/en-US/toolkit/updates/history.ftl index 8108a0fda07a..cfcdab536754 100644 --- a/toolkit/locales/en-US/toolkit/updates/history.ftl +++ b/toolkit/locales/en-US/toolkit/updates/history.ftl @@ -20,5 +20,8 @@ state-header = State # Variables: # $name (String): name of the update # $buildID (String): build identifier from the local updates.xml -update-full-name = - .name = { $name } ({ $buildID }) +update-full-build-name = { $name } ({ $buildID }) + +update-details = Details +update-installed-on = Installed on: { $date } +update-status = Status: { $status } diff --git a/toolkit/mozapps/update/content/history.js b/toolkit/mozapps/update/content/history.js index b12592b74641..8b6d73a7fb31 100644 --- a/toolkit/mozapps/update/content/history.js +++ b/toolkit/mozapps/update/content/history.js @@ -33,15 +33,38 @@ var gUpdateHistory = { var element = document.createXULElement("richlistitem"); element.className = "update"; + + const topLine = document.createXULElement("hbox"); + const nameLabel = document.createXULElement("label"); + nameLabel.className = "update-name"; + document.l10n.setAttributes(nameLabel, "update-full-build-name", { + name: update.name, + buildID: update.buildID, + }); + topLine.appendChild(nameLabel); + + if (update.detailsURL) { + const detailsLink = document.createXULElement("label"); + detailsLink.className = "text-link"; + detailsLink.href = update.detailsURL; + document.l10n.setAttributes(detailsLink, "update-details"); + topLine.appendChild(detailsLink); + } + + const installedOnLabel = document.createXULElement("label"); + installedOnLabel.className = "update-installedOn-label"; + document.l10n.setAttributes(installedOnLabel, "update-installed-on", { + date: this._formatDate(update.installDate), + }); + + const statusLabel = document.createXULElement("label"); + statusLabel.className = "update-status-label"; + document.l10n.setAttributes(statusLabel, "update-status", { + status: update.statusText, + }); + + element.append(topLine, installedOnLabel, statusLabel); this._view.appendChild(element); - element.setAttribute("data-l10n-attrs", "name"); - document.l10n.setAttributes(element, "update-full-name", { name: update.name, buildID: update.buildID}); - element.installDate = this._formatDate(update.installDate); - if (update.detailsURL) - element.detailsURL = update.detailsURL; - else - element.hideDetailsURL = true; - element.status = update.statusText; } } var cancelbutton = document.documentElement.getButton("cancel"); @@ -61,4 +84,3 @@ var gUpdateHistory = { return date.toLocaleString(undefined, dtOptions); }, }; - diff --git a/toolkit/mozapps/update/content/updates.css b/toolkit/mozapps/update/content/updates.css index 470343186c53..3311c45b4d0a 100644 --- a/toolkit/mozapps/update/content/updates.css +++ b/toolkit/mozapps/update/content/updates.css @@ -25,7 +25,10 @@ updateheader { /* Update History Window */ richlistitem.update { - -moz-binding: url("chrome://mozapps/content/update/updates.xml#update"); display: -moz-box; -moz-box-orient: vertical; } + +.update-name { + -moz-box-flex: 1; +} diff --git a/toolkit/mozapps/update/content/updates.xml b/toolkit/mozapps/update/content/updates.xml index 39bfe033a100..6f6f8e0ffd42 100644 --- a/toolkit/mozapps/update/content/updates.xml +++ b/toolkit/mozapps/update/content/updates.xml @@ -3,9 +3,6 @@ - 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/. --> - - - - - - - - - - - - &update.installedOn.label; - - - - &update.status.label; - - - - - - - - - - - - - - -