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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<?xml version="1.0"?>
<!-- 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/. -->
<!--
* The unknownContentType popup can have two different layouts depending on
* whether a helper application can be selected or not.
* This tests that both layouts have correct collapsed elements.
-->
<window title="Unknown Content Type Dialog Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="init()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
let testIndex = -1;
let tests = [
{ // This URL will trigger the simple UI, where only the Save an Cancel buttons are available
url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif",
elements: {
basicBox: { collapsed: false },
normalBox: { collapsed: true }
}
},
{ // This URL will trigger the full UI
url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt",
elements: {
basicBox: { collapsed: true },
normalBox: { collapsed: false }
}
}
];
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
SimpleTest.waitForExplicitFinish();
let windowObserver = {
observe: function(aSubject, aTopic, aData) {
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
if (aTopic == "domwindowclosed") {
if (win.location == UCT_URI)
loadNextTest();
return;
}
// domwindowopened
win.addEventListener("load", function onLoad(event) {
win.removeEventListener("load", onLoad, false);
// Let the dialog initialize
SimpleTest.executeSoon(function() {
checkWindow(win);
});
}, false);
}
};
function init() {
ww.registerNotification(windowObserver);
loadNextTest();
}
function loadNextTest() {
if (!tests[++testIndex]) {
ww.unregisterNotification(windowObserver);
SimpleTest.finish();
return;
}
let frame = document.getElementById("testframe");
frame.setAttribute("src", tests[testIndex].url);
}
function checkWindow(win) {
for (let [id, props] of Object.entries(tests[testIndex].elements)) {
let elem = win.dialog.dialogElement(id);
for (let [prop, value] of Object.entries(props)) {
is(elem[prop], value,
"Element with id " + id + " has property " +
prop + " set to " + value);
}
}
win.document.documentElement.cancelDialog();
}
]]>
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display:none;"></div>
<pre id="test"></pre>
</body>
<iframe xmlns="http://www.w3.org/1999/xhtml"
id="testframe">
</iframe>
</window>
|