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