Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=517078
6 Tests for plugin stream error conditions.
7 -->
8 <head>
9 <title>NPAPI Stream Error Tests</title>
10 <script type="text/javascript"
11 src="/tests/SimpleTest/SimpleTest.js"></script>
12 <script type="text/javascript" src="utils.js"></script>
13 <link rel="stylesheet" type="text/css"
14 href="/tests/SimpleTest/test.css" />
15 </head>
16 <body onload="runNextTest()">
17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517078">
18 Mozilla Bug 517078</a> - Plugin Stream Error Tests
19 <p id="display"></p>
20 <div id="content" style="display: none">
22 </div>
23 <div id="test">
24 <script class="testbody" type="text/javascript">
25 ////
26 // These tests verify that nothing "bad" happens when a plugin returns an
27 // error from one of the NPP_ stream functions. "Bad" is defined here
28 // as the plugin being terminated, or NPP_ stream functions being
29 // called inappropriately by the browser after the plugin has returned
30 // a stream error.
31 //
33 function $(id) { return document.getElementById(id); }
35 SimpleTest.waitForExplicitFinish();
36 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
39 var tests = [
40 {
41 "src": "loremipsum.txt",
42 "streammode": "normal",
43 "functiontofail": "npp_newstream",
44 "failurecode": "1",
45 "frame": "testframe"
46 },
47 {
48 "src": "loremipsum.txt",
49 "streammode": "normal",
50 "functiontofail": "npp_newstream",
51 "failurecode": "3",
52 "frame": "testframe"
53 },
54 {
55 "src": "loremipsum.txt",
56 "streammode": "normal",
57 "functiontofail": "npp_newstream",
58 "failurecode": "5",
59 "frame": "testframe"
60 },
61 {
62 "geturl": "loremipsum.txt",
63 "streammode": "normal",
64 "functiontofail": "npp_newstream",
65 "failurecode": "1",
66 "frame": "testframe"
67 },
68 {
69 "src": "loremipsum.txt",
70 "streammode": "normal",
71 "functiontofail": "npp_write",
72 "frame": "testframe"
73 },
74 {
75 "src": "loremipsum.txt",
76 "streammode": "asfile",
77 "functiontofail": "npp_write",
78 "frame": "testframe"
79 },
80 {
81 "src": "loremipsum.txt",
82 "streammode": "normal",
83 "functiontofail": "npp_destroystream",
84 "failurecode": "1",
85 "frame": "testframe"
86 },
87 ];
89 function iframeonload(evt) {
90 var contentLength = evt.target.contentDocument.body.innerHTML.length;
91 var plugin = gTestWindow.document.getElementById("embedtest");
92 var functionToFail = plugin.getAttribute("functiontofail");
93 if (contentLength > 0) {
94 is(evt.target.contentDocument.body.innerHTML, "pass",
95 "test frame has unexpected content");
96 setTimeout(function() {
97 // This verifies that the plugin hasn't been unloaded, and that
98 // no calls to NPP_ functions have been made unexpectedly.
99 is(plugin.getError(), "pass", "plugin reported an error");
100 gTestWindow.close();
101 setTimeout(runNextTest, 10);
102 }, functionToFail == "npp_newstream" ? 500 : 10);
103 }
104 }
106 var index = 0;
107 var gTestWindow;
108 function runNextTest() {
109 if (index == tests.length * 2) {
110 SimpleTest.finish();
111 return;
112 }
114 gTestWindow = window.open("plugin_window.html",
115 "",
116 "width=620,height=320");
117 }
119 function continueTest() {
120 // We run each test as an embed and an object, as their initial stream
121 // handling differs.
122 var tag = index % 2 ? "embed" : "object";
123 var test = tests[Math.floor(index / 2)];
125 var p = gTestWindow.document.createElement("p");
126 p.innerHTML = "Plugin Stream Test " + index;
127 gTestWindow.document.getElementById("test").appendChild(p);
129 if (test.frame) {
130 var iframe = gTestWindow.document.createElement("iframe");
131 iframe.name = test.frame;
132 iframe.onload = iframeonload;
133 gTestWindow.document.getElementById("test").appendChild(iframe);
134 }
136 var plugin = gTestWindow.document.createElement(tag);
137 plugin.setAttribute("id", "embedtest");
138 plugin.setAttribute("style", "width: 400px; height: 100px;");
139 plugin.setAttribute("type", "application/x-test");
140 for (var name in test) {
141 if (tag == "embed") {
142 plugin.setAttribute(name, test[name]);
143 } else if (name == "src") {
144 plugin.setAttribute("data", test[name]);
145 } else {
146 var param = document.createElement("param");
147 param.name = name;
148 param.value = test[name];
149 plugin.appendChild(param);
150 }
151 }
152 gTestWindow.document.getElementById("test").appendChild(plugin);
154 gTestWindow.document.getElementById("test")
155 .appendChild(document.createElement("br"));
157 index++;
158 }
160 </script>
161 </div>
162 </body>
163 </html>