|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 ignoreAllUncaughtExceptions(); |
|
7 |
|
8 let doc; |
|
9 let nodes; |
|
10 let cursor; |
|
11 let inspector; |
|
12 |
|
13 gBrowser.selectedTab = gBrowser.addTab(); |
|
14 gBrowser.selectedBrowser.addEventListener("load", function onload() { |
|
15 gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
|
16 doc = content.document; |
|
17 waitForFocus(setupInfobarTest, content); |
|
18 }, true); |
|
19 |
|
20 let style = "body{width:100%;height: 100%} div {position: absolute;height: 100px;width: 500px}#bottom {bottom: 0px}#vertical {height: 100%}#farbottom{bottom: -200px}"; |
|
21 let html = "<style>" + style + "</style><div id=vertical></div><div id=top class='class1 class2'></div><div id=bottom></div><div id=farbottom></div>" |
|
22 |
|
23 content.location = "data:text/html," + encodeURIComponent(html); |
|
24 |
|
25 function setupInfobarTest() { |
|
26 nodes = [ |
|
27 {node: doc.querySelector("#top"), position: "bottom", tag: "DIV", id: "#top", classes: ".class1.class2"}, |
|
28 {node: doc.querySelector("#vertical"), position: "overlap", tag: "DIV", id: "#vertical", classes: ""}, |
|
29 {node: doc.querySelector("#bottom"), position: "top", tag: "DIV", id: "#bottom", classes: ""}, |
|
30 {node: doc.querySelector("body"), position: "overlap", tag: "BODY", id: "", classes: ""}, |
|
31 {node: doc.querySelector("#farbottom"), position: "top", tag: "DIV", id: "#farbottom", classes: ""}, |
|
32 ] |
|
33 |
|
34 for (let i = 0; i < nodes.length; i++) { |
|
35 ok(nodes[i].node, "node " + i + " found"); |
|
36 } |
|
37 |
|
38 openInspector(runTests); |
|
39 } |
|
40 |
|
41 function mouseOverContainerToShowHighlighter(node, cb) { |
|
42 let container = getContainerForRawNode(inspector.markup, node); |
|
43 EventUtils.synthesizeMouse(container.tagLine, 2, 2, {type: "mousemove"}, |
|
44 inspector.markup.doc.defaultView); |
|
45 executeSoon(cb); |
|
46 } |
|
47 |
|
48 function runTests(aInspector) { |
|
49 inspector = aInspector; |
|
50 inspector.selection.setNode(content.document.querySelector("body")); |
|
51 inspector.once("inspector-updated", () => { |
|
52 cursor = 0; |
|
53 executeSoon(function() { |
|
54 mouseOverContainerToShowHighlighter(nodes[0].node, nodeSelected); |
|
55 }); |
|
56 }); |
|
57 } |
|
58 |
|
59 function nodeSelected() { |
|
60 executeSoon(function() { |
|
61 performTest(); |
|
62 cursor++; |
|
63 if (cursor >= nodes.length) { |
|
64 finishUp(); |
|
65 } else { |
|
66 let node = nodes[cursor].node; |
|
67 mouseOverContainerToShowHighlighter(node, nodeSelected); |
|
68 } |
|
69 }); |
|
70 } |
|
71 |
|
72 function performTest() { |
|
73 let browser = gBrowser.selectedBrowser; |
|
74 let stack = browser.parentNode; |
|
75 |
|
76 let container = stack.querySelector(".highlighter-nodeinfobar-positioner"); |
|
77 is(container.getAttribute("position"), nodes[cursor].position, "node " + cursor + ": position matches."); |
|
78 |
|
79 let tagNameLabel = stack.querySelector(".highlighter-nodeinfobar-tagname"); |
|
80 is(tagNameLabel.textContent, nodes[cursor].tag, "node " + cursor + ": tagName matches."); |
|
81 |
|
82 let idLabel = stack.querySelector(".highlighter-nodeinfobar-id"); |
|
83 is(idLabel.textContent, nodes[cursor].id, "node " + cursor + ": id matches."); |
|
84 |
|
85 let classesBox = stack.querySelector(".highlighter-nodeinfobar-classes"); |
|
86 is(classesBox.textContent, nodes[cursor].classes, "node " + cursor + ": classes match."); |
|
87 } |
|
88 |
|
89 function finishUp() { |
|
90 doc = nodes = null; |
|
91 gBrowser.removeCurrentTab(); |
|
92 finish(); |
|
93 } |
|
94 } |