Bug 1446975 - Replace synced Tabs sidebar device icons. r=eoger
authorAmy Chan <amy_yyc@yahoo.com>
Tue, 27 Mar 2018 23:38:30 -0700
changeset 413133 dfdc093a1727
parent 413132 8bc58e08f3a7
child 413134 5c3c36ffacd8
push id33834
push useraiakab@mozilla.com
push dateFri, 13 Apr 2018 09:44:04 +0000
treeherdermozilla-central@cf543bdd424f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseoger
bugs1446975
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1446975 - Replace synced Tabs sidebar device icons. r=eoger MozReview-Commit-ID: GnawrVrfpEz
browser/base/content/test/sync/browser_contextmenu_sendpage.js
browser/base/content/test/urlbar/browser_page_action_menu.js
services/sync/tests/unit/test_syncedtabs.js
toolkit/components/places/tests/unifiedcomplete/test_remote_tab_matches.js
--- a/browser/base/content/test/sync/browser_contextmenu_sendpage.js
+++ b/browser/base/content/test/sync/browser_contextmenu_sendpage.js
@@ -4,16 +4,17 @@
 "use strict";
 
 const remoteClientsFixture = [ { id: 1, name: "Foo"}, { id: 2, name: "Bar"} ];
 
 add_task(async function setup() {
   await promiseSyncReady();
   // gSync.init() is called in a requestIdleCallback. Force its initialization.
   gSync.init();
+  sinon.stub(Weave.Service.clientsEngine, "getClientType").returns("desktop");
   await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
 });
 
 add_task(async function test_page_contextmenu() {
   const sandbox = setupSendTabMocks({ syncReady: true, clientsSynced: true, remoteClients: remoteClientsFixture,
                                       state: UIState.STATUS_SIGNED_IN, isSendableURI: true });
 
   await openContentContextMenu("#moztext", "context-sendpagetodevice");
@@ -188,16 +189,17 @@ add_task(async function test_page_contex
   [...document.querySelectorAll(".sync-ui-item")].forEach(e => e.hidden = false);
 });
 
 // We are not going to bother testing the visibility of context-sendlinktodevice
 // since it uses the exact same code.
 // However, browser_contextmenu.js contains tests that verify its presence.
 
 add_task(async function teardown() {
+  Weave.Service.clientsEngine.getClientType.restore();
   gBrowser.removeCurrentTab();
 });
 
 function checkPopup(expectedItems = null) {
   const popup = document.getElementById("context-sendpagetodevice-popup");
   if (!expectedItems) {
     is(popup.state, "closed", "Popup should be hidden.");
     return;
--- a/browser/base/content/test/urlbar/browser_page_action_menu.js
+++ b/browser/base/content/test/urlbar/browser_page_action_menu.js
@@ -264,16 +264,17 @@ add_task(async function sendToDevice_syn
     const lastSync = sandbox.stub(Weave.Service.clientsEngine, "isFirstSync").get(() => true);
     sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
     sandbox.stub(gSync, "isSendableURI").returns(true);
 
     sandbox.stub(Weave.Service, "sync").callsFake(() => {
       syncReady.get(() => true);
       lastSync.get(() => Date.now());
       sandbox.stub(gSync, "remoteClients").get(() => mockRemoteClients);
+      sandbox.stub(Weave.Service.clientsEngine, "getClientType").callsFake(id => mockRemoteClients.find(c => c.id == id).type);
     });
 
     let onShowingSubview = BrowserPageActions.sendToDevice.onShowingSubview;
     sandbox.stub(BrowserPageActions.sendToDevice, "onShowingSubview").callsFake((...args) => {
       this.numCall++ || (this.numCall = 1);
       onShowingSubview.call(BrowserPageActions.sendToDevice, ...args);
       testSendTabToDeviceMenu(this.numCall);
     });
@@ -400,16 +401,17 @@ add_task(async function sendToDevice_noD
   await BrowserTestUtils.withNewTab("http://example.com/", async () => {
     await promiseSyncReady();
     const sandbox = sinon.sandbox.create();
     sandbox.stub(gSync, "syncReady").get(() => true);
     sandbox.stub(Weave.Service.clientsEngine, "isFirstSync").get(() => false);
     sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
     sandbox.stub(gSync, "isSendableURI").returns(true);
     sandbox.stub(gSync, "remoteClients").get(() => []);
+    sandbox.stub(Weave.Service.clientsEngine, "getClientType").callsFake(id => mockRemoteClients.find(c => c.id == id).type);
 
     let cleanUp = () => {
       sandbox.restore();
     };
     registerCleanupFunction(cleanUp);
 
     // Open the panel.
     await promisePageActionPanelOpen();
@@ -465,16 +467,17 @@ add_task(async function sendToDevice_dev
   await BrowserTestUtils.withNewTab("http://example.com/", async () => {
     await promiseSyncReady();
     const sandbox = sinon.sandbox.create();
     sandbox.stub(gSync, "syncReady").get(() => true);
     sandbox.stub(Weave.Service.clientsEngine, "isFirstSync").get(() => false);
     sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
     sandbox.stub(gSync, "isSendableURI").returns(true);
     sandbox.stub(gSync, "remoteClients").get(() => mockRemoteClients);
+    sandbox.stub(Weave.Service.clientsEngine, "getClientType").callsFake(id => mockRemoteClients.find(c => c.id == id).type);
 
     let cleanUp = () => {
       sandbox.restore();
     };
     registerCleanupFunction(cleanUp);
 
     // Open the panel.
     await promisePageActionPanelOpen();
@@ -529,16 +532,17 @@ add_task(async function sendToDevice_inU
   await BrowserTestUtils.withNewTab("http://example.com/", async () => {
     await promiseSyncReady();
     const sandbox = sinon.sandbox.create();
     sandbox.stub(gSync, "syncReady").get(() => true);
     sandbox.stub(Weave.Service.clientsEngine, "isFirstSync").get(() => false);
     sandbox.stub(UIState, "get").returns({ status: UIState.STATUS_SIGNED_IN });
     sandbox.stub(gSync, "isSendableURI").returns(true);
     sandbox.stub(gSync, "remoteClients").get(() => mockRemoteClients);
+    sandbox.stub(Weave.Service.clientsEngine, "getClientType").callsFake(id => mockRemoteClients.find(c => c.id == id).type);
 
     let cleanUp = () => {
       sandbox.restore();
     };
     registerCleanupFunction(cleanUp);
 
     // Add Send to Device to the urlbar.
     let action = PageActions.actionForID("sendToDevice");
--- a/services/sync/tests/unit/test_syncedtabs.js
+++ b/services/sync/tests/unit/test_syncedtabs.js
@@ -47,16 +47,20 @@ let MockClientsEngine = {
     return this.clientSettings[id] !== false;
   },
   getClientName(id) {
     if (this.clientSettings[id]) {
       return this.clientSettings[id];
     }
     return tabsEngine.clients[id].clientName;
   },
+
+  getClientType(id) {
+    return "desktop";
+  }
 };
 
 function configureClients(clients, clientSettings = {}) {
   // each client record is expected to have an id.
   for (let [guid, client] of Object.entries(clients)) {
     client.id = guid;
   }
   tabsEngine.clients = clients;
--- a/toolkit/components/places/tests/unifiedcomplete/test_remote_tab_matches.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_remote_tab_matches.js
@@ -20,37 +20,37 @@ MockTabsEngine.prototype = {
   startTracking() {},
   getAllClients() {
     return this.clients;
   },
 };
 
 // A clients engine that doesn't need to be a constructor.
 let MockClientsEngine = {
-  isMobile(guid) {
+  getClientType(guid) {
     Assert.ok(guid.endsWith("desktop") || guid.endsWith("mobile"));
-    return guid.endsWith("mobile");
-  },
+    return guid.endsWith("mobile") ? "phone" : "desktop";
+  }
 };
 
 // Tell Sync about the mocks.
 Weave.Service.engineManager.register(MockTabsEngine);
-Weave.Service.clientsEngine = MockClientsEngine;
 
 // Tell the Sync XPCOM service it is initialized.
 let weaveXPCService = Cc["@mozilla.org/weave/service;1"]
                         .getService(Ci.nsISupports)
                         .wrappedJSObject;
 weaveXPCService.ready = true;
 
 // Configure the singleton engine for a test.
 function configureEngine(clients) {
   // Configure the instance Sync created.
   let engine = Weave.Service.engineManager.get("tabs");
   engine.clients = clients;
+  Weave.Service.clientsEngine = MockClientsEngine;
   // Send an observer that pretends the engine just finished a sync.
   Services.obs.notifyObservers(null, "weave:engine:sync:finish", "tabs");
 }
 
 // Make a match object suitable for passing to check_autocomplete.
 function makeRemoteTabMatch(url, deviceName, extra = {}) {
   return {
     uri: makeActionURI("remotetab", {url, deviceName}),