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