michael@0: /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const TEST_URI = "http://example.com/browser/dom/tests/browser/browser_frame_elements.html"; michael@0: let gWindow; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: var tab = gBrowser.addTab(TEST_URI); michael@0: gBrowser.selectedTab = tab; michael@0: var browser = gBrowser.selectedBrowser; michael@0: michael@0: registerCleanupFunction(function () { michael@0: gBrowser.removeTab(tab); michael@0: gWindow = null; michael@0: }); michael@0: michael@0: browser.addEventListener("DOMContentLoaded", function onLoad(event) { michael@0: browser.removeEventListener("DOMContentLoaded", onLoad, false); michael@0: executeSoon(function test_executeSoon() { michael@0: gWindow = browser.contentWindow; michael@0: startTests(); michael@0: }); michael@0: }, false); michael@0: } michael@0: michael@0: function startTests() { michael@0: info("Frame tests started"); michael@0: michael@0: info("Checking top window"); michael@0: let windowUtils = getWindowUtils(gWindow); michael@0: is (windowUtils.containerElement, gBrowser.selectedBrowser, "Container element for main window is xul:browser"); michael@0: is (gWindow.top, gWindow, "gWindow is top"); michael@0: is (gWindow.parent, gWindow, "gWindow is parent"); michael@0: michael@0: info("Checking about:blank iframe"); michael@0: let iframeBlank = gWindow.document.querySelector("#iframe-blank"); michael@0: ok (iframeBlank, "Iframe exists on page"); michael@0: let iframeBlankUtils = getWindowUtils(iframeBlank.contentWindow); michael@0: is (iframeBlankUtils.containerElement, iframeBlank, "Container element for iframe window is iframe"); michael@0: is (iframeBlank.contentWindow.top, gWindow, "gWindow is top"); michael@0: is (iframeBlank.contentWindow.parent, gWindow, "gWindow is parent"); michael@0: michael@0: info("Checking iframe with data url src"); michael@0: let iframeDataUrl = gWindow.document.querySelector("#iframe-data-url"); michael@0: ok (iframeDataUrl, "Iframe exists on page"); michael@0: let iframeDataUrlUtils = getWindowUtils(iframeDataUrl.contentWindow); michael@0: is (iframeDataUrlUtils.containerElement, iframeDataUrl, "Container element for iframe window is iframe"); michael@0: is (iframeDataUrl.contentWindow.top, gWindow, "gWindow is top"); michael@0: is (iframeDataUrl.contentWindow.parent, gWindow, "gWindow is parent"); michael@0: michael@0: info("Checking object with data url data attribute"); michael@0: let objectDataUrl = gWindow.document.querySelector("#object-data-url"); michael@0: ok (objectDataUrl, "Object exists on page"); michael@0: let objectDataUrlUtils = getWindowUtils(objectDataUrl.contentWindow); michael@0: is (objectDataUrlUtils.containerElement, objectDataUrl, "Container element for object window is the object"); michael@0: is (objectDataUrl.contentWindow.top, gWindow, "gWindow is top"); michael@0: is (objectDataUrl.contentWindow.parent, gWindow, "gWindow is parent"); michael@0: michael@0: info("Granting special powers for mozbrowser"); michael@0: SpecialPowers.addPermission("browser", true, gWindow.document); michael@0: SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true); michael@0: michael@0: info("Checking mozbrowser iframe"); michael@0: let mozBrowserFrame = gWindow.document.createElement("iframe"); michael@0: mozBrowserFrame.setAttribute("mozbrowser", ""); michael@0: gWindow.document.body.appendChild(mozBrowserFrame); michael@0: is (mozBrowserFrame.contentWindow.top, mozBrowserFrame.contentWindow, "Mozbrowser top == iframe window"); michael@0: is (mozBrowserFrame.contentWindow.parent, mozBrowserFrame.contentWindow, "Mozbrowser parent == iframe window"); michael@0: michael@0: info("Revoking special powers for mozbrowser"); michael@0: SpecialPowers.clearUserPref('dom.mozBrowserFramesEnabled') michael@0: SpecialPowers.removePermission("browser", gWindow.document); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: function getWindowUtils(window) michael@0: { michael@0: return window. michael@0: QueryInterface(Components.interfaces.nsIInterfaceRequestor). michael@0: getInterface(Components.interfaces.nsIDOMWindowUtils); michael@0: }