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
164
165
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=517078
Tests for plugin stream error conditions.
-->
<head>
<title>NPAPI Stream Error Tests</title>
<script type="text/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="plugin-utils.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css" />
</head>
<body onload="runNextTest()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517078">
Mozilla Bug 517078</a> - Plugin Stream Error Tests
<p id="display"></p>
<div id="content" style="display: none">
</div>
<div id="test">
<script class="testbody" type="text/javascript">
////
// These tests verify that nothing "bad" happens when a plugin returns an
// error from one of the NPP_ stream functions. "Bad" is defined here
// as the plugin being terminated, or NPP_ stream functions being
// called inappropriately by the browser after the plugin has returned
// a stream error.
//
function $(id) { return document.getElementById(id); }
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
var tests = [
{
"src": "loremipsum.txt",
"streammode": "normal",
"functiontofail": "npp_newstream",
"failurecode": "1",
"frame": "testframe"
},
{
"src": "loremipsum.txt",
"streammode": "normal",
"functiontofail": "npp_newstream",
"failurecode": "3",
"frame": "testframe"
},
{
"src": "loremipsum.txt",
"streammode": "normal",
"functiontofail": "npp_newstream",
"failurecode": "5",
"frame": "testframe"
},
{
"geturl": "loremipsum.txt",
"streammode": "normal",
"functiontofail": "npp_newstream",
"failurecode": "1",
"frame": "testframe"
},
{
"src": "loremipsum.txt",
"streammode": "normal",
"functiontofail": "npp_write",
"frame": "testframe"
},
{
"src": "loremipsum.txt",
"streammode": "asfile",
"functiontofail": "npp_write",
"frame": "testframe"
},
{
"src": "loremipsum.txt",
"streammode": "normal",
"functiontofail": "npp_destroystream",
"failurecode": "1",
"frame": "testframe"
},
];
function iframeonload(evt) {
var contentLength = evt.target.contentDocument.body.innerHTML.length;
var plugin = gTestWindow.document.getElementById("embedtest");
var functionToFail = plugin.getAttribute("functiontofail");
if (contentLength > 0) {
is(evt.target.contentDocument.body.innerHTML, "pass",
"test frame has unexpected content");
setTimeout(function() {
// This verifies that the plugin hasn't been unloaded, and that
// no calls to NPP_ functions have been made unexpectedly.
is(plugin.getError(), "pass", "plugin reported an error");
gTestWindow.close();
setTimeout(runNextTest, 10);
}, functionToFail == "npp_newstream" ? 500 : 10);
}
}
var index = 0;
var gTestWindow;
function runNextTest() {
if (index == tests.length * 2) {
SimpleTest.finish();
return;
}
gTestWindow = window.open("plugin_window.html",
"",
"width=620,height=320");
}
function continueTest() {
// We run each test as an embed and an object, as their initial stream
// handling differs.
var tag = index % 2 ? "embed" : "object";
var test = tests[Math.floor(index / 2)];
var p = gTestWindow.document.createElement("p");
p.innerHTML = "Plugin Stream Test " + index;
gTestWindow.document.getElementById("test").appendChild(p);
if (test.frame) {
var iframe = gTestWindow.document.createElement("iframe");
iframe.name = test.frame;
iframe.onload = iframeonload;
gTestWindow.document.getElementById("test").appendChild(iframe);
}
var plugin = gTestWindow.document.createElement(tag);
plugin.setAttribute("id", "embedtest");
plugin.setAttribute("style", "width: 400px; height: 100px;");
plugin.setAttribute("type", "application/x-test");
for (var name in test) {
if (tag == "embed") {
plugin.setAttribute(name, test[name]);
} else if (name == "src") {
plugin.setAttribute("data", test[name]);
} else {
var param = document.createElement("param");
param.name = name;
param.value = test[name];
plugin.appendChild(param);
}
}
gTestWindow.document.getElementById("test").appendChild(plugin);
gTestWindow.document.getElementById("test")
.appendChild(document.createElement("br"));
index++;
}
</script>
</div>
</body>
</html>
|