michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: michael@0: function test() { michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: let doc; michael@0: let inspector; michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true); michael@0: doc = content.document; michael@0: waitForFocus(setupTest, content); michael@0: }, true); michael@0: michael@0: content.location = "http://mochi.test:8888/browser/browser/devtools/" + michael@0: "inspector/test/browser_inspector_menu.html"; michael@0: michael@0: function setupTest() { michael@0: openInspector(runTests); michael@0: } michael@0: michael@0: function runTests(aInspector) { michael@0: inspector = aInspector; michael@0: checkDocTypeMenuItems(); michael@0: } michael@0: michael@0: function checkDocTypeMenuItems() { michael@0: info("Checking context menu entries for doctype node"); michael@0: inspector.selection.setNode(doc.doctype); michael@0: inspector.once("inspector-updated", () => { michael@0: let docTypeNode = getMarkupTagNodeContaining(""); michael@0: michael@0: // Right-click doctype tag michael@0: contextMenuClick(docTypeNode); michael@0: michael@0: checkDisabled("node-menu-copyinner"); michael@0: checkDisabled("node-menu-copyouter"); michael@0: checkDisabled("node-menu-copyuniqueselector"); michael@0: checkDisabled("node-menu-delete"); michael@0: michael@0: for (let name of ["hover", "active", "focus"]) { michael@0: checkDisabled("node-menu-pseudo-" + name); michael@0: } michael@0: michael@0: checkElementMenuItems(); michael@0: }); michael@0: } michael@0: michael@0: function checkElementMenuItems() { michael@0: info("Checking context menu entries for p tag"); michael@0: inspector.selection.setNode(doc.querySelector("p")); michael@0: inspector.once("inspector-updated", () => { michael@0: let tag = getMarkupTagNodeContaining("p"); michael@0: michael@0: // Right-click p tag michael@0: contextMenuClick(tag); michael@0: michael@0: checkEnabled("node-menu-copyinner"); michael@0: checkEnabled("node-menu-copyouter"); michael@0: checkEnabled("node-menu-copyuniqueselector"); michael@0: checkEnabled("node-menu-delete"); michael@0: michael@0: for (let name of ["hover", "active", "focus"]) { michael@0: checkEnabled("node-menu-pseudo-" + name); michael@0: } michael@0: michael@0: testCopyInnerMenu(); michael@0: }); michael@0: } michael@0: michael@0: function testCopyInnerMenu() { michael@0: let copyInner = inspector.panelDoc.getElementById("node-menu-copyinner"); michael@0: ok(copyInner, "the popup menu has a copy inner html menu item"); michael@0: michael@0: waitForClipboard("This is some example text", michael@0: function() { copyInner.doCommand(); }, michael@0: testCopyOuterMenu, testCopyOuterMenu); michael@0: } michael@0: michael@0: function testCopyOuterMenu() { michael@0: let copyOuter = inspector.panelDoc.getElementById("node-menu-copyouter"); michael@0: ok(copyOuter, "the popup menu has a copy outer html menu item"); michael@0: michael@0: waitForClipboard("

This is some example text

", michael@0: function() { copyOuter.doCommand(); }, michael@0: testCopyUniqueSelectorMenu, testCopyUniqueSelectorMenu); michael@0: } michael@0: michael@0: function testCopyUniqueSelectorMenu() { michael@0: let copyUniqueSelector = inspector.panelDoc.getElementById("node-menu-copyuniqueselector"); michael@0: ok(copyUniqueSelector, "the popup menu has a copy unique selector menu item"); michael@0: michael@0: waitForClipboard("body > div:nth-child(1) > p:nth-child(2)", michael@0: function() { copyUniqueSelector.doCommand(); }, michael@0: testDeleteNode, testDeleteNode); michael@0: } michael@0: michael@0: function testDeleteNode() { michael@0: let deleteNode = inspector.panelDoc.getElementById("node-menu-delete"); michael@0: ok(deleteNode, "the popup menu has a delete menu item"); michael@0: michael@0: inspector.once("inspector-updated", deleteTest); michael@0: michael@0: let commandEvent = document.createEvent("XULCommandEvent"); michael@0: commandEvent.initCommandEvent("command", true, true, window, 0, false, false, michael@0: false, false, null); michael@0: deleteNode.dispatchEvent(commandEvent); michael@0: } michael@0: michael@0: function deleteTest() { michael@0: let p = doc.querySelector("P"); michael@0: is(p, null, "node deleted"); michael@0: michael@0: deleteRootNode(); michael@0: } michael@0: michael@0: function deleteRootNode() { michael@0: inspector.selection.setNode(doc.documentElement); michael@0: michael@0: inspector.once("inspector-updated", () => { michael@0: let deleteNode = inspector.panelDoc.getElementById("node-menu-delete"); michael@0: let commandEvent = inspector.panelDoc.createEvent("XULCommandEvent"); michael@0: commandEvent.initCommandEvent("command", true, true, window, 0, false, false, michael@0: false, false, null); michael@0: deleteNode.dispatchEvent(commandEvent); michael@0: executeSoon(isRootStillAlive); michael@0: }); michael@0: } michael@0: michael@0: function isRootStillAlive() { michael@0: ok(doc.documentElement, "Document element still alive."); michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: michael@0: function getMarkupTagNodeContaining(text) { michael@0: let tags = inspector._markupFrame.contentDocument.querySelectorAll("span"); michael@0: for (let tag of tags) { michael@0: if (tag.textContent == text) { michael@0: return tag; michael@0: } michael@0: } michael@0: } michael@0: michael@0: function checkEnabled(elementId) { michael@0: let elt = inspector.panelDoc.getElementById(elementId); michael@0: ok(!elt.hasAttribute("disabled"), michael@0: '"' + elt.label + '" context menu option is not disabled'); michael@0: } michael@0: michael@0: function checkDisabled(elementId) { michael@0: let elt = inspector.panelDoc.getElementById(elementId); michael@0: ok(elt.hasAttribute("disabled"), michael@0: '"' + elt.label + '" context menu option is disabled'); michael@0: } michael@0: michael@0: function contextMenuClick(element) { michael@0: let evt = element.ownerDocument.createEvent('MouseEvents'); michael@0: let button = 2; // right click michael@0: michael@0: evt.initMouseEvent('contextmenu', true, true, michael@0: element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, michael@0: false, false, false, button, null); michael@0: michael@0: element.dispatchEvent(evt); michael@0: } michael@0: }