michael@0: /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0: /* vim: set ts=2 et sw=2 tw=80: */
michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0: let doc;
michael@0: let salutation;
michael@0:
michael@0: function createDocument()
michael@0: {
michael@0: doc.body.innerHTML = '
\n' +
michael@0: '
Some header text
\n' +
michael@0: '
hi.
\n' +
michael@0: '
I am a test-case. This text exists ' +
michael@0: 'solely to provide some things to test the inspector initialization.
\n' +
michael@0: 'If you are reading this, you should go do something else instead. Maybe ' +
michael@0: 'read a book. Or better yet, write some test-cases for another bit of code. ' +
michael@0: '
Inspector\'s!\n' +
michael@0: '
end transmission
\n' +
michael@0: '
';
michael@0: doc.title = "Inspector Initialization Test";
michael@0:
michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0: gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
michael@0: startInspectorTests(toolbox);
michael@0: }).then(null, console.error);
michael@0: }
michael@0:
michael@0: function startInspectorTests(toolbox)
michael@0: {
michael@0: let inspector = toolbox.getCurrentPanel();
michael@0: ok(true, "Inspector started, and notification received.");
michael@0:
michael@0: ok(inspector, "Inspector instance is accessible");
michael@0: ok(inspector.isReady, "Inspector instance is ready");
michael@0: is(inspector.target.tab, gBrowser.selectedTab, "Valid target");
michael@0:
michael@0: let p = doc.querySelector("p");
michael@0:
michael@0: inspector.selection.setNode(p);
michael@0: inspector.once("inspector-updated", () => {
michael@0: testMarkupView(p);
michael@0: testBreadcrumbs(p);
michael@0:
michael@0: let span = doc.querySelector("span");
michael@0: span.scrollIntoView();
michael@0:
michael@0: inspector.selection.setNode(span);
michael@0: inspector.once("inspector-updated", () => {
michael@0: testMarkupView(span);
michael@0: testBreadcrumbs(span);
michael@0:
michael@0: toolbox.once("destroyed", function() {
michael@0: ok("true", "'destroyed' notification received.");
michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0: ok(!gDevTools.getToolbox(target), "Toolbox destroyed.");
michael@0: executeSoon(runContextMenuTest);
michael@0: });
michael@0: toolbox.destroy();
michael@0: });
michael@0: });
michael@0: }
michael@0:
michael@0: let callNo = 0;
michael@0: function testMarkupView(node)
michael@0: {
michael@0: let i = getActiveInspector();
michael@0: try {
michael@0: is(i.markup._selectedContainer.node.rawNode(), node, "Right node is selected in the markup view");
michael@0: } catch(ex) { console.error(ex); }
michael@0: }
michael@0:
michael@0: function testBreadcrumbs(node)
michael@0: {
michael@0: let b = getActiveInspector().breadcrumbs;
michael@0: let expectedText = b.prettyPrintNodeAsText(getNodeFront(node));
michael@0: let button = b.container.querySelector("button[checked=true]");
michael@0: ok(button, "A crumbs is checked=true");
michael@0: is(button.getAttribute("tooltiptext"), expectedText, "Crumb refers to the right node");
michael@0: }
michael@0:
michael@0: function _clickOnInspectMenuItem(node) {
michael@0: document.popupNode = node;
michael@0: var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
michael@0: var contextMenu = new nsContextMenu(contentAreaContextMenu);
michael@0: var {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
michael@0: var deferred = promise.defer();
michael@0: contextMenu.inspectNode().then(() => {
michael@0: let i = getActiveInspector();
michael@0: i.once("inspector-updated", () => {
michael@0: deferred.resolve(undefined);
michael@0: });
michael@0: });
michael@0: return deferred.promise;
michael@0: }
michael@0:
michael@0: function runContextMenuTest()
michael@0: {
michael@0: salutation = doc.getElementById("salutation");
michael@0: _clickOnInspectMenuItem(salutation).then(testInitialNodeIsSelected);
michael@0: }
michael@0:
michael@0: function testInitialNodeIsSelected() {
michael@0: testMarkupView(salutation);
michael@0: testBreadcrumbs(salutation);
michael@0: inspectNodesFromContextTestWhileOpen();
michael@0: }
michael@0:
michael@0: function inspectNodesFromContextTestWhileOpen()
michael@0: {
michael@0: let closing = doc.getElementById("closing");
michael@0: getActiveInspector().selection.once("new-node", function() {
michael@0: ok(true, "Get selection's 'new-node' selection");
michael@0: executeSoon(function() {
michael@0: testMarkupView(closing);
michael@0: testBreadcrumbs(closing);
michael@0: getActiveInspector().once("inspector-updated", finishInspectorTests)
michael@0: }
michael@0: )});
michael@0: _clickOnInspectMenuItem(closing);
michael@0: }
michael@0:
michael@0: function finishInspectorTests(subject, topic, aWinIdString)
michael@0: {
michael@0: gBrowser.removeCurrentTab();
michael@0: finish();
michael@0: }
michael@0:
michael@0: function test()
michael@0: {
michael@0: waitForExplicitFinish();
michael@0: gBrowser.selectedTab = gBrowser.addTab();
michael@0: gBrowser.selectedBrowser.addEventListener("load", function() {
michael@0: gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0: doc = content.document;
michael@0: waitForFocus(createDocument, content);
michael@0: }, true);
michael@0:
michael@0: content.location = "data:text/html;charset=utf-8,browser_inspector_initialization.js";
michael@0: }