browser/devtools/tilt/test/browser_tilt_utils05.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3 "use strict";
michael@0 4
michael@0 5 const STACK_THICKNESS = 15;
michael@0 6
michael@0 7 function init(callback) {
michael@0 8 let iframe = gBrowser.ownerDocument.createElement("iframe");
michael@0 9
michael@0 10 iframe.addEventListener("load", function onLoad() {
michael@0 11 iframe.removeEventListener("load", onLoad, true);
michael@0 12 callback(iframe);
michael@0 13
michael@0 14 gBrowser.parentNode.removeChild(iframe);
michael@0 15 finish();
michael@0 16 }, true);
michael@0 17
michael@0 18 iframe.setAttribute("src", ["data:text/html,",
michael@0 19 "<!DOCTYPE html>",
michael@0 20 "<html>",
michael@0 21 "<head>",
michael@0 22 "<style>",
michael@0 23 "</style>",
michael@0 24 "<script>",
michael@0 25 "</script>",
michael@0 26 "</head>",
michael@0 27 "<body style='margin: 0;'>",
michael@0 28 "<div style='margin-top: 98px;" +
michael@0 29 "margin-left: 76px;" +
michael@0 30 "width: 123px;" +
michael@0 31 "height: 456px;' id='test-div'>",
michael@0 32 "<span></span>",
michael@0 33 "</div>",
michael@0 34 "</body>",
michael@0 35 "</html>"
michael@0 36 ].join(""));
michael@0 37
michael@0 38 gBrowser.parentNode.appendChild(iframe);
michael@0 39 }
michael@0 40
michael@0 41 function test() {
michael@0 42 waitForExplicitFinish();
michael@0 43 ok(TiltUtils, "The TiltUtils object doesn't exist.");
michael@0 44
michael@0 45 let dom = TiltUtils.DOM;
michael@0 46 ok(dom, "The TiltUtils.DOM wasn't found.");
michael@0 47
michael@0 48 init(function(iframe) {
michael@0 49 let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow);
michael@0 50
michael@0 51 is(cwDimensions.width - iframe.contentWindow.scrollMaxX,
michael@0 52 iframe.contentWindow.innerWidth,
michael@0 53 "The content window width wasn't calculated correctly.");
michael@0 54 is(cwDimensions.height - iframe.contentWindow.scrollMaxY,
michael@0 55 iframe.contentWindow.innerHeight,
michael@0 56 "The content window height wasn't calculated correctly.");
michael@0 57
michael@0 58 let lh = new LayoutHelpers(gBrowser.contentWindow);
michael@0 59 let nodeCoordinates = lh.getRect(
michael@0 60 iframe.contentDocument.getElementById("test-div"), iframe.contentWindow);
michael@0 61
michael@0 62 let frameOffset = lh.getIframeContentOffset(iframe);
michael@0 63 let frameRect = iframe.getBoundingClientRect();
michael@0 64
michael@0 65 is(nodeCoordinates.top, frameRect.top + frameOffset[0] + 98,
michael@0 66 "The node coordinates top value wasn't calculated correctly.");
michael@0 67 is(nodeCoordinates.left, frameRect.left + frameOffset[1] + 76,
michael@0 68 "The node coordinates left value wasn't calculated correctly.");
michael@0 69 is(nodeCoordinates.width, 123,
michael@0 70 "The node coordinates width value wasn't calculated correctly.");
michael@0 71 is(nodeCoordinates.height, 456,
michael@0 72 "The node coordinates height value wasn't calculated correctly.");
michael@0 73
michael@0 74
michael@0 75 let store = dom.traverse(iframe.contentWindow);
michael@0 76
michael@0 77 let expected = [
michael@0 78 { name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 79 { name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 80 { name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 81 { name: "style", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 82 { name: "script", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 83 { name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 84 { name: "span", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS },
michael@0 85 ];
michael@0 86
michael@0 87 is(store.nodes.length, expected.length,
michael@0 88 "The traverse() function didn't walk the correct number of nodes.");
michael@0 89 is(store.info.length, expected.length,
michael@0 90 "The traverse() function didn't examine the correct number of nodes.");
michael@0 91
michael@0 92 for (let i = 0; i < expected.length; i++) {
michael@0 93 is(store.info[i].name, expected[i].name,
michael@0 94 "traversed node " + (i + 1) + " isn't the expected one.");
michael@0 95 is(store.info[i].coord.depth, expected[i].depth,
michael@0 96 "traversed node " + (i + 1) + " doesn't have the expected depth.");
michael@0 97 is(store.info[i].coord.thickness, expected[i].thickness,
michael@0 98 "traversed node " + (i + 1) + " doesn't have the expected thickness.");
michael@0 99 }
michael@0 100 });
michael@0 101 }

mercurial