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.

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

mercurial