1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_utils07.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,159 @@ 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 + "<body style='margin: 0;'>", 1.25 + "<frameset cols='50%,50%'>", 1.26 + "<frame src='", 1.27 + ["data:text/html,", 1.28 + "<!DOCTYPE html>", 1.29 + "<html>", 1.30 + "<body style='margin: 0;'>", 1.31 + "<div id='test-div' style='width: 123px; height: 456px;'></div>", 1.32 + "</body>", 1.33 + "</html>" 1.34 + ].join(""), 1.35 + "' />", 1.36 + "<frame src='", 1.37 + ["data:text/html,", 1.38 + "<!DOCTYPE html>", 1.39 + "<html>", 1.40 + "<body style='margin: 0;'>", 1.41 + "<span></span>", 1.42 + "</body>", 1.43 + "</html>" 1.44 + ].join(""), 1.45 + "' />", 1.46 + "</frameset>", 1.47 + "<iframe src='", 1.48 + ["data:text/html,", 1.49 + "<!DOCTYPE html>", 1.50 + "<html>", 1.51 + "<body>", 1.52 + "<span></span>", 1.53 + "</body>", 1.54 + "</html>" 1.55 + ].join(""), 1.56 + "'></iframe>", 1.57 + "<frame src='", 1.58 + ["data:text/html,", 1.59 + "<!DOCTYPE html>", 1.60 + "<html>", 1.61 + "<body style='margin: 0;'>", 1.62 + "<span></span>", 1.63 + "</body>", 1.64 + "</html>" 1.65 + ].join(""), 1.66 + "' />", 1.67 + "<frame src='", 1.68 + ["data:text/html,", 1.69 + "<!DOCTYPE html>", 1.70 + "<html>", 1.71 + "<body style='margin: 0;'>", 1.72 + "<iframe src='", 1.73 + ["data:text/html,", 1.74 + "<!DOCTYPE html>", 1.75 + "<html>", 1.76 + "<body>", 1.77 + "<div></div>", 1.78 + "</body>", 1.79 + "</html>" 1.80 + ].join(""), 1.81 + "'></iframe>", 1.82 + "</body>", 1.83 + "</html>" 1.84 + ].join(""), 1.85 + "' />", 1.86 + "</body>", 1.87 + "</html>" 1.88 + ].join("")); 1.89 + 1.90 + gBrowser.parentNode.appendChild(iframe); 1.91 +} 1.92 + 1.93 +function test() { 1.94 + waitForExplicitFinish(); 1.95 + ok(TiltUtils, "The TiltUtils object doesn't exist."); 1.96 + 1.97 + let dom = TiltUtils.DOM; 1.98 + ok(dom, "The TiltUtils.DOM wasn't found."); 1.99 + 1.100 + init(function(iframe) { 1.101 + let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow); 1.102 + 1.103 + is(cwDimensions.width - iframe.contentWindow.scrollMaxX, 1.104 + iframe.contentWindow.innerWidth, 1.105 + "The content window width wasn't calculated correctly."); 1.106 + is(cwDimensions.height - iframe.contentWindow.scrollMaxY, 1.107 + iframe.contentWindow.innerHeight, 1.108 + "The content window height wasn't calculated correctly."); 1.109 + 1.110 + let lh = new LayoutHelpers(gBrowser.contentWindow); 1.111 + let nodeCoordinates = lh.getRect( 1.112 + iframe.contentDocument.getElementById("test-div"), iframe.contentWindow); 1.113 + 1.114 + let frameOffset = lh.getIframeContentOffset(iframe); 1.115 + let frameRect = iframe.getBoundingClientRect(); 1.116 + 1.117 + is(nodeCoordinates.top, frameRect.top + frameOffset[0], 1.118 + "The node coordinates top value wasn't calculated correctly."); 1.119 + is(nodeCoordinates.left, frameRect.left + frameOffset[1], 1.120 + "The node coordinates left value wasn't calculated correctly."); 1.121 + is(nodeCoordinates.width, 123, 1.122 + "The node coordinates width value wasn't calculated correctly."); 1.123 + is(nodeCoordinates.height, 456, 1.124 + "The node coordinates height value wasn't calculated correctly."); 1.125 + 1.126 + 1.127 + let store = dom.traverse(iframe.contentWindow); 1.128 + 1.129 + let expected = [ 1.130 + { name: "html", depth: 0 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.131 + { name: "head", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.132 + { name: "body", depth: 1 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.133 + { name: "div", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.134 + { name: "span", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.135 + { name: "iframe", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.136 + { name: "span", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.137 + { name: "iframe", depth: 2 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.138 + { name: "html", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.139 + { name: "html", depth: 3 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.140 + { name: "head", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.141 + { name: "body", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.142 + { name: "head", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.143 + { name: "body", depth: 4 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.144 + { name: "span", depth: 5 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.145 + { name: "div", depth: 5 * STACK_THICKNESS, thickness: STACK_THICKNESS }, 1.146 + ]; 1.147 + 1.148 + is(store.nodes.length, expected.length, 1.149 + "The traverse() function didn't walk the correct number of nodes."); 1.150 + is(store.info.length, expected.length, 1.151 + "The traverse() function didn't examine the correct number of nodes."); 1.152 + 1.153 + for (let i = 0; i < expected.length; i++) { 1.154 + is(store.info[i].name, expected[i].name, 1.155 + "traversed node " + (i + 1) + " isn't the expected one."); 1.156 + is(store.info[i].coord.depth, expected[i].depth, 1.157 + "traversed node " + (i + 1) + " doesn't have the expected depth."); 1.158 + is(store.info[i].coord.thickness, expected[i].thickness, 1.159 + "traversed node " + (i + 1) + " doesn't have the expected thickness."); 1.160 + } 1.161 + }); 1.162 +}