browser/devtools/inspector/test/browser_inspector_breadcrumbs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 function test()
michael@0 5 {
michael@0 6 waitForExplicitFinish();
michael@0 7 ignoreAllUncaughtExceptions();
michael@0 8
michael@0 9 let nodes = [
michael@0 10 {nodeId: "i1111", result: "i1 i11 i111 i1111"},
michael@0 11 {nodeId: "i22", result: "i2 i22 i221"},
michael@0 12 {nodeId: "i2111", result: "i2 i21 i211 i2111"},
michael@0 13 {nodeId: "i21", result: "i2 i21 i211 i2111"},
michael@0 14 {nodeId: "i22211", result: "i2 i22 i222 i2221 i22211"},
michael@0 15 {nodeId: "i22", result: "i2 i22 i222 i2221 i22211"},
michael@0 16 ];
michael@0 17
michael@0 18 let doc;
michael@0 19 let nodes;
michael@0 20 let cursor;
michael@0 21 let inspector;
michael@0 22 let target;
michael@0 23 let panel;
michael@0 24 let container;
michael@0 25
michael@0 26 gBrowser.selectedTab = gBrowser.addTab();
michael@0 27 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 28 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 29 doc = content.document;
michael@0 30 waitForFocus(setupTest, content);
michael@0 31 }, true);
michael@0 32
michael@0 33 content.location = "http://mochi.test:8888/browser/browser/devtools/inspector/test/browser_inspector_breadcrumbs.html";
michael@0 34
michael@0 35 function setupTest()
michael@0 36 {
michael@0 37 for (let i = 0; i < nodes.length; i++) {
michael@0 38 let node = doc.getElementById(nodes[i].nodeId);
michael@0 39 nodes[i].node = node;
michael@0 40 ok(nodes[i].node, "node " + nodes[i].nodeId + " found");
michael@0 41 }
michael@0 42
michael@0 43 openInspector(runTests);
michael@0 44 }
michael@0 45
michael@0 46 function runTests(aInspector)
michael@0 47 {
michael@0 48 inspector = aInspector;
michael@0 49 target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 50 panel = gDevTools.getToolbox(target).getPanel("inspector");
michael@0 51 container = panel.panelDoc.getElementById("inspector-breadcrumbs");
michael@0 52 cursor = 0;
michael@0 53 inspector.on("breadcrumbs-updated", nodeSelected);
michael@0 54 executeSoon(function() {
michael@0 55 inspector.selection.setNode(nodes[0].node);
michael@0 56 });
michael@0 57 }
michael@0 58
michael@0 59 function nodeSelected()
michael@0 60 {
michael@0 61 performTest();
michael@0 62 cursor++;
michael@0 63
michael@0 64 if (cursor >= nodes.length) {
michael@0 65 inspector.off("breadcrumbs-updated", nodeSelected);
michael@0 66 // breadcrumbs-updated is an event that is fired before the rest of the
michael@0 67 // inspector is updated, so there'll be hanging connections if we finish
michael@0 68 // up before waiting for everything to end.
michael@0 69 inspector.once("inspector-updated", finishUp);
michael@0 70 } else {
michael@0 71 let node = nodes[cursor].node;
michael@0 72 inspector.selection.setNode(node);
michael@0 73 }
michael@0 74 }
michael@0 75
michael@0 76 function performTest()
michael@0 77 {
michael@0 78 let buttonsLabelIds = nodes[cursor].result.split(" ");
michael@0 79
michael@0 80 // html > body > …
michael@0 81 is(container.childNodes.length, buttonsLabelIds.length + 2, "Node " + cursor + ": Items count");
michael@0 82
michael@0 83 for (let i = 2; i < container.childNodes.length; i++) {
michael@0 84 let expectedId = "#" + buttonsLabelIds[i - 2];
michael@0 85 let button = container.childNodes[i];
michael@0 86 let labelId = button.querySelector(".breadcrumbs-widget-item-id");
michael@0 87 is(labelId.textContent, expectedId, "Node " + cursor + ": button " + i + " matches");
michael@0 88 }
michael@0 89
michael@0 90 let checkedButton = container.querySelector("button[checked]");
michael@0 91 let labelId = checkedButton.querySelector(".breadcrumbs-widget-item-id");
michael@0 92 let id = inspector.selection.node.id;
michael@0 93 is(labelId.textContent, "#" + id, "Node " + cursor + ": selection matches");
michael@0 94 }
michael@0 95
michael@0 96 function finishUp() {
michael@0 97 doc = nodes = inspector = null;
michael@0 98 gBrowser.removeCurrentTab();
michael@0 99 finish();
michael@0 100 }
michael@0 101 }

mercurial