summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/browser/browser_label_textlink.js
blob: 4d53c2b5e99c05a6e77f4d50699ca9d17cd0fcf4 (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
add_task(async function () {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: "about:preferences" },
    async function (browser) {
      let newTabURL = "http://www.example.com/";
      await SpecialPowers.spawn(
        browser,
        [newTabURL],
        async function (newTabURL) {
          let doc = content.document;
          let label = doc.createXULElement("label", { is: "text-link" });
          label.href = newTabURL;
          label.id = "textlink-test";
          label.textContent = "click me";
          doc.body.append(label);
        }
      );

      // Test that click will open tab in foreground.
      let awaitNewTab = BrowserTestUtils.waitForNewTab(gBrowser, newTabURL);
      await BrowserTestUtils.synthesizeMouseAtCenter(
        "#textlink-test",
        {},
        browser
      );
      let newTab = await awaitNewTab;
      is(
        newTab.linkedBrowser,
        gBrowser.selectedBrowser,
        "selected tab should be example page"
      );
      BrowserTestUtils.removeTab(gBrowser.selectedTab);

      // Test that ctrl+shift+click/meta+shift+click will open tab in background.
      awaitNewTab = BrowserTestUtils.waitForNewTab(gBrowser, newTabURL);
      await BrowserTestUtils.synthesizeMouseAtCenter(
        "#textlink-test",
        { ctrlKey: true, metaKey: true, shiftKey: true },
        browser
      );
      await awaitNewTab;
      is(
        gBrowser.selectedBrowser,
        browser,
        "selected tab should be original tab"
      );
      BrowserTestUtils.removeTab(gBrowser.tabs[gBrowser.tabs.length - 1]);

      // Middle-clicking should open tab in foreground.
      awaitNewTab = BrowserTestUtils.waitForNewTab(gBrowser, newTabURL);
      await BrowserTestUtils.synthesizeMouseAtCenter(
        "#textlink-test",
        { button: 1 },
        browser
      );
      newTab = await awaitNewTab;
      is(
        newTab.linkedBrowser,
        gBrowser.selectedBrowser,
        "selected tab should be example page"
      );
      BrowserTestUtils.removeTab(gBrowser.tabs[gBrowser.tabs.length - 1]);
    }
  );
});