dom/plugins/test/mochitest/test_pluginstream_err.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial