|
1 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 const TEST_URI = "http://example.com/browser/dom/tests/browser/browser_frame_elements.html"; |
|
8 let gWindow; |
|
9 |
|
10 function test() { |
|
11 waitForExplicitFinish(); |
|
12 |
|
13 var tab = gBrowser.addTab(TEST_URI); |
|
14 gBrowser.selectedTab = tab; |
|
15 var browser = gBrowser.selectedBrowser; |
|
16 |
|
17 registerCleanupFunction(function () { |
|
18 gBrowser.removeTab(tab); |
|
19 gWindow = null; |
|
20 }); |
|
21 |
|
22 browser.addEventListener("DOMContentLoaded", function onLoad(event) { |
|
23 browser.removeEventListener("DOMContentLoaded", onLoad, false); |
|
24 executeSoon(function test_executeSoon() { |
|
25 gWindow = browser.contentWindow; |
|
26 startTests(); |
|
27 }); |
|
28 }, false); |
|
29 } |
|
30 |
|
31 function startTests() { |
|
32 info("Frame tests started"); |
|
33 |
|
34 info("Checking top window"); |
|
35 let windowUtils = getWindowUtils(gWindow); |
|
36 is (windowUtils.containerElement, gBrowser.selectedBrowser, "Container element for main window is xul:browser"); |
|
37 is (gWindow.top, gWindow, "gWindow is top"); |
|
38 is (gWindow.parent, gWindow, "gWindow is parent"); |
|
39 |
|
40 info("Checking about:blank iframe"); |
|
41 let iframeBlank = gWindow.document.querySelector("#iframe-blank"); |
|
42 ok (iframeBlank, "Iframe exists on page"); |
|
43 let iframeBlankUtils = getWindowUtils(iframeBlank.contentWindow); |
|
44 is (iframeBlankUtils.containerElement, iframeBlank, "Container element for iframe window is iframe"); |
|
45 is (iframeBlank.contentWindow.top, gWindow, "gWindow is top"); |
|
46 is (iframeBlank.contentWindow.parent, gWindow, "gWindow is parent"); |
|
47 |
|
48 info("Checking iframe with data url src"); |
|
49 let iframeDataUrl = gWindow.document.querySelector("#iframe-data-url"); |
|
50 ok (iframeDataUrl, "Iframe exists on page"); |
|
51 let iframeDataUrlUtils = getWindowUtils(iframeDataUrl.contentWindow); |
|
52 is (iframeDataUrlUtils.containerElement, iframeDataUrl, "Container element for iframe window is iframe"); |
|
53 is (iframeDataUrl.contentWindow.top, gWindow, "gWindow is top"); |
|
54 is (iframeDataUrl.contentWindow.parent, gWindow, "gWindow is parent"); |
|
55 |
|
56 info("Checking object with data url data attribute"); |
|
57 let objectDataUrl = gWindow.document.querySelector("#object-data-url"); |
|
58 ok (objectDataUrl, "Object exists on page"); |
|
59 let objectDataUrlUtils = getWindowUtils(objectDataUrl.contentWindow); |
|
60 is (objectDataUrlUtils.containerElement, objectDataUrl, "Container element for object window is the object"); |
|
61 is (objectDataUrl.contentWindow.top, gWindow, "gWindow is top"); |
|
62 is (objectDataUrl.contentWindow.parent, gWindow, "gWindow is parent"); |
|
63 |
|
64 info("Granting special powers for mozbrowser"); |
|
65 SpecialPowers.addPermission("browser", true, gWindow.document); |
|
66 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true); |
|
67 |
|
68 info("Checking mozbrowser iframe"); |
|
69 let mozBrowserFrame = gWindow.document.createElement("iframe"); |
|
70 mozBrowserFrame.setAttribute("mozbrowser", ""); |
|
71 gWindow.document.body.appendChild(mozBrowserFrame); |
|
72 is (mozBrowserFrame.contentWindow.top, mozBrowserFrame.contentWindow, "Mozbrowser top == iframe window"); |
|
73 is (mozBrowserFrame.contentWindow.parent, mozBrowserFrame.contentWindow, "Mozbrowser parent == iframe window"); |
|
74 |
|
75 info("Revoking special powers for mozbrowser"); |
|
76 SpecialPowers.clearUserPref('dom.mozBrowserFramesEnabled') |
|
77 SpecialPowers.removePermission("browser", gWindow.document); |
|
78 |
|
79 finish(); |
|
80 } |
|
81 |
|
82 function getWindowUtils(window) |
|
83 { |
|
84 return window. |
|
85 QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
|
86 getInterface(Components.interfaces.nsIDOMWindowUtils); |
|
87 } |