Bug 1332858 - Alternate wording for Sync new device connected notification when device name missing. r?markh
MozReview-Commit-ID: DdwrRGjwI3
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2313,17 +2313,19 @@ BrowserGlue.prototype = {
}
},
_onDeviceConnected(deviceName) {
let accountsBundle = Services.strings.createBundle(
"chrome://browser/locale/accounts.properties"
);
let title = accountsBundle.GetStringFromName("deviceConnectedTitle");
- let body = accountsBundle.formatStringFromName("deviceConnectedBody", [deviceName], 1);
+ let body = accountsBundle.formatStringFromName("deviceConnectedBody" +
+ (deviceName ? "" : ".noDeviceName"),
+ [deviceName], 1);
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.settings.devices.uri");
function clickCallback(subject, topic, data) {
if (topic != "alertclickcallback")
return;
let win = RecentWindow.getMostRecentBrowserWindow({private: false});
if (!win) {
Services.appShell.hiddenDOMWindow.open(url);
--- a/browser/locales/en-US/chrome/browser/accounts.properties
+++ b/browser/locales/en-US/chrome/browser/accounts.properties
@@ -11,20 +11,23 @@ verifyDescription = Verify %S
# These strings are shown in a desktop notification after the
# user requests we resend a verification email.
verificationSentTitle = Verification Sent
# LOCALIZATION NOTE (verificationSentBody) - %S = Email address of user's Firefox Account
verificationSentBody = A verification link has been sent to %S.
verificationNotSentTitle = Unable to Send Verification
verificationNotSentBody = We are unable to send a verification mail at this time, please try again later.
-# LOCALIZATION NOTE (deviceConnectedTitle, deviceConnectedBody)
+# LOCALIZATION NOTE (deviceConnectedTitle, deviceConnectedBody, deviceConnectedBody.noDeviceName)
# These strings are used in a notification shown when a new device joins the Sync account.
+# deviceConnectedBody.noDeviceName is shown instead of deviceConnectedBody when we
+# could not get the device name that joined
deviceConnectedTitle = Firefox Sync
deviceConnectedBody = This computer is now syncing with %S.
+deviceConnectedBody.noDeviceName = This computer is now syncing with a new device.
# LOCALIZATION NOTE (syncStartNotification.title, syncStartNotification.body)
# These strings are used in a notification shown after Sync is connected.
syncStartNotification.title = Sync enabled
# %S is brandShortName
syncStartNotification.body2 = %S will begin syncing momentarily.
# LOCALIZATION NOTE (deviceDisconnectedNotification.title, deviceDisconnectedNotification.body)
--- a/services/fxaccounts/tests/browser/browser_device_connected.js
+++ b/services/fxaccounts/tests/browser/browser_device_connected.js
@@ -1,38 +1,60 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const { MockRegistrar } =
Cu.import("resource://testing-common/MockRegistrar.jsm", {});
-const StubAlertsService = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService, Ci.nsISupports]),
+let accountsBundle = Services.strings.createBundle(
+ "chrome://browser/locale/accounts.properties"
+);
+
+let expectedBody;
- showAlertNotification(image, title, text, clickable, cookie, clickCallback) {
- // We can't simulate a click on the alert popup,
- // so instead we call the click listener ourselves directly
- clickCallback.observe(null, "alertclickcallback", null);
- }
-}
+add_task(async function setup() {
+ const alertsService = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService, Ci.nsISupports]),
+ showAlertNotification: (image, title, text, clickable, cookie, clickCallback) => {
+ // We can't simulate a click on the alert popup,
+ // so instead we call the click listener ourselves directly
+ clickCallback.observe(null, "alertclickcallback", null);
+ Assert.equal(text, expectedBody);
+ }
+ };
+ let alertsServiceCID = MockRegistrar.register("@mozilla.org/alerts-service;1", alertsService);
+ registerCleanupFunction(() => {
+ MockRegistrar.unregister(alertsServiceCID);
+ });
+});
-add_task(function*() {
+async function testDeviceConnected(deviceName) {
+ info("testDeviceConnected with deviceName=" + deviceName);
gBrowser.selectedBrowser.loadURI("about:robots");
- yield waitForDocLoadComplete();
+ await waitForDocLoadComplete();
- MockRegistrar.register("@mozilla.org/alerts-service;1", StubAlertsService);
Preferences.set("identity.fxaccounts.settings.devices.uri", "http://localhost/devices");
let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
- Services.obs.notifyObservers(null, "fxaccounts:device_connected", "My phone");
+ Services.obs.notifyObservers(null, "fxaccounts:device_connected", deviceName);
- let tab = yield waitForTabPromise;
+ let tab = await waitForTabPromise;
Assert.ok("Tab successfully opened");
let expectedURI = Preferences.get("identity.fxaccounts.settings.devices.uri",
"prefundefined");
Assert.equal(tab.linkedBrowser.currentURI.spec, expectedURI);
- yield BrowserTestUtils.removeTab(tab);
+ await BrowserTestUtils.removeTab(tab);
+}
+
+add_task(async function() {
+ expectedBody = accountsBundle.formatStringFromName("deviceConnectedBody", ["My phone"], 1);
+ await testDeviceConnected("My phone");
});
+
+add_task(async function() {
+ expectedBody = accountsBundle.GetStringFromName("deviceConnectedBody.noDeviceName");
+ await testDeviceConnected(null);
+});