browser/devtools/inspector/test/browser_inspector_breadcrumbs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/inspector/test/browser_inspector_breadcrumbs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test()
     1.8 +{
     1.9 +  waitForExplicitFinish();
    1.10 +  ignoreAllUncaughtExceptions();
    1.11 +
    1.12 +  let nodes = [
    1.13 +    {nodeId: "i1111", result: "i1 i11 i111 i1111"},
    1.14 +    {nodeId: "i22", result: "i2 i22 i221"},
    1.15 +    {nodeId: "i2111", result: "i2 i21 i211 i2111"},
    1.16 +    {nodeId: "i21", result: "i2 i21 i211 i2111"},
    1.17 +    {nodeId: "i22211", result: "i2 i22 i222 i2221 i22211"},
    1.18 +    {nodeId: "i22", result: "i2 i22 i222 i2221 i22211"},
    1.19 +  ];
    1.20 +
    1.21 +  let doc;
    1.22 +  let nodes;
    1.23 +  let cursor;
    1.24 +  let inspector;
    1.25 +  let target;
    1.26 +  let panel;
    1.27 +  let container;
    1.28 +
    1.29 +  gBrowser.selectedTab = gBrowser.addTab();
    1.30 +  gBrowser.selectedBrowser.addEventListener("load", function onload() {
    1.31 +    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    1.32 +    doc = content.document;
    1.33 +    waitForFocus(setupTest, content);
    1.34 +  }, true);
    1.35 +
    1.36 +  content.location = "http://mochi.test:8888/browser/browser/devtools/inspector/test/browser_inspector_breadcrumbs.html";
    1.37 +
    1.38 +  function setupTest()
    1.39 +  {
    1.40 +    for (let i = 0; i < nodes.length; i++) {
    1.41 +      let node = doc.getElementById(nodes[i].nodeId);
    1.42 +      nodes[i].node = node;
    1.43 +      ok(nodes[i].node, "node " + nodes[i].nodeId + " found");
    1.44 +    }
    1.45 +
    1.46 +    openInspector(runTests);
    1.47 +  }
    1.48 +
    1.49 +  function runTests(aInspector)
    1.50 +  {
    1.51 +    inspector = aInspector;
    1.52 +    target = TargetFactory.forTab(gBrowser.selectedTab);
    1.53 +    panel = gDevTools.getToolbox(target).getPanel("inspector");
    1.54 +    container = panel.panelDoc.getElementById("inspector-breadcrumbs");
    1.55 +    cursor = 0;
    1.56 +    inspector.on("breadcrumbs-updated", nodeSelected);
    1.57 +    executeSoon(function() {
    1.58 +      inspector.selection.setNode(nodes[0].node);
    1.59 +    });
    1.60 +  }
    1.61 +
    1.62 +  function nodeSelected()
    1.63 +  {
    1.64 +    performTest();
    1.65 +    cursor++;
    1.66 +
    1.67 +    if (cursor >= nodes.length) {
    1.68 +      inspector.off("breadcrumbs-updated", nodeSelected);
    1.69 +      // breadcrumbs-updated is an event that is fired before the rest of the
    1.70 +      // inspector is updated, so there'll be hanging connections if we finish
    1.71 +      // up before waiting for everything to end.
    1.72 +      inspector.once("inspector-updated", finishUp);
    1.73 +    } else {
    1.74 +      let node = nodes[cursor].node;
    1.75 +      inspector.selection.setNode(node);
    1.76 +    }
    1.77 +  }
    1.78 +
    1.79 +  function performTest()
    1.80 +  {
    1.81 +    let buttonsLabelIds = nodes[cursor].result.split(" ");
    1.82 +
    1.83 +    // html > body > …
    1.84 +    is(container.childNodes.length, buttonsLabelIds.length + 2, "Node " + cursor + ": Items count");
    1.85 +
    1.86 +    for (let i = 2; i < container.childNodes.length; i++) {
    1.87 +      let expectedId = "#" + buttonsLabelIds[i - 2];
    1.88 +      let button = container.childNodes[i];
    1.89 +      let labelId = button.querySelector(".breadcrumbs-widget-item-id");
    1.90 +      is(labelId.textContent, expectedId, "Node " + cursor + ": button " + i + " matches");
    1.91 +    }
    1.92 +
    1.93 +    let checkedButton = container.querySelector("button[checked]");
    1.94 +    let labelId = checkedButton.querySelector(".breadcrumbs-widget-item-id");
    1.95 +    let id = inspector.selection.node.id;
    1.96 +    is(labelId.textContent, "#" + id, "Node " + cursor + ": selection matches");
    1.97 +  }
    1.98 +
    1.99 +  function finishUp() {
   1.100 +    doc = nodes = inspector = null;
   1.101 +    gBrowser.removeCurrentTab();
   1.102 +    finish();
   1.103 +  }
   1.104 +}

mercurial