2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2013-09-24 19:05:00 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const TEST_URI = "http://example.com/browser/dom/tests/browser/browser_frame_elements.html";
|
|
|
|
|
2016-02-10 01:40:36 +03:00
|
|
|
function getWindowUtils(window) {
|
|
|
|
return window.
|
|
|
|
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
}
|
2013-09-24 19:05:00 +04:00
|
|
|
|
2016-02-10 01:40:36 +03:00
|
|
|
add_task(function* test() {
|
|
|
|
yield BrowserTestUtils.withNewTab({ gBrowser, url: TEST_URI }, function* (browser) {
|
|
|
|
if (!browser.isRemoteBrowser) {
|
|
|
|
// Non-e10s, access contentWindow and confirm its container is the browser:
|
|
|
|
let windowUtils = getWindowUtils(browser.contentWindow);
|
|
|
|
is (windowUtils.containerElement, browser,
|
|
|
|
"Container element for main window is xul:browser");
|
2013-09-24 19:05:00 +04:00
|
|
|
|
2016-02-10 01:40:36 +03:00
|
|
|
}
|
2013-09-24 19:05:00 +04:00
|
|
|
|
2016-02-10 01:40:36 +03:00
|
|
|
yield ContentTask.spawn(browser, null, startTests);
|
|
|
|
yield Task.spawn(mozBrowserTests(browser));
|
|
|
|
});
|
|
|
|
});
|
2013-09-24 19:05:00 +04:00
|
|
|
|
|
|
|
function startTests() {
|
2016-02-10 01:40:36 +03:00
|
|
|
function getWindowUtils(window) {
|
|
|
|
return window.
|
|
|
|
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
|
|
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
|
|
|
}
|
2013-09-24 19:05:00 +04:00
|
|
|
info("Frame tests started");
|
|
|
|
|
|
|
|
info("Checking top window");
|
2016-02-10 01:40:36 +03:00
|
|
|
let gWindow = content;
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.equal(gWindow.top, gWindow, "gWindow is top");
|
|
|
|
Assert.equal(gWindow.parent, gWindow, "gWindow is parent");
|
2013-09-24 19:05:00 +04:00
|
|
|
|
|
|
|
info("Checking about:blank iframe");
|
|
|
|
let iframeBlank = gWindow.document.querySelector("#iframe-blank");
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.ok(iframeBlank, "Iframe exists on page");
|
2013-09-24 19:05:00 +04:00
|
|
|
let iframeBlankUtils = getWindowUtils(iframeBlank.contentWindow);
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.equal(iframeBlankUtils.containerElement, iframeBlank, "Container element for iframe window is iframe");
|
|
|
|
Assert.equal(iframeBlank.contentWindow.top, gWindow, "gWindow is top");
|
|
|
|
Assert.equal(iframeBlank.contentWindow.parent, gWindow, "gWindow is parent");
|
2013-09-24 19:05:00 +04:00
|
|
|
|
|
|
|
info("Checking iframe with data url src");
|
|
|
|
let iframeDataUrl = gWindow.document.querySelector("#iframe-data-url");
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.ok(iframeDataUrl, "Iframe exists on page");
|
2013-09-24 19:05:00 +04:00
|
|
|
let iframeDataUrlUtils = getWindowUtils(iframeDataUrl.contentWindow);
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.equal(iframeDataUrlUtils.containerElement, iframeDataUrl, "Container element for iframe window is iframe");
|
|
|
|
Assert.equal(iframeDataUrl.contentWindow.top, gWindow, "gWindow is top");
|
|
|
|
Assert.equal(iframeDataUrl.contentWindow.parent, gWindow, "gWindow is parent");
|
2013-09-24 19:05:00 +04:00
|
|
|
|
|
|
|
info("Checking object with data url data attribute");
|
|
|
|
let objectDataUrl = gWindow.document.querySelector("#object-data-url");
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.ok(objectDataUrl, "Object exists on page");
|
2013-09-24 19:05:00 +04:00
|
|
|
let objectDataUrlUtils = getWindowUtils(objectDataUrl.contentWindow);
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.equal(objectDataUrlUtils.containerElement, objectDataUrl, "Container element for object window is the object");
|
|
|
|
Assert.equal(objectDataUrl.contentWindow.top, gWindow, "gWindow is top");
|
|
|
|
Assert.equal(objectDataUrl.contentWindow.parent, gWindow, "gWindow is parent");
|
2016-02-10 01:40:36 +03:00
|
|
|
}
|
2013-09-24 19:05:00 +04:00
|
|
|
|
2016-02-10 01:40:36 +03:00
|
|
|
function* mozBrowserTests(browser) {
|
2013-09-24 19:05:00 +04:00
|
|
|
info("Granting special powers for mozbrowser");
|
2016-02-10 01:40:36 +03:00
|
|
|
SpecialPowers.addPermission("browser", true, TEST_URI);
|
2013-09-24 19:05:00 +04:00
|
|
|
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
|
2016-11-17 16:53:30 +03:00
|
|
|
SpecialPowers.setBoolPref('network.disable.ipc.security', true);
|
2013-09-24 19:05:00 +04:00
|
|
|
|
2016-02-10 01:40:36 +03:00
|
|
|
yield ContentTask.spawn(browser, null, function() {
|
|
|
|
info("Checking mozbrowser iframe");
|
|
|
|
let mozBrowserFrame = content.document.createElement("iframe");
|
|
|
|
mozBrowserFrame.setAttribute("mozbrowser", "");
|
|
|
|
content.document.body.appendChild(mozBrowserFrame);
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.equal(mozBrowserFrame.contentWindow.top, mozBrowserFrame.contentWindow,
|
2016-02-10 01:40:36 +03:00
|
|
|
"Mozbrowser top == iframe window");
|
2016-03-04 16:32:32 +03:00
|
|
|
Assert.equal(mozBrowserFrame.contentWindow.parent, mozBrowserFrame.contentWindow,
|
2016-02-10 01:40:36 +03:00
|
|
|
"Mozbrowser parent == iframe window");
|
|
|
|
});
|
2013-09-24 19:05:00 +04:00
|
|
|
|
|
|
|
info("Revoking special powers for mozbrowser");
|
2016-11-17 16:53:30 +03:00
|
|
|
SpecialPowers.clearUserPref('dom.mozBrowserFramesEnabled');
|
|
|
|
SpecialPowers.clearUserPref('network.disable.ipc.security');
|
2016-02-10 01:40:36 +03:00
|
|
|
SpecialPowers.removePermission("browser", TEST_URI);
|
2013-09-24 19:05:00 +04:00
|
|
|
}
|