1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/inspector/test/browser_inspector_initialization.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,141 @@ 1.4 +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +let doc; 1.10 +let salutation; 1.11 + 1.12 +function createDocument() 1.13 +{ 1.14 + doc.body.innerHTML = '<div id="first" style="{ margin: 10em; ' + 1.15 + 'font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA}">\n' + 1.16 + '<h1>Some header text</h1>\n' + 1.17 + '<p id="salutation" style="{font-size: 12pt}">hi.</p>\n' + 1.18 + '<p id="body" style="{font-size: 12pt}">I am a test-case. This text exists ' + 1.19 + 'solely to provide some things to test the inspector initialization.</p>\n' + 1.20 + 'If you are reading this, you should go do something else instead. Maybe ' + 1.21 + 'read a book. Or better yet, write some test-cases for another bit of code. ' + 1.22 + '<span style="{font-style: italic}">Inspector\'s!</span></p>\n' + 1.23 + '<p id="closing">end transmission</p>\n' + 1.24 + '</div>'; 1.25 + doc.title = "Inspector Initialization Test"; 1.26 + 1.27 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.28 + gDevTools.showToolbox(target, "inspector").then(function(toolbox) { 1.29 + startInspectorTests(toolbox); 1.30 + }).then(null, console.error); 1.31 +} 1.32 + 1.33 +function startInspectorTests(toolbox) 1.34 +{ 1.35 + let inspector = toolbox.getCurrentPanel(); 1.36 + ok(true, "Inspector started, and notification received."); 1.37 + 1.38 + ok(inspector, "Inspector instance is accessible"); 1.39 + ok(inspector.isReady, "Inspector instance is ready"); 1.40 + is(inspector.target.tab, gBrowser.selectedTab, "Valid target"); 1.41 + 1.42 + let p = doc.querySelector("p"); 1.43 + 1.44 + inspector.selection.setNode(p); 1.45 + inspector.once("inspector-updated", () => { 1.46 + testMarkupView(p); 1.47 + testBreadcrumbs(p); 1.48 + 1.49 + let span = doc.querySelector("span"); 1.50 + span.scrollIntoView(); 1.51 + 1.52 + inspector.selection.setNode(span); 1.53 + inspector.once("inspector-updated", () => { 1.54 + testMarkupView(span); 1.55 + testBreadcrumbs(span); 1.56 + 1.57 + toolbox.once("destroyed", function() { 1.58 + ok("true", "'destroyed' notification received."); 1.59 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.60 + ok(!gDevTools.getToolbox(target), "Toolbox destroyed."); 1.61 + executeSoon(runContextMenuTest); 1.62 + }); 1.63 + toolbox.destroy(); 1.64 + }); 1.65 + }); 1.66 +} 1.67 + 1.68 +let callNo = 0; 1.69 +function testMarkupView(node) 1.70 +{ 1.71 + let i = getActiveInspector(); 1.72 + try { 1.73 + is(i.markup._selectedContainer.node.rawNode(), node, "Right node is selected in the markup view"); 1.74 + } catch(ex) { console.error(ex); } 1.75 +} 1.76 + 1.77 +function testBreadcrumbs(node) 1.78 +{ 1.79 + let b = getActiveInspector().breadcrumbs; 1.80 + let expectedText = b.prettyPrintNodeAsText(getNodeFront(node)); 1.81 + let button = b.container.querySelector("button[checked=true]"); 1.82 + ok(button, "A crumbs is checked=true"); 1.83 + is(button.getAttribute("tooltiptext"), expectedText, "Crumb refers to the right node"); 1.84 +} 1.85 + 1.86 +function _clickOnInspectMenuItem(node) { 1.87 + document.popupNode = node; 1.88 + var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); 1.89 + var contextMenu = new nsContextMenu(contentAreaContextMenu); 1.90 + var {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); 1.91 + var deferred = promise.defer(); 1.92 + contextMenu.inspectNode().then(() => { 1.93 + let i = getActiveInspector(); 1.94 + i.once("inspector-updated", () => { 1.95 + deferred.resolve(undefined); 1.96 + }); 1.97 + }); 1.98 + return deferred.promise; 1.99 +} 1.100 + 1.101 +function runContextMenuTest() 1.102 +{ 1.103 + salutation = doc.getElementById("salutation"); 1.104 + _clickOnInspectMenuItem(salutation).then(testInitialNodeIsSelected); 1.105 +} 1.106 + 1.107 +function testInitialNodeIsSelected() { 1.108 + testMarkupView(salutation); 1.109 + testBreadcrumbs(salutation); 1.110 + inspectNodesFromContextTestWhileOpen(); 1.111 +} 1.112 + 1.113 +function inspectNodesFromContextTestWhileOpen() 1.114 +{ 1.115 + let closing = doc.getElementById("closing"); 1.116 + getActiveInspector().selection.once("new-node", function() { 1.117 + ok(true, "Get selection's 'new-node' selection"); 1.118 + executeSoon(function() { 1.119 + testMarkupView(closing); 1.120 + testBreadcrumbs(closing); 1.121 + getActiveInspector().once("inspector-updated", finishInspectorTests) 1.122 + } 1.123 + )}); 1.124 + _clickOnInspectMenuItem(closing); 1.125 +} 1.126 + 1.127 +function finishInspectorTests(subject, topic, aWinIdString) 1.128 +{ 1.129 + gBrowser.removeCurrentTab(); 1.130 + finish(); 1.131 +} 1.132 + 1.133 +function test() 1.134 +{ 1.135 + waitForExplicitFinish(); 1.136 + gBrowser.selectedTab = gBrowser.addTab(); 1.137 + gBrowser.selectedBrowser.addEventListener("load", function() { 1.138 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.139 + doc = content.document; 1.140 + waitForFocus(createDocument, content); 1.141 + }, true); 1.142 + 1.143 + content.location = "data:text/html;charset=utf-8,browser_inspector_initialization.js"; 1.144 +}