Loading services/sync/modules/engines/clients.js +18 −1 Original line number Diff line number Diff line Loading @@ -237,7 +237,24 @@ ClientEngine.prototype = { return this.localName; } let client = this._store._remoteClients[id]; return client ? client.name : ""; if (!client) { return ""; } // Sometimes the sync clients don't always correctly update the device name // However FxA always does, so try to pull the name from there first let fxaDevice = this.fxAccounts.device.recentDeviceList.find( device => device.id === client.fxaDeviceId ); // should be very rare, but could happen if we have yet to fetch devices, // or the client recently disconnected if (!fxaDevice) { this.log.warn( "Couldn't find associated FxA device, falling back to client name" ); return client.name; } return fxaDevice.name; }, getClientFxaDeviceId(id) { Loading services/sync/tests/unit/test_syncedtabs.js +63 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,27 @@ Log.repository.getLogger("Sync.RemoteTabs").addAppender(new Log.DumpAppender()); // engine. We pass a constructor that Sync creates. function MockTabsEngine() { this.clients = {}; // We'll set this dynamically // Mock fxAccounts + recentDeviceList as if we hit the FxA server this.fxAccounts = { device: { recentDeviceList: [ { id: 1, name: "updated desktop name", availableCommands: { "https://identity.mozilla.com/cmd/open-uri": "baz", }, }, { id: 2, name: "updated mobile name", availableCommands: { "https://identity.mozilla.com/cmd/open-uri": "boo", }, }, ], }, }; } MockTabsEngine.prototype = { Loading Loading @@ -54,7 +75,18 @@ let MockClientsEngine = { if (this.clientSettings[id]) { return this.clientSettings[id]; } return tabsEngine.clients[id].clientName; let client = tabsEngine.clients[id]; let fxaDevice = tabsEngine.fxAccounts.device.recentDeviceList.find( device => device.id === client.fxaDeviceId ); return fxaDevice ? fxaDevice.name : client.clientName; }, getClientFxaDeviceId(id) { if (this.clientSettings[id]) { return this.clientSettings[id]; } return tabsEngine.clients[id].fxaDeviceId; }, getClientType(id) { Loading Loading @@ -273,3 +305,33 @@ add_task(async function test_duplicatesTabsAcrossClients() { equal(clients[0].tabs[0].url, "http://foo.com/"); equal(clients[1].tabs[0].url, "http://foo.com/"); }); add_task(async function test_clientsTabUpdatedName() { // See the "fxAccounts" object in the MockEngine above for the device list await configureClients({ guid_desktop: { clientName: "My Desktop", tabs: [ { urlHistory: ["http://foo.com/"], icon: "http://foo.com/favicon", }, ], fxaDeviceId: 1, }, guid_mobile: { clientName: "My Phone", tabs: [ { urlHistory: ["http://bar.com/"], icon: "http://bar.com/favicon", }, ], fxaDeviceId: 2, }, }); let clients = await SyncedTabs.getTabClients(); equal(clients.length, 2); equal(clients[0].name, "updated desktop name"); equal(clients[1].name, "updated mobile name"); }); Loading
services/sync/modules/engines/clients.js +18 −1 Original line number Diff line number Diff line Loading @@ -237,7 +237,24 @@ ClientEngine.prototype = { return this.localName; } let client = this._store._remoteClients[id]; return client ? client.name : ""; if (!client) { return ""; } // Sometimes the sync clients don't always correctly update the device name // However FxA always does, so try to pull the name from there first let fxaDevice = this.fxAccounts.device.recentDeviceList.find( device => device.id === client.fxaDeviceId ); // should be very rare, but could happen if we have yet to fetch devices, // or the client recently disconnected if (!fxaDevice) { this.log.warn( "Couldn't find associated FxA device, falling back to client name" ); return client.name; } return fxaDevice.name; }, getClientFxaDeviceId(id) { Loading
services/sync/tests/unit/test_syncedtabs.js +63 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,27 @@ Log.repository.getLogger("Sync.RemoteTabs").addAppender(new Log.DumpAppender()); // engine. We pass a constructor that Sync creates. function MockTabsEngine() { this.clients = {}; // We'll set this dynamically // Mock fxAccounts + recentDeviceList as if we hit the FxA server this.fxAccounts = { device: { recentDeviceList: [ { id: 1, name: "updated desktop name", availableCommands: { "https://identity.mozilla.com/cmd/open-uri": "baz", }, }, { id: 2, name: "updated mobile name", availableCommands: { "https://identity.mozilla.com/cmd/open-uri": "boo", }, }, ], }, }; } MockTabsEngine.prototype = { Loading Loading @@ -54,7 +75,18 @@ let MockClientsEngine = { if (this.clientSettings[id]) { return this.clientSettings[id]; } return tabsEngine.clients[id].clientName; let client = tabsEngine.clients[id]; let fxaDevice = tabsEngine.fxAccounts.device.recentDeviceList.find( device => device.id === client.fxaDeviceId ); return fxaDevice ? fxaDevice.name : client.clientName; }, getClientFxaDeviceId(id) { if (this.clientSettings[id]) { return this.clientSettings[id]; } return tabsEngine.clients[id].fxaDeviceId; }, getClientType(id) { Loading Loading @@ -273,3 +305,33 @@ add_task(async function test_duplicatesTabsAcrossClients() { equal(clients[0].tabs[0].url, "http://foo.com/"); equal(clients[1].tabs[0].url, "http://foo.com/"); }); add_task(async function test_clientsTabUpdatedName() { // See the "fxAccounts" object in the MockEngine above for the device list await configureClients({ guid_desktop: { clientName: "My Desktop", tabs: [ { urlHistory: ["http://foo.com/"], icon: "http://foo.com/favicon", }, ], fxaDeviceId: 1, }, guid_mobile: { clientName: "My Phone", tabs: [ { urlHistory: ["http://bar.com/"], icon: "http://bar.com/favicon", }, ], fxaDeviceId: 2, }, }); let clients = await SyncedTabs.getTabClients(); equal(clients.length, 2); equal(clients[0].name, "updated desktop name"); equal(clients[1].name, "updated mobile name"); });