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: "use strict"; michael@0: michael@0: const { Loader } = require("sdk/test/loader"); michael@0: const hiddenFrames = require("sdk/frame/hidden-frame"); michael@0: const { HiddenFrame } = hiddenFrames; michael@0: michael@0: exports["test Frame"] = function(assert, done) { michael@0: let url = "data:text/html;charset=utf-8,"; michael@0: michael@0: let hiddenFrame = hiddenFrames.add(HiddenFrame({ michael@0: onReady: function () { michael@0: assert.equal(this.element.contentWindow.location, "about:blank", michael@0: "HiddenFrame loads about:blank by default."); michael@0: michael@0: function onDOMReady() { michael@0: hiddenFrame.element.removeEventListener("DOMContentLoaded", onDOMReady, michael@0: false); michael@0: assert.equal(hiddenFrame.element.contentWindow.location, url, michael@0: "HiddenFrame loads the specified content."); michael@0: done(); michael@0: } michael@0: michael@0: this.element.addEventListener("DOMContentLoaded", onDOMReady, false); michael@0: this.element.setAttribute("src", url); michael@0: } michael@0: })); michael@0: }; michael@0: michael@0: exports["test frame removed properly"] = function(assert, done) { michael@0: let url = "data:text/html;charset=utf-8,"; michael@0: michael@0: let hiddenFrame = hiddenFrames.add(HiddenFrame({ michael@0: onReady: function () { michael@0: let frame = this.element; michael@0: assert.ok(frame.parentNode, "frame has a parent node"); michael@0: hiddenFrames.remove(hiddenFrame); michael@0: assert.ok(!frame.parentNode, "frame no longer has a parent node"); michael@0: done(); michael@0: } michael@0: })); michael@0: }; michael@0: michael@0: exports["test unload detaches panels"] = function(assert, done) { michael@0: let loader = Loader(module); michael@0: let { add, remove, HiddenFrame } = loader.require("sdk/frame/hidden-frame"); michael@0: let frames = [] michael@0: michael@0: function ready() { michael@0: frames.push(this.element); michael@0: if (frames.length === 2) complete(); michael@0: } michael@0: michael@0: add(HiddenFrame({ onReady: ready })); michael@0: add(HiddenFrame({ onReady: ready })); michael@0: michael@0: function complete() { michael@0: frames.forEach(function(frame) { michael@0: assert.ok(frame.parentNode, "frame is in the document"); michael@0: }) michael@0: loader.unload(); michael@0: frames.forEach(function(frame) { michael@0: assert.ok(!frame.parentNode, "frame isn't in the document'"); michael@0: }); michael@0: done(); michael@0: } michael@0: }; michael@0: michael@0: require("test").run(exports);