Bug 1332858 - Alternate wording for Sync new device connected notification when device name missing. r?markh draft
authorEdouard Oger <eoger@fastmail.com>
Thu, 02 Feb 2017 15:49:03 -0500
changeset 469837 c1ad7468d14b4df92870f715cf3e312b8d33be63
parent 469123 f3d187bd0733b1182dffc97b5dfe623e18f92a44
child 544324 fe13ec29d9f01ed814ccac867341bc7e6b46fb0f
push id43865
push userbmo:eoger@fastmail.com
push dateThu, 02 Feb 2017 22:05:17 +0000
reviewersmarkh
bugs1332858
milestone54.0a1
Bug 1332858 - Alternate wording for Sync new device connected notification when device name missing. r?markh MozReview-Commit-ID: DdwrRGjwI3
browser/components/nsBrowserGlue.js
browser/locales/en-US/chrome/browser/accounts.properties
services/fxaccounts/tests/browser/browser_device_connected.js
--- 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);
+});