|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 "use strict"; |
|
5 |
|
6 const { Loader } = require("sdk/test/loader"); |
|
7 const hiddenFrames = require("sdk/frame/hidden-frame"); |
|
8 const { HiddenFrame } = hiddenFrames; |
|
9 |
|
10 exports["test Frame"] = function(assert, done) { |
|
11 let url = "data:text/html;charset=utf-8,<!DOCTYPE%20html>"; |
|
12 |
|
13 let hiddenFrame = hiddenFrames.add(HiddenFrame({ |
|
14 onReady: function () { |
|
15 assert.equal(this.element.contentWindow.location, "about:blank", |
|
16 "HiddenFrame loads about:blank by default."); |
|
17 |
|
18 function onDOMReady() { |
|
19 hiddenFrame.element.removeEventListener("DOMContentLoaded", onDOMReady, |
|
20 false); |
|
21 assert.equal(hiddenFrame.element.contentWindow.location, url, |
|
22 "HiddenFrame loads the specified content."); |
|
23 done(); |
|
24 } |
|
25 |
|
26 this.element.addEventListener("DOMContentLoaded", onDOMReady, false); |
|
27 this.element.setAttribute("src", url); |
|
28 } |
|
29 })); |
|
30 }; |
|
31 |
|
32 exports["test frame removed properly"] = function(assert, done) { |
|
33 let url = "data:text/html;charset=utf-8,<!DOCTYPE%20html>"; |
|
34 |
|
35 let hiddenFrame = hiddenFrames.add(HiddenFrame({ |
|
36 onReady: function () { |
|
37 let frame = this.element; |
|
38 assert.ok(frame.parentNode, "frame has a parent node"); |
|
39 hiddenFrames.remove(hiddenFrame); |
|
40 assert.ok(!frame.parentNode, "frame no longer has a parent node"); |
|
41 done(); |
|
42 } |
|
43 })); |
|
44 }; |
|
45 |
|
46 exports["test unload detaches panels"] = function(assert, done) { |
|
47 let loader = Loader(module); |
|
48 let { add, remove, HiddenFrame } = loader.require("sdk/frame/hidden-frame"); |
|
49 let frames = [] |
|
50 |
|
51 function ready() { |
|
52 frames.push(this.element); |
|
53 if (frames.length === 2) complete(); |
|
54 } |
|
55 |
|
56 add(HiddenFrame({ onReady: ready })); |
|
57 add(HiddenFrame({ onReady: ready })); |
|
58 |
|
59 function complete() { |
|
60 frames.forEach(function(frame) { |
|
61 assert.ok(frame.parentNode, "frame is in the document"); |
|
62 }) |
|
63 loader.unload(); |
|
64 frames.forEach(function(frame) { |
|
65 assert.ok(!frame.parentNode, "frame isn't in the document'"); |
|
66 }); |
|
67 done(); |
|
68 } |
|
69 }; |
|
70 |
|
71 require("test").run(exports); |