|
1 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 let doc; |
|
8 let div1; |
|
9 let div2; |
|
10 let iframe1; |
|
11 let iframe2; |
|
12 let inspector; |
|
13 |
|
14 function createDocument() { |
|
15 doc.title = "Inspector iframe Tests"; |
|
16 |
|
17 iframe1 = doc.createElement('iframe'); |
|
18 |
|
19 iframe1.addEventListener("load", function () { |
|
20 iframe1.removeEventListener("load", arguments.callee, false); |
|
21 |
|
22 div1 = iframe1.contentDocument.createElement('div'); |
|
23 div1.textContent = 'little div'; |
|
24 iframe1.contentDocument.body.appendChild(div1); |
|
25 |
|
26 iframe2 = iframe1.contentDocument.createElement('iframe'); |
|
27 |
|
28 iframe2.addEventListener('load', function () { |
|
29 iframe2.removeEventListener("load", arguments.callee, false); |
|
30 |
|
31 div2 = iframe2.contentDocument.createElement('div'); |
|
32 div2.textContent = 'nested div'; |
|
33 iframe2.contentDocument.body.appendChild(div2); |
|
34 |
|
35 // Open the inspector, start the picker mode, and start the tests |
|
36 openInspector(aInspector => { |
|
37 inspector = aInspector; |
|
38 inspector.toolbox.highlighterUtils.startPicker().then(runTests); |
|
39 }); |
|
40 }, false); |
|
41 |
|
42 iframe2.src = 'data:text/html,nested iframe'; |
|
43 iframe1.contentDocument.body.appendChild(iframe2); |
|
44 }, false); |
|
45 |
|
46 iframe1.src = 'data:text/html,little iframe'; |
|
47 doc.body.appendChild(iframe1); |
|
48 } |
|
49 |
|
50 function moveMouseOver(aElement, cb) { |
|
51 inspector.toolbox.once("picker-node-hovered", cb); |
|
52 EventUtils.synthesizeMouseAtCenter(aElement, {type: "mousemove"}, |
|
53 aElement.ownerDocument.defaultView); |
|
54 } |
|
55 |
|
56 function runTests() { |
|
57 testDiv1Highlighter(); |
|
58 } |
|
59 |
|
60 function testDiv1Highlighter() { |
|
61 moveMouseOver(div1, () => { |
|
62 is(getHighlitNode(), div1, "highlighter matches selection of div1"); |
|
63 testDiv2Highlighter(); |
|
64 }); |
|
65 } |
|
66 |
|
67 function testDiv2Highlighter() { |
|
68 moveMouseOver(div2, () => { |
|
69 is(getHighlitNode(), div2, "highlighter matches selection of div2"); |
|
70 selectRoot(); |
|
71 }); |
|
72 } |
|
73 |
|
74 function selectRoot() { |
|
75 // Select the root document element to clear the breadcrumbs. |
|
76 inspector.selection.setNode(doc.documentElement, null); |
|
77 inspector.once("inspector-updated", selectIframe); |
|
78 } |
|
79 |
|
80 function selectIframe() { |
|
81 // Directly select an element in an iframe (without navigating to it |
|
82 // with mousemoves). |
|
83 inspector.selection.setNode(div2, null); |
|
84 inspector.once("inspector-updated", () => { |
|
85 let breadcrumbs = inspector.breadcrumbs; |
|
86 is(breadcrumbs.nodeHierarchy.length, 9, "Should have 9 items"); |
|
87 finishUp(); |
|
88 }); |
|
89 } |
|
90 |
|
91 function finishUp() { |
|
92 inspector.toolbox.highlighterUtils.stopPicker().then(() => { |
|
93 doc = div1 = div2 = iframe1 = iframe2 = inspector = null; |
|
94 let target = TargetFactory.forTab(gBrowser.selectedTab); |
|
95 gDevTools.closeToolbox(target); |
|
96 gBrowser.removeCurrentTab(); |
|
97 finish(); |
|
98 }); |
|
99 } |
|
100 |
|
101 function test() { |
|
102 waitForExplicitFinish(); |
|
103 |
|
104 gBrowser.selectedTab = gBrowser.addTab(); |
|
105 gBrowser.selectedBrowser.addEventListener("load", function() { |
|
106 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
|
107 doc = content.document; |
|
108 gBrowser.selectedBrowser.focus(); |
|
109 createDocument(); |
|
110 }, true); |
|
111 |
|
112 content.location = "data:text/html,iframe tests for inspector"; |
|
113 } |