From 51c59a72ccdc361b336e374f27720cdfd8b04f8b Mon Sep 17 00:00:00 2001 From: Sankha Narayan Guria Date: Tue, 10 Jul 2012 22:28:00 +0300 Subject: [PATCH] Bug 739151 - Tilt now supports frames; r=vporof,rcampbell --- browser/devtools/tilt/TiltUtils.jsm | 2 +- browser/devtools/tilt/test/Makefile.in | 1 + .../tilt/test/browser_tilt_utils07.js | 192 ++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 browser/devtools/tilt/test/browser_tilt_utils07.js diff --git a/browser/devtools/tilt/TiltUtils.jsm b/browser/devtools/tilt/TiltUtils.jsm index ff8898af1f9..c142feb9e6b 100644 --- a/browser/devtools/tilt/TiltUtils.jsm +++ b/browser/devtools/tilt/TiltUtils.jsm @@ -441,7 +441,7 @@ TiltUtils.DOM = { } // prepare the queue array - Array.prototype.push.apply(queue, name === "iframe" ? + Array.prototype.push.apply(queue, name === "iframe" || name === "frame" ? node.contentDocument.childNodes : node.childNodes); } diff --git a/browser/devtools/tilt/test/Makefile.in b/browser/devtools/tilt/test/Makefile.in index 3f5c66e38f4..79b9976b583 100644 --- a/browser/devtools/tilt/test/Makefile.in +++ b/browser/devtools/tilt/test/Makefile.in @@ -56,6 +56,7 @@ MOCHITEST_BROWSER_FILES += \ browser_tilt_utils04.js \ browser_tilt_utils05.js \ browser_tilt_utils06.js \ + browser_tilt_utils07.js \ browser_tilt_visualizer.js \ browser_tilt_zoom.js \ $(NULL) diff --git a/browser/devtools/tilt/test/browser_tilt_utils07.js b/browser/devtools/tilt/test/browser_tilt_utils07.js new file mode 100644 index 00000000000..e40aa8ec270 --- /dev/null +++ b/browser/devtools/tilt/test/browser_tilt_utils07.js @@ -0,0 +1,192 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +function init(callback) { + let iframe = gBrowser.ownerDocument.createElement("iframe"); + + iframe.addEventListener("load", function onLoad() { + iframe.removeEventListener("load", onLoad, true); + callback(iframe); + + gBrowser.parentNode.removeChild(iframe); + finish(); + }, true); + + iframe.setAttribute("src", ["data:text/html,", + "", + "", + "", + "", + "", + "
", + "", + "" + ].join(""), + "' />", + "", + "", + "", + "" + ].join(""), + "' />", + "", + "", + "", + "", + "", + "" + ].join(""), + "' />", + "", + "", + "", + "" + ].join(""), + "' />", + "", + "" + ].join("")); + + gBrowser.parentNode.appendChild(iframe); +} + +function test() { + waitForExplicitFinish(); + ok(TiltUtils, "The TiltUtils object doesn't exist."); + + let dom = TiltUtils.DOM; + ok(dom, "The TiltUtils.DOM wasn't found."); + + init(function(iframe) { + let cwDimensions = dom.getContentWindowDimensions(iframe.contentWindow); + + is(cwDimensions.width - iframe.contentWindow.scrollMaxX, + iframe.contentWindow.innerWidth, + "The content window width wasn't calculated correctly."); + is(cwDimensions.height - iframe.contentWindow.scrollMaxY, + iframe.contentWindow.innerHeight, + "The content window height wasn't calculated correctly."); + + let nodeCoordinates = LayoutHelpers.getRect( + iframe.contentDocument.getElementById("test-div"), iframe.contentWindow); + + let frameOffset = LayoutHelpers.getIframeContentOffset(iframe); + let frameRect = iframe.getBoundingClientRect(); + + is(nodeCoordinates.top, frameRect.top + frameOffset[0], + "The node coordinates top value wasn't calculated correctly."); + is(nodeCoordinates.left, frameRect.left + frameOffset[1], + "The node coordinates left value wasn't calculated correctly."); + is(nodeCoordinates.width, 123, + "The node coordinates width value wasn't calculated correctly."); + is(nodeCoordinates.height, 456, + "The node coordinates height value wasn't calculated correctly."); + + + let store = dom.traverse(iframe.contentWindow); + + is(store.nodes.length, 16, + "The traverse() function didn't walk the correct number of nodes."); + is(store.info.length, 16, + "The traverse() function didn't examine the correct number of nodes."); + is(store.info[0].name, "html", + "the 1st traversed node isn't the expected one."); + is(store.info[0].depth, 0, + "the 1st traversed node doesn't have the expected depth."); + is(store.info[1].name, "head", + "the 2nd traversed node isn't the expected one."); + is(store.info[1].depth, 1, + "the 2nd traversed node doesn't have the expected depth."); + is(store.info[2].name, "body", + "the 3rd traversed node isn't the expected one."); + is(store.info[2].depth, 1, + "the 3rd traversed node doesn't have the expected depth."); + is(store.info[3].name, "div", + "the 4th traversed node isn't the expected one."); + is(store.info[3].depth, 2, + "the 4th traversed node doesn't have the expected depth."); + is(store.info[4].name, "span", + "the 5th traversed node isn't the expected one."); + is(store.info[4].depth, 2, + "the 5th traversed node doesn't have the expected depth."); + is(store.info[5].name, "iframe", + "the 6th traversed node isn't the expected one."); + is(store.info[5].depth, 2, + "the 6th traversed node doesn't have the expected depth."); + is(store.info[6].name, "span", + "the 7th traversed node isn't the expected one."); + is(store.info[6].depth, 2, + "the 7th traversed node doesn't have the expected depth."); + is(store.info[7].name, "iframe", + "the 8th traversed node isn't the expected one."); + is(store.info[7].depth, 2, + "the 8th traversed node doesn't have the expected depth."); + is(store.info[8].name, "html", + "the 9th traversed node isn't the expected one."); + is(store.info[8].depth, 3, + "the 9th traversed node doesn't have the expected depth."); + is(store.info[9].name, "html", + "the 10th traversed node isn't the expected one."); + is(store.info[9].depth, 3, + "the 10th traversed node doesn't have the expected depth."); + is(store.info[10].name, "head", + "the 11th traversed node isn't the expected one."); + is(store.info[10].depth, 4, + "the 11th traversed node doesn't have the expected depth."); + is(store.info[11].name, "body", + "the 12th traversed node isn't the expected one."); + is(store.info[11].depth, 4, + "the 12th traversed node doesn't have the expected depth."); + is(store.info[12].name, "head", + "the 13th traversed node isn't the expected one."); + is(store.info[12].depth, 4, + "the 13th traversed node doesn't have the expected depth."); + is(store.info[13].name, "body", + "the 14th traversed node isn't the expected one."); + is(store.info[13].depth, 4, + "the 14th traversed node doesn't have the expected depth."); + is(store.info[14].name, "span", + "the 15th traversed node isn't the expected one."); + is(store.info[14].depth, 5, + "the 15th traversed node doesn't have the expected depth."); + is(store.info[15].name, "div", + "the 16th traversed node isn't the expected one."); + is(store.info[15].depth, 5, + "the 16th traversed node doesn't have the expected depth."); + }); +}