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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
function runTest() {
let frameUrl = SimpleTest.getTestFileURL('/file_empty.html');
SpecialPowers.pushPermissions([{
type: 'browser:embedded-system-app',
allow: true,
context: {
url: frameUrl,
originAttributes: {
inIsolatedMozBrowser: true
}
}
},{
type: 'browser',
allow: true,
context: {
url: frameUrl,
originAttributes: {
inIsolatedMozBrowser: true
}
}
}], createFrame);
}
var frame;
var mm;
function createFrame() {
let loadEnd = function() {
// The frame script running in the frame where the input is hosted.
let appFrameScript = function appFrameScript() {
let i = 1;
addMessageListener('test:next', function() {
try {
switch (i) {
case 1:
content.document.addEventListener(
'visibilitychange', function fn() {
content.document.removeEventListener('visibilitychange', fn);
sendAsyncMessage('test:done', {
ok: true,
msg: 'setVisible()'
});
});
// Test a no return method
content.navigator.mozBrowserElementProxy.setVisible(false);
break;
case 2:
// Test a DOMRequest method
var req = content.navigator.mozBrowserElementProxy.getVisible();
req.onsuccess = function() {
sendAsyncMessage('test:done', {
ok: true,
msg: 'getVisible()'
});
};
req.onerror = function() {
sendAsyncMessage('test:done', {
ok: false,
msg: 'getVisible() DOMRequest return error.'
});
};
break;
case 3:
// Test an unimplemented method
try {
content.navigator.mozBrowserElementProxy.getActive();
sendAsyncMessage('test:done', {
ok: false,
msg: 'getActive() should throw.'
});
} catch (e) {
sendAsyncMessage('test:done', {
ok: true,
msg: 'getActive() throws.'
});
}
break;
case 4:
content.navigator.mozBrowserElementProxy
.addEventListener(
'mozbrowserlocationchange',
function() {
content.navigator.mozBrowserElementProxy
.onmozbrowserlocationchange = null;
sendAsyncMessage('test:done', {
ok: true,
msg: 'mozbrowserlocationchange'
});
});
// Test event
content.location.hash = '#foo';
break;
}
} catch (e) {
sendAsyncMessage('test:done', {
ok: false, msg: 'thrown: ' + e.toString() });
}
i++;
});
sendAsyncMessage('test:done', {});
}
mm = SpecialPowers.getBrowserFrameMessageManager(frame);
mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false);
mm.addMessageListener("test:done", next);
};
frame = document.createElement('iframe');
frame.setAttribute('mozbrowser', 'true');
frame.src = 'file_empty.html';
document.body.appendChild(frame);
frame.addEventListener('mozbrowserloadend', loadEnd);
}
var i = 0;
function next(msg) {
let wrappedMsg = SpecialPowers.wrap(msg);
let isOK = wrappedMsg.data.ok;
let msgString = wrappedMsg.data.msg;
switch (i) {
case 0:
mm.sendAsyncMessage('test:next');
break;
case 1:
case 2:
case 3:
ok(isOK, msgString);
mm.sendAsyncMessage('test:next');
break;
case 4:
ok(isOK, msgString);
SimpleTest.finish();
break;
}
i++;
}
addEventListener('testready', runTest);
|