summaryrefslogtreecommitdiffstats
path: root/services/fxaccounts/tests/browser
diff options
context:
space:
mode:
Diffstat (limited to 'services/fxaccounts/tests/browser')
-rw-r--r--services/fxaccounts/tests/browser/browser.toml6
-rw-r--r--services/fxaccounts/tests/browser/browser_device_connected.js51
-rw-r--r--services/fxaccounts/tests/browser/browser_verify_login.js33
-rw-r--r--services/fxaccounts/tests/browser/head.js73
4 files changed, 163 insertions, 0 deletions
diff --git a/services/fxaccounts/tests/browser/browser.toml b/services/fxaccounts/tests/browser/browser.toml
new file mode 100644
index 0000000000..7cb752b59a
--- /dev/null
+++ b/services/fxaccounts/tests/browser/browser.toml
@@ -0,0 +1,6 @@
+[DEFAULT]
+support-files = ["head.js"]
+
+["browser_device_connected.js"]
+
+["browser_verify_login.js"]
diff --git a/services/fxaccounts/tests/browser/browser_device_connected.js b/services/fxaccounts/tests/browser/browser_device_connected.js
new file mode 100644
index 0000000000..8e567ddf35
--- /dev/null
+++ b/services/fxaccounts/tests/browser/browser_device_connected.js
@@ -0,0 +1,51 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const { FxAccounts } = ChromeUtils.importESModule(
+ "resource://gre/modules/FxAccounts.sys.mjs"
+);
+
+const gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService(
+ Ci.nsIObserver
+);
+const DEVICES_URL = "https://example.com/devices";
+
+add_setup(async function () {
+ const origManageDevicesURI = FxAccounts.config.promiseManageDevicesURI;
+ FxAccounts.config.promiseManageDevicesURI = () =>
+ Promise.resolve(DEVICES_URL);
+ setupMockAlertsService();
+
+ registerCleanupFunction(function () {
+ FxAccounts.config.promiseManageDevicesURI = origManageDevicesURI;
+ delete window.FxAccounts;
+ });
+});
+
+async function testDeviceConnected(deviceName) {
+ info("testDeviceConnected with deviceName=" + deviceName);
+ BrowserTestUtils.startLoadingURIString(
+ gBrowser.selectedBrowser,
+ "about:mozilla"
+ );
+ await waitForDocLoadComplete();
+
+ let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
+
+ Services.obs.notifyObservers(null, "fxaccounts:device_connected", deviceName);
+
+ let tab = await waitForTabPromise;
+ Assert.ok("Tab successfully opened");
+
+ Assert.equal(tab.linkedBrowser.currentURI.spec, DEVICES_URL);
+
+ BrowserTestUtils.removeTab(tab);
+}
+
+add_task(async function () {
+ await testDeviceConnected("My phone");
+});
+
+add_task(async function () {
+ await testDeviceConnected(null);
+});
diff --git a/services/fxaccounts/tests/browser/browser_verify_login.js b/services/fxaccounts/tests/browser/browser_verify_login.js
new file mode 100644
index 0000000000..fa9d952a52
--- /dev/null
+++ b/services/fxaccounts/tests/browser/browser_verify_login.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function () {
+ let payload = {
+ data: {
+ deviceName: "Laptop",
+ url: "https://example.com/newLogin",
+ title: "Sign-in Request",
+ body: "New sign-in request from vershwal's Nighty on Intel Mac OS X 10.12",
+ },
+ };
+ info("testVerifyNewSignin");
+ setupMockAlertsService();
+ BrowserTestUtils.startLoadingURIString(
+ gBrowser.selectedBrowser,
+ "about:mozilla"
+ );
+ await waitForDocLoadComplete();
+
+ let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
+
+ Services.obs.notifyObservers(
+ null,
+ "fxaccounts:verify_login",
+ JSON.stringify(payload.data)
+ );
+
+ let tab = await waitForTabPromise;
+ Assert.ok("Tab successfully opened");
+ Assert.equal(tab.linkedBrowser.currentURI.spec, payload.data.url);
+ BrowserTestUtils.removeTab(tab);
+});
diff --git a/services/fxaccounts/tests/browser/head.js b/services/fxaccounts/tests/browser/head.js
new file mode 100644
index 0000000000..e9fb8ad0dc
--- /dev/null
+++ b/services/fxaccounts/tests/browser/head.js
@@ -0,0 +1,73 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Waits for the next load to complete in any browser or the given browser.
+ * If a <tabbrowser> is given it waits for a load in any of its browsers.
+ *
+ * @return promise
+ */
+function waitForDocLoadComplete(aBrowser = gBrowser) {
+ return new Promise(resolve => {
+ let listener = {
+ onStateChange(webProgress, req, flags, status) {
+ let docStop =
+ Ci.nsIWebProgressListener.STATE_IS_NETWORK |
+ Ci.nsIWebProgressListener.STATE_STOP;
+ info(
+ "Saw state " +
+ flags.toString(16) +
+ " and status " +
+ status.toString(16)
+ );
+
+ // When a load needs to be retargetted to a new process it is cancelled
+ // with NS_BINDING_ABORTED so ignore that case
+ if ((flags & docStop) == docStop && status != Cr.NS_BINDING_ABORTED) {
+ aBrowser.removeProgressListener(this);
+ waitForDocLoadComplete.listeners.delete(this);
+
+ let chan = req.QueryInterface(Ci.nsIChannel);
+ info("Browser loaded " + chan.originalURI.spec);
+ resolve();
+ }
+ },
+ QueryInterface: ChromeUtils.generateQI([
+ "nsIWebProgressListener",
+ "nsISupportsWeakReference",
+ ]),
+ };
+ aBrowser.addProgressListener(listener);
+ waitForDocLoadComplete.listeners.add(listener);
+ info("Waiting for browser load");
+ });
+}
+
+function setupMockAlertsService() {
+ const alertsService = {
+ showAlertNotification: (
+ image,
+ title,
+ text,
+ clickable,
+ cookie,
+ clickCallback
+ ) => {
+ // We are invoking the event handler ourselves directly.
+ clickCallback(null, "alertclickcallback", null);
+ },
+ };
+ const gBrowserGlue = Cc["@mozilla.org/browser/browserglue;1"].getService(
+ Ci.nsIObserver
+ );
+ gBrowserGlue.observe(
+ { wrappedJSObject: alertsService },
+ "browser-glue-test",
+ "mock-alerts-service"
+ );
+}
+
+// Keep a set of progress listeners for waitForDocLoadComplete() to make sure
+// they're not GC'ed before we saw the page load.
+waitForDocLoadComplete.listeners = new Set();
+registerCleanupFunction(() => waitForDocLoadComplete.listeners.clear());