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