summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_bug1554070.js
blob: a5efc17e197bca89600f86221a2ae7fc84a339cf (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
"use strict";

const HTTPS_TEST_ROOT = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "https://example.com"
);

const URL0 = HTTPS_TEST_ROOT + "file_bug1554070_1.html";
const URL1 = HTTPS_TEST_ROOT + "file_bug1554070_2.html";
const URL2 = "https://example.org/";

add_task(async function () {
  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    waitForLoad: true,
  });

  let browser = tab.linkedBrowser;

  function click() {
    return SpecialPowers.spawn(browser, [], () => {
      let anchor = content.document.querySelector("a");
      anchor.click();
    });
  }

  // Load file_bug1554070_1.html.
  BrowserTestUtils.loadURIString(browser, URL0);
  await BrowserTestUtils.browserLoaded(browser, false, URL0);
  is(gBrowser.currentURI.spec, URL0, "loaded file_bug1554070_1.html");

  // Click the link in file_bug1554070_1.html. It should open
  // file_bug1554070_2.html in the current tab.
  await click();
  await BrowserTestUtils.browserLoaded(browser, false, URL1);
  is(gBrowser.currentURI.spec, URL1, "loaded file_bug1554070_2.html");

  // Click the link in file_bug1554070_2.html. It should open example.org in
  // a new tab.
  await Promise.all([
    click(),
    BrowserTestUtils.waitForNewTab(gBrowser, URL2, true),
  ]);
  is(gBrowser.tabs.length, 3, "got new tab");
  is(gBrowser.currentURI.spec, URL2, "loaded example.org");

  BrowserTestUtils.removeTab(gBrowser.selectedTab);
  BrowserTestUtils.removeTab(tab);
});