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/. */
6 let doc;
7 let salutation;
9 function createDocument()
10 {
11 doc.body.innerHTML = '<div id="first" style="{ margin: 10em; ' +
12 'font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA}">\n' +
13 '<h1>Some header text</h1>\n' +
14 '<p id="salutation" style="{font-size: 12pt}">hi.</p>\n' +
15 '<p id="body" style="{font-size: 12pt}">I am a test-case. This text exists ' +
16 'solely to provide some things to test the inspector initialization.</p>\n' +
17 'If you are reading this, you should go do something else instead. Maybe ' +
18 'read a book. Or better yet, write some test-cases for another bit of code. ' +
19 '<span style="{font-style: italic}">Inspector\'s!</span></p>\n' +
20 '<p id="closing">end transmission</p>\n' +
21 '</div>';
22 doc.title = "Inspector Initialization Test";
24 let target = TargetFactory.forTab(gBrowser.selectedTab);
25 gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
26 startInspectorTests(toolbox);
27 }).then(null, console.error);
28 }
30 function startInspectorTests(toolbox)
31 {
32 let inspector = toolbox.getCurrentPanel();
33 ok(true, "Inspector started, and notification received.");
35 ok(inspector, "Inspector instance is accessible");
36 ok(inspector.isReady, "Inspector instance is ready");
37 is(inspector.target.tab, gBrowser.selectedTab, "Valid target");
39 let p = doc.querySelector("p");
41 inspector.selection.setNode(p);
42 inspector.once("inspector-updated", () => {
43 testMarkupView(p);
44 testBreadcrumbs(p);
46 let span = doc.querySelector("span");
47 span.scrollIntoView();
49 inspector.selection.setNode(span);
50 inspector.once("inspector-updated", () => {
51 testMarkupView(span);
52 testBreadcrumbs(span);
54 toolbox.once("destroyed", function() {
55 ok("true", "'destroyed' notification received.");
56 let target = TargetFactory.forTab(gBrowser.selectedTab);
57 ok(!gDevTools.getToolbox(target), "Toolbox destroyed.");
58 executeSoon(runContextMenuTest);
59 });
60 toolbox.destroy();
61 });
62 });
63 }
65 let callNo = 0;
66 function testMarkupView(node)
67 {
68 let i = getActiveInspector();
69 try {
70 is(i.markup._selectedContainer.node.rawNode(), node, "Right node is selected in the markup view");
71 } catch(ex) { console.error(ex); }
72 }
74 function testBreadcrumbs(node)
75 {
76 let b = getActiveInspector().breadcrumbs;
77 let expectedText = b.prettyPrintNodeAsText(getNodeFront(node));
78 let button = b.container.querySelector("button[checked=true]");
79 ok(button, "A crumbs is checked=true");
80 is(button.getAttribute("tooltiptext"), expectedText, "Crumb refers to the right node");
81 }
83 function _clickOnInspectMenuItem(node) {
84 document.popupNode = node;
85 var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
86 var contextMenu = new nsContextMenu(contentAreaContextMenu);
87 var {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
88 var deferred = promise.defer();
89 contextMenu.inspectNode().then(() => {
90 let i = getActiveInspector();
91 i.once("inspector-updated", () => {
92 deferred.resolve(undefined);
93 });
94 });
95 return deferred.promise;
96 }
98 function runContextMenuTest()
99 {
100 salutation = doc.getElementById("salutation");
101 _clickOnInspectMenuItem(salutation).then(testInitialNodeIsSelected);
102 }
104 function testInitialNodeIsSelected() {
105 testMarkupView(salutation);
106 testBreadcrumbs(salutation);
107 inspectNodesFromContextTestWhileOpen();
108 }
110 function inspectNodesFromContextTestWhileOpen()
111 {
112 let closing = doc.getElementById("closing");
113 getActiveInspector().selection.once("new-node", function() {
114 ok(true, "Get selection's 'new-node' selection");
115 executeSoon(function() {
116 testMarkupView(closing);
117 testBreadcrumbs(closing);
118 getActiveInspector().once("inspector-updated", finishInspectorTests)
119 }
120 )});
121 _clickOnInspectMenuItem(closing);
122 }
124 function finishInspectorTests(subject, topic, aWinIdString)
125 {
126 gBrowser.removeCurrentTab();
127 finish();
128 }
130 function test()
131 {
132 waitForExplicitFinish();
133 gBrowser.selectedTab = gBrowser.addTab();
134 gBrowser.selectedBrowser.addEventListener("load", function() {
135 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
136 doc = content.document;
137 waitForFocus(createDocument, content);
138 }, true);
140 content.location = "data:text/html;charset=utf-8,browser_inspector_initialization.js";
141 }