browser/devtools/inspector/test/browser_inspector_infobar.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_infobar.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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 +  waitForExplicitFinish();
     1.9 +  ignoreAllUncaughtExceptions();
    1.10 +
    1.11 +  let doc;
    1.12 +  let nodes;
    1.13 +  let cursor;
    1.14 +  let inspector;
    1.15 +
    1.16 +  gBrowser.selectedTab = gBrowser.addTab();
    1.17 +  gBrowser.selectedBrowser.addEventListener("load", function onload() {
    1.18 +    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    1.19 +    doc = content.document;
    1.20 +    waitForFocus(setupInfobarTest, content);
    1.21 +  }, true);
    1.22 +
    1.23 +  let style = "body{width:100%;height: 100%} div {position: absolute;height: 100px;width: 500px}#bottom {bottom: 0px}#vertical {height: 100%}#farbottom{bottom: -200px}";
    1.24 +  let html = "<style>" + style + "</style><div id=vertical></div><div id=top class='class1 class2'></div><div id=bottom></div><div id=farbottom></div>"
    1.25 +
    1.26 +  content.location = "data:text/html," + encodeURIComponent(html);
    1.27 +
    1.28 +  function setupInfobarTest() {
    1.29 +    nodes = [
    1.30 +      {node: doc.querySelector("#top"), position: "bottom", tag: "DIV", id: "#top", classes: ".class1.class2"},
    1.31 +      {node: doc.querySelector("#vertical"), position: "overlap", tag: "DIV", id: "#vertical", classes: ""},
    1.32 +      {node: doc.querySelector("#bottom"), position: "top", tag: "DIV", id: "#bottom", classes: ""},
    1.33 +      {node: doc.querySelector("body"), position: "overlap", tag: "BODY", id: "", classes: ""},
    1.34 +      {node: doc.querySelector("#farbottom"), position: "top", tag: "DIV", id: "#farbottom", classes: ""},
    1.35 +    ]
    1.36 +
    1.37 +    for (let i = 0; i < nodes.length; i++) {
    1.38 +      ok(nodes[i].node, "node " + i + " found");
    1.39 +    }
    1.40 +
    1.41 +    openInspector(runTests);
    1.42 +  }
    1.43 +
    1.44 +  function mouseOverContainerToShowHighlighter(node, cb) {
    1.45 +    let container = getContainerForRawNode(inspector.markup, node);
    1.46 +    EventUtils.synthesizeMouse(container.tagLine, 2, 2, {type: "mousemove"},
    1.47 +      inspector.markup.doc.defaultView);
    1.48 +    executeSoon(cb);
    1.49 +  }
    1.50 +
    1.51 +  function runTests(aInspector) {
    1.52 +    inspector = aInspector;
    1.53 +    inspector.selection.setNode(content.document.querySelector("body"));
    1.54 +    inspector.once("inspector-updated", () => {
    1.55 +      cursor = 0;
    1.56 +      executeSoon(function() {
    1.57 +        mouseOverContainerToShowHighlighter(nodes[0].node, nodeSelected);
    1.58 +      });
    1.59 +    });
    1.60 +  }
    1.61 +
    1.62 +  function nodeSelected() {
    1.63 +    executeSoon(function() {
    1.64 +      performTest();
    1.65 +      cursor++;
    1.66 +      if (cursor >= nodes.length) {
    1.67 +        finishUp();
    1.68 +      } else {
    1.69 +        let node = nodes[cursor].node;
    1.70 +        mouseOverContainerToShowHighlighter(node, nodeSelected);
    1.71 +      }
    1.72 +    });
    1.73 +  }
    1.74 +
    1.75 +  function performTest() {
    1.76 +    let browser = gBrowser.selectedBrowser;
    1.77 +    let stack = browser.parentNode;
    1.78 +
    1.79 +    let container = stack.querySelector(".highlighter-nodeinfobar-positioner");
    1.80 +    is(container.getAttribute("position"), nodes[cursor].position, "node " + cursor + ": position matches.");
    1.81 +
    1.82 +    let tagNameLabel = stack.querySelector(".highlighter-nodeinfobar-tagname");
    1.83 +    is(tagNameLabel.textContent, nodes[cursor].tag, "node " + cursor  + ": tagName matches.");
    1.84 +
    1.85 +    let idLabel = stack.querySelector(".highlighter-nodeinfobar-id");
    1.86 +    is(idLabel.textContent, nodes[cursor].id, "node " + cursor  + ": id matches.");
    1.87 +
    1.88 +    let classesBox = stack.querySelector(".highlighter-nodeinfobar-classes");
    1.89 +    is(classesBox.textContent, nodes[cursor].classes, "node " + cursor  + ": classes match.");
    1.90 +  }
    1.91 +
    1.92 +  function finishUp() {
    1.93 +    doc = nodes = null;
    1.94 +    gBrowser.removeCurrentTab();
    1.95 +    finish();
    1.96 +  }
    1.97 +}

mercurial