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