summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_bug_851132_middle_click.js
blob: a666156b1e0c88fa9f10ff7aafa1113501ad285f (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
/* 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 styleeditor.xul in a new
// tab (bug 851132).

const TESTCASE_URI = TEST_BASE_HTTP + "four.html";

add_task(function* () {
  let { ui } = yield openStyleEditorForURL(TESTCASE_URI);
  gBrowser.tabContainer.addEventListener("TabOpen", onTabAdded, false);

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

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

  info("Waiting for the second editor to be selected.");
  let editor = yield 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.");
  yield 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.
 */
function* clickOnStyleSheetLink(editor, button) {
  let window = editor._window;
  let link = editor.summary.querySelector(".stylesheet-name");

  info("Waiting for focus.");
  yield 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, false);
});