summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_bug_851132_middle_click.js
blob: ed0d5838b2e0c424d24b3551e04013b21c4e4bf3 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that middle click on style sheet doesn't open index.xhtml in a new
// tab (bug 851132).

const TESTCASE_URI = TEST_BASE_HTTP + "four.html";

add_task(async function () {
  const { ui } = await openStyleEditorForURL(TESTCASE_URI);
  gBrowser.tabContainer.addEventListener("TabOpen", onTabAdded);

  await ui.editors[0].getSourceEditor();
  info("first editor selected");

  await waitFor(
    () => ui.editors[0].sourceEditor.hasFocus(),
    "Wait until the initially selected editor grabs the focus"
  );

  info("Left-clicking on the second editor link.");
  await clickOnStyleSheetLink(ui.editors[1], 0);

  info("Waiting for the second editor to be selected.");
  const editor = await ui.once("editor-selected");

  ok(
    editor.sourceEditor.hasFocus(),
    "Left mouse click gave second editor focus."
  );

  // middle mouse click should not open a new tab
  info("Middle clicking on the third editor link.");
  await clickOnStyleSheetLink(ui.editors[2], 1);
});

/**
 * A helper that clicks on style sheet link in the sidebar.
 *
 * @param {StyleSheetEditor} editor
 *        The editor of which link should be clicked.
 * @param {MouseEvent.button} button
 *        The button to click the link with.
 */
async function clickOnStyleSheetLink(editor, button) {
  const window = editor._window;
  const link = editor.summary.querySelector(".stylesheet-name");

  info("Waiting for focus.");
  await SimpleTest.promiseFocus(window);

  info("Pressing button " + button + " on style sheet name link.");
  EventUtils.synthesizeMouseAtCenter(link, { button }, window);
}

function onTabAdded() {
  ok(false, "middle mouse click has opened a new tab");
}

registerCleanupFunction(function () {
  gBrowser.tabContainer.removeEventListener("TabOpen", onTabAdded);
});