Bug 1148893 - Clean up browser_styleeditor_bug_851132_middle_click.js. r=bgrinstead

This commit is contained in:
Sami Jaktholm 2015-04-04 11:44:28 +03:00
Родитель 03a3a5f492
Коммит 3d7d7eb730
1 изменённых файлов: 33 добавлений и 52 удалений

Просмотреть файл

@ -1,75 +1,56 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
///////////////////
//
// Whitelisting this test.
// As part of bug 1077403, the leaking uncaught rejection should be fixed.
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
// 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";
let gUI;
function test() {
waitForExplicitFinish();
addTabAndOpenStyleEditors(4, runTests);
content.location = TESTCASE_URI;
}
let timeoutID;
function runTests(panel) {
gUI = panel.UI;
add_task(function* () {
let { ui } = yield openStyleEditorForURL(TESTCASE_URI);
gBrowser.tabContainer.addEventListener("TabOpen", onTabAdded, false);
gUI.editors[0].getSourceEditor().then(onEditor0Attach);
gUI.editors[1].getSourceEditor().then(onEditor1Attach);
}
function getStylesheetNameLinkFor(aEditor) {
return aEditor.summary.querySelector(".stylesheet-name");
}
function onEditor0Attach(aEditor) {
yield ui.editors[0].getSourceEditor();
info("first editor selected");
waitForFocus(function () {
// left mouse click should focus editor 1
EventUtils.synthesizeMouseAtCenter(
getStylesheetNameLinkFor(gUI.editors[1]),
{button: 0},
gPanelWindow);
}, gPanelWindow);
}
info("Left-clicking on the second editor link.");
yield clickOnStyleSheetLink(ui.editors[1], 0);
function onEditor1Attach(aEditor) {
info("second editor selected");
info("Waiting for the second editor to be selected.");
let editor = yield ui.once("editor-selected");
// Wait for the focus to be set.
executeSoon(function () {
ok(aEditor.sourceEditor.hasFocus(),
"left mouse click has given editor 1 focus");
ok(editor.sourceEditor.hasFocus(),
"Left mouse click gave second editor focus.");
// right mouse click should not open a new tab
EventUtils.synthesizeMouseAtCenter(
getStylesheetNameLinkFor(gUI.editors[2]),
{button: 1},
gPanelWindow);
// middle mouse click should not open a new tab
info("Middle clicking on the third editor link.");
yield clickOnStyleSheetLink(ui.editors[2], 1);
});
setTimeout(finish, 0);
});
/**
* 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");
finish();
}
registerCleanupFunction(function () {
gBrowser.tabContainer.removeEventListener("TabOpen", onTabAdded, false);
gUI = null;
});