browser/devtools/inspector/test/browser_inspector_menu.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4
michael@0 5 function test() {
michael@0 6
michael@0 7 waitForExplicitFinish();
michael@0 8
michael@0 9 let doc;
michael@0 10 let inspector;
michael@0 11
michael@0 12 gBrowser.selectedTab = gBrowser.addTab();
michael@0 13 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 14 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 15 doc = content.document;
michael@0 16 waitForFocus(setupTest, content);
michael@0 17 }, true);
michael@0 18
michael@0 19 content.location = "http://mochi.test:8888/browser/browser/devtools/" +
michael@0 20 "inspector/test/browser_inspector_menu.html";
michael@0 21
michael@0 22 function setupTest() {
michael@0 23 openInspector(runTests);
michael@0 24 }
michael@0 25
michael@0 26 function runTests(aInspector) {
michael@0 27 inspector = aInspector;
michael@0 28 checkDocTypeMenuItems();
michael@0 29 }
michael@0 30
michael@0 31 function checkDocTypeMenuItems() {
michael@0 32 info("Checking context menu entries for doctype node");
michael@0 33 inspector.selection.setNode(doc.doctype);
michael@0 34 inspector.once("inspector-updated", () => {
michael@0 35 let docTypeNode = getMarkupTagNodeContaining("<!DOCTYPE html>");
michael@0 36
michael@0 37 // Right-click doctype tag
michael@0 38 contextMenuClick(docTypeNode);
michael@0 39
michael@0 40 checkDisabled("node-menu-copyinner");
michael@0 41 checkDisabled("node-menu-copyouter");
michael@0 42 checkDisabled("node-menu-copyuniqueselector");
michael@0 43 checkDisabled("node-menu-delete");
michael@0 44
michael@0 45 for (let name of ["hover", "active", "focus"]) {
michael@0 46 checkDisabled("node-menu-pseudo-" + name);
michael@0 47 }
michael@0 48
michael@0 49 checkElementMenuItems();
michael@0 50 });
michael@0 51 }
michael@0 52
michael@0 53 function checkElementMenuItems() {
michael@0 54 info("Checking context menu entries for p tag");
michael@0 55 inspector.selection.setNode(doc.querySelector("p"));
michael@0 56 inspector.once("inspector-updated", () => {
michael@0 57 let tag = getMarkupTagNodeContaining("p");
michael@0 58
michael@0 59 // Right-click p tag
michael@0 60 contextMenuClick(tag);
michael@0 61
michael@0 62 checkEnabled("node-menu-copyinner");
michael@0 63 checkEnabled("node-menu-copyouter");
michael@0 64 checkEnabled("node-menu-copyuniqueselector");
michael@0 65 checkEnabled("node-menu-delete");
michael@0 66
michael@0 67 for (let name of ["hover", "active", "focus"]) {
michael@0 68 checkEnabled("node-menu-pseudo-" + name);
michael@0 69 }
michael@0 70
michael@0 71 testCopyInnerMenu();
michael@0 72 });
michael@0 73 }
michael@0 74
michael@0 75 function testCopyInnerMenu() {
michael@0 76 let copyInner = inspector.panelDoc.getElementById("node-menu-copyinner");
michael@0 77 ok(copyInner, "the popup menu has a copy inner html menu item");
michael@0 78
michael@0 79 waitForClipboard("This is some example text",
michael@0 80 function() { copyInner.doCommand(); },
michael@0 81 testCopyOuterMenu, testCopyOuterMenu);
michael@0 82 }
michael@0 83
michael@0 84 function testCopyOuterMenu() {
michael@0 85 let copyOuter = inspector.panelDoc.getElementById("node-menu-copyouter");
michael@0 86 ok(copyOuter, "the popup menu has a copy outer html menu item");
michael@0 87
michael@0 88 waitForClipboard("<p>This is some example text</p>",
michael@0 89 function() { copyOuter.doCommand(); },
michael@0 90 testCopyUniqueSelectorMenu, testCopyUniqueSelectorMenu);
michael@0 91 }
michael@0 92
michael@0 93 function testCopyUniqueSelectorMenu() {
michael@0 94 let copyUniqueSelector = inspector.panelDoc.getElementById("node-menu-copyuniqueselector");
michael@0 95 ok(copyUniqueSelector, "the popup menu has a copy unique selector menu item");
michael@0 96
michael@0 97 waitForClipboard("body > div:nth-child(1) > p:nth-child(2)",
michael@0 98 function() { copyUniqueSelector.doCommand(); },
michael@0 99 testDeleteNode, testDeleteNode);
michael@0 100 }
michael@0 101
michael@0 102 function testDeleteNode() {
michael@0 103 let deleteNode = inspector.panelDoc.getElementById("node-menu-delete");
michael@0 104 ok(deleteNode, "the popup menu has a delete menu item");
michael@0 105
michael@0 106 inspector.once("inspector-updated", deleteTest);
michael@0 107
michael@0 108 let commandEvent = document.createEvent("XULCommandEvent");
michael@0 109 commandEvent.initCommandEvent("command", true, true, window, 0, false, false,
michael@0 110 false, false, null);
michael@0 111 deleteNode.dispatchEvent(commandEvent);
michael@0 112 }
michael@0 113
michael@0 114 function deleteTest() {
michael@0 115 let p = doc.querySelector("P");
michael@0 116 is(p, null, "node deleted");
michael@0 117
michael@0 118 deleteRootNode();
michael@0 119 }
michael@0 120
michael@0 121 function deleteRootNode() {
michael@0 122 inspector.selection.setNode(doc.documentElement);
michael@0 123
michael@0 124 inspector.once("inspector-updated", () => {
michael@0 125 let deleteNode = inspector.panelDoc.getElementById("node-menu-delete");
michael@0 126 let commandEvent = inspector.panelDoc.createEvent("XULCommandEvent");
michael@0 127 commandEvent.initCommandEvent("command", true, true, window, 0, false, false,
michael@0 128 false, false, null);
michael@0 129 deleteNode.dispatchEvent(commandEvent);
michael@0 130 executeSoon(isRootStillAlive);
michael@0 131 });
michael@0 132 }
michael@0 133
michael@0 134 function isRootStillAlive() {
michael@0 135 ok(doc.documentElement, "Document element still alive.");
michael@0 136 gBrowser.removeCurrentTab();
michael@0 137 finish();
michael@0 138 }
michael@0 139
michael@0 140 function getMarkupTagNodeContaining(text) {
michael@0 141 let tags = inspector._markupFrame.contentDocument.querySelectorAll("span");
michael@0 142 for (let tag of tags) {
michael@0 143 if (tag.textContent == text) {
michael@0 144 return tag;
michael@0 145 }
michael@0 146 }
michael@0 147 }
michael@0 148
michael@0 149 function checkEnabled(elementId) {
michael@0 150 let elt = inspector.panelDoc.getElementById(elementId);
michael@0 151 ok(!elt.hasAttribute("disabled"),
michael@0 152 '"' + elt.label + '" context menu option is not disabled');
michael@0 153 }
michael@0 154
michael@0 155 function checkDisabled(elementId) {
michael@0 156 let elt = inspector.panelDoc.getElementById(elementId);
michael@0 157 ok(elt.hasAttribute("disabled"),
michael@0 158 '"' + elt.label + '" context menu option is disabled');
michael@0 159 }
michael@0 160
michael@0 161 function contextMenuClick(element) {
michael@0 162 let evt = element.ownerDocument.createEvent('MouseEvents');
michael@0 163 let button = 2; // right click
michael@0 164
michael@0 165 evt.initMouseEvent('contextmenu', true, true,
michael@0 166 element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
michael@0 167 false, false, false, button, null);
michael@0 168
michael@0 169 element.dispatchEvent(evt);
michael@0 170 }
michael@0 171 }

mercurial