summaryrefslogtreecommitdiffstats
path: root/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_url.js
blob: 876193b7ad6dd0f6468268baaa3114b582c9468a (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_OPEN_URL() {
  const action = {
    type: "OPEN_URL",
    data: { args: EXAMPLE_URL, where: "current" },
  };
  await BrowserTestUtils.withNewTab("about:blank", async browser => {
    const loaded = BrowserTestUtils.browserLoaded(browser);
    await SMATestUtils.executeAndValidateAction(action);
    const url = await loaded;
    Assert.equal(
      url,
      "https://example.com/",
      "should open URL in the same tab"
    );
  });
});

add_task(async function test_OPEN_URL_new_tab() {
  const action = {
    type: "OPEN_URL",
    data: { args: EXAMPLE_URL, where: "tab" },
  };
  const tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, EXAMPLE_URL);
  await SpecialMessageActions.handleAction(action, gBrowser);
  const browser = await tabPromise;
  ok(browser, "should open URL in a new tab");
  BrowserTestUtils.removeTab(browser);
});