Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 let doc;
8 let div1;
9 let div2;
10 let iframe1;
11 let iframe2;
12 let inspector;
14 function createDocument() {
15 doc.title = "Inspector iframe Tests";
17 iframe1 = doc.createElement('iframe');
19 iframe1.addEventListener("load", function () {
20 iframe1.removeEventListener("load", arguments.callee, false);
22 div1 = iframe1.contentDocument.createElement('div');
23 div1.textContent = 'little div';
24 iframe1.contentDocument.body.appendChild(div1);
26 iframe2 = iframe1.contentDocument.createElement('iframe');
28 iframe2.addEventListener('load', function () {
29 iframe2.removeEventListener("load", arguments.callee, false);
31 div2 = iframe2.contentDocument.createElement('div');
32 div2.textContent = 'nested div';
33 iframe2.contentDocument.body.appendChild(div2);
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);
42 iframe2.src = 'data:text/html,nested iframe';
43 iframe1.contentDocument.body.appendChild(iframe2);
44 }, false);
46 iframe1.src = 'data:text/html,little iframe';
47 doc.body.appendChild(iframe1);
48 }
50 function moveMouseOver(aElement, cb) {
51 inspector.toolbox.once("picker-node-hovered", cb);
52 EventUtils.synthesizeMouseAtCenter(aElement, {type: "mousemove"},
53 aElement.ownerDocument.defaultView);
54 }
56 function runTests() {
57 testDiv1Highlighter();
58 }
60 function testDiv1Highlighter() {
61 moveMouseOver(div1, () => {
62 is(getHighlitNode(), div1, "highlighter matches selection of div1");
63 testDiv2Highlighter();
64 });
65 }
67 function testDiv2Highlighter() {
68 moveMouseOver(div2, () => {
69 is(getHighlitNode(), div2, "highlighter matches selection of div2");
70 selectRoot();
71 });
72 }
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 }
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 }
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 }
101 function test() {
102 waitForExplicitFinish();
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);
112 content.location = "data:text/html,iframe tests for inspector";
113 }