summaryrefslogtreecommitdiffstats
path: root/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_show_firefox_accounts.js
blob: 82bba359a3236f07da59fabb7a432d4e85e73679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Note: "identity.fxaccounts.remote.root" is set to https://example.com in browser.ini
add_task(async function test_SHOW_FIREFOX_ACCOUNTS() {
  await BrowserTestUtils.withNewTab("about:blank", async browser => {
    let loaded = BrowserTestUtils.browserLoaded(browser);
    await SMATestUtils.executeAndValidateAction({
      type: "SHOW_FIREFOX_ACCOUNTS",
      data: { entrypoint: "snippets" },
    });
    Assert.equal(
      await loaded,
      "https://example.com/?context=fx_desktop_v3&entrypoint=snippets&action=email&service=sync",
      "should load fxa with endpoint=snippets"
    );

    // Open a URL
    loaded = BrowserTestUtils.browserLoaded(browser);
    await SMATestUtils.executeAndValidateAction({
      type: "SHOW_FIREFOX_ACCOUNTS",
      data: { entrypoint: "aboutwelcome" },
    });

    Assert.equal(
      await loaded,
      "https://example.com/?context=fx_desktop_v3&entrypoint=aboutwelcome&action=email&service=sync",
      "should load fxa with a custom endpoint"
    );

    // Open a URL with extra parameters
    loaded = BrowserTestUtils.browserLoaded(browser);
    await SMATestUtils.executeAndValidateAction({
      type: "SHOW_FIREFOX_ACCOUNTS",
      data: { entrypoint: "test", extraParams: { foo: "bar" } },
    });

    Assert.equal(
      await loaded,
      "https://example.com/?context=fx_desktop_v3&entrypoint=test&action=email&service=sync&foo=bar",
      "should load fxa with a custom endpoint and extra parameters in url"
    );
  });

  add_task(async function test_SHOW_FIREFOX_ACCOUNTS_where() {
    // Open FXA with a 'where' prop
    const action = {
      type: "SHOW_FIREFOX_ACCOUNTS",
      data: {
        entrypoint: "activity-stream-firstrun",
        where: "tab",
      },
    };
    const tabPromise = BrowserTestUtils.waitForNewTab(
      gBrowser,
      "https://example.com/?context=fx_desktop_v3&entrypoint=activity-stream-firstrun&action=email&service=sync"
    );

    await SpecialMessageActions.handleAction(action, gBrowser);
    const browser = await tabPromise;
    ok(browser, "should open FXA in a new tab");
    BrowserTestUtils.removeTab(browser);
  });
});