browser/devtools/tilt/test/browser_tilt_utils05.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/test/browser_tilt_utils05.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 +"use strict";
     1.7 +
     1.8 +const STACK_THICKNESS = 15;
     1.9 +
    1.10 +function init(callback) {
    1.11 +  let iframe = gBrowser.ownerDocument.createElement("iframe");
    1.12 +
    1.13 +  iframe.addEventListener("load", function onLoad() {
    1.14 +    iframe.removeEventListener("load", onLoad, true);
    1.15 +    callback(iframe);
    1.16 +
    1.17 +    gBrowser.parentNode.removeChild(iframe);
    1.18 +    finish();
    1.19 +  }, true);
    1.20 +
    1.21 +  iframe.setAttribute("src", ["data:text/html,",
    1.22 +    "<!DOCTYPE html>",
    1.23 +    "<html>",
    1.24 +      "<head>",
    1.25 +        "<style>",
    1.26 +        "</style>",
    1.27 +        "<script>",
    1.28 +        "</script>",
    1.29 +      "</head>",
    1.30 +      "<body style='margin: 0;'>",
    1.31 +        "<div style='margin-top: 98px;" +
    1.32 +                    "margin-left: 76px;" +
    1.33 +                    "width: 123px;" +
    1.34 +                    "height: 456px;' id='test-div'>",
    1.35 +          "<span></span>",
    1.36 +        "</div>",
    1.37 +      "</body>",
    1.38 +    "</html>"
    1.39 +  ].join(""));
    1.40 +
    1.41 +  gBrowser.parentNode.appendChild(iframe);
    1.42 +}
    1.43 +
    1.44 +function test() {
    1.45 +  waitForExplicitFinish();
    1.46 +  ok(TiltUtils, "The TiltUtils object doesn't exist.");
    1.47 +
    1.48 +  let dom = TiltUtils.DOM;
    1.49 +  ok(dom, "The TiltUtils.DOM wasn't found.");
    1.50 +
    1.51 +  init(function(iframe) {
    1.52 +    let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow);
    1.53 +
    1.54 +    is(cwDimensions.width - iframe.contentWindow.scrollMaxX,
    1.55 +      iframe.contentWindow.innerWidth,
    1.56 +      "The content window width wasn't calculated correctly.");
    1.57 +    is(cwDimensions.height - iframe.contentWindow.scrollMaxY,
    1.58 +      iframe.contentWindow.innerHeight,
    1.59 +      "The content window height wasn't calculated correctly.");
    1.60 +
    1.61 +    let lh = new LayoutHelpers(gBrowser.contentWindow);
    1.62 +    let nodeCoordinates = lh.getRect(
    1.63 +      iframe.contentDocument.getElementById("test-div"), iframe.contentWindow);
    1.64 +
    1.65 +    let frameOffset = lh.getIframeContentOffset(iframe);
    1.66 +    let frameRect = iframe.getBoundingClientRect();
    1.67 +
    1.68 +    is(nodeCoordinates.top, frameRect.top + frameOffset[0] + 98,
    1.69 +      "The node coordinates top value wasn't calculated correctly.");
    1.70 +    is(nodeCoordinates.left, frameRect.left + frameOffset[1] + 76,
    1.71 +      "The node coordinates left value wasn't calculated correctly.");
    1.72 +    is(nodeCoordinates.width, 123,
    1.73 +      "The node coordinates width value wasn't calculated correctly.");
    1.74 +    is(nodeCoordinates.height, 456,
    1.75 +      "The node coordinates height value wasn't calculated correctly.");
    1.76 +
    1.77 +
    1.78 +    let store = dom.traverse(iframe.contentWindow);
    1.79 +
    1.80 +    let expected = [
    1.81 +      { name: "html",   depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.82 +      { name: "head",   depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.83 +      { name: "body",   depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.84 +      { name: "style",  depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.85 +      { name: "script", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.86 +      { name: "div",    depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.87 +      { name: "span",   depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
    1.88 +    ];
    1.89 +
    1.90 +    is(store.nodes.length, expected.length,
    1.91 +      "The traverse() function didn't walk the correct number of nodes.");
    1.92 +    is(store.info.length, expected.length,
    1.93 +      "The traverse() function didn't examine the correct number of nodes.");
    1.94 +
    1.95 +    for (let i = 0; i < expected.length; i++) {
    1.96 +      is(store.info[i].name, expected[i].name,
    1.97 +        "traversed node " + (i + 1) + " isn't the expected one.");
    1.98 +      is(store.info[i].coord.depth, expected[i].depth,
    1.99 +        "traversed node " + (i + 1) + " doesn't have the expected depth.");
   1.100 +      is(store.info[i].coord.thickness, expected[i].thickness,
   1.101 +        "traversed node " + (i + 1) + " doesn't have the expected thickness.");
   1.102 +    }
   1.103 +  });
   1.104 +}

mercurial