browser_device_connected.js (1349B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { FxAccounts } = ChromeUtils.importESModule( 5 "resource://gre/modules/FxAccounts.sys.mjs" 6 ); 7 8 const DEVICES_URL = "https://example.com/devices"; 9 10 add_setup(async function () { 11 const origManageDevicesURI = FxAccounts.config.promiseManageDevicesURI; 12 FxAccounts.config.promiseManageDevicesURI = () => 13 Promise.resolve(DEVICES_URL); 14 setupMockAlertsService(); 15 16 registerCleanupFunction(function () { 17 FxAccounts.config.promiseManageDevicesURI = origManageDevicesURI; 18 delete window.FxAccounts; 19 }); 20 }); 21 22 async function testDeviceConnected(deviceName) { 23 info("testDeviceConnected with deviceName=" + deviceName); 24 BrowserTestUtils.startLoadingURIString( 25 gBrowser.selectedBrowser, 26 "about:mozilla" 27 ); 28 await waitForDocLoadComplete(); 29 30 let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser); 31 32 Services.obs.notifyObservers(null, "fxaccounts:device_connected", deviceName); 33 34 let tab = await waitForTabPromise; 35 Assert.ok("Tab successfully opened"); 36 37 Assert.equal(tab.linkedBrowser.currentURI.spec, DEVICES_URL); 38 39 BrowserTestUtils.removeTab(tab); 40 } 41 42 add_task(async function () { 43 await testDeviceConnected("My phone"); 44 }); 45 46 add_task(async function () { 47 await testDeviceConnected(null); 48 });