summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_network_message_ctrl_click.js
blob: 9941ac6a218d49f93fd3e8bfba873a2120741ebb (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
67
68
// Test that URL opens in a new tab when click while
// pressing CTR (or CMD in MacOS) as expected.

"use strict";

const TEST_URI =
  "https://example.com/browser/devtools/client/webconsole/" +
  "test/browser/test-console.html";

add_task(async function () {
  // Enable net messages in the console for this test.
  await pushPref("devtools.webconsole.filter.net", true);
  const isMacOS = Services.appinfo.OS === "Darwin";

  // We open the console
  const hud = await openNewTabAndConsole(TEST_URI);

  info("Reload the content window to produce a network log");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
    content.wrappedJSObject.location.reload();
  });
  const message = await waitFor(() =>
    findMessageByType(hud, "test-console.html", ".network")
  );
  ok(message, "Network log found in the console");

  const currentTab = gBrowser.selectedTab;
  const tabLoaded = listenToTabLoad();

  info("Cmd/Ctrl click on the message");
  const urlObject = message.querySelector(".url");

  EventUtils.sendMouseEvent(
    {
      type: "click",
      [isMacOS ? "metaKey" : "ctrlKey"]: true,
    },
    urlObject,
    hud.ui.window
  );

  info("Opening the URL of the message on a new tab");
  const newTab = await tabLoaded;
  const newTabHref = newTab.linkedBrowser.currentURI.spec;

  is(newTabHref, TEST_URI, "Tab was opened with the expected URL");
  info("Remove the new tab and select the previous tab back");
  gBrowser.removeTab(newTab);
  gBrowser.selectedTab = currentTab;
});

/**
 * Simple helper to wrap a tab load listener in a promise.
 */
function listenToTabLoad() {
  return new Promise(resolve => {
    gBrowser.tabContainer.addEventListener(
      "TabOpen",
      function (evt) {
        const newTab = evt.target;
        BrowserTestUtils.browserLoaded(newTab.linkedBrowser).then(() =>
          resolve(newTab)
        );
      },
      { capture: true, once: true }
    );
  });
}