summaryrefslogtreecommitdiffstats
path: root/browser/actors/test/browser/browser_nested_link_clicks.js
blob: 32ac6a46853efe0b31fe614811672ac937633137 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Nested links should only open a single tab when ctrl-clicked.
 */
add_task(async function nested_link_click_opens_single_tab() {
  await BrowserTestUtils.withNewTab(
    "https://example.com/empty",
    async browser => {
      await SpecialPowers.spawn(browser, [], () => {
        let doc = content.document;
        let outerLink = doc.createElement("a");
        outerLink.href = "https://mozilla.org/";
        let link = doc.createElement("a");
        link.href = "https://example.org/linked";
        link.textContent = "Click me";
        link.id = "mylink";
        outerLink.append(link);
        doc.body.append(outerLink);
      });

      let startingNumberOfTabs = gBrowser.tabs.length;
      let newTabPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        "https://example.org/linked",
        true
      );
      await BrowserTestUtils.synthesizeMouseAtCenter(
        "#mylink",
        { accelKey: true },
        browser
      );
      let tab = await newTabPromise;
      is(
        gBrowser.tabs.length,
        startingNumberOfTabs + 1,
        "Should only have opened 1 tab."
      );
      BrowserTestUtils.removeTab(tab);
    }
  );
});