1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_pluginstream_err.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=517078 1.8 + 1.9 +Tests for plugin stream error conditions. 1.10 +--> 1.11 +<head> 1.12 + <title>NPAPI Stream Error Tests</title> 1.13 + <script type="text/javascript" 1.14 + src="/tests/SimpleTest/SimpleTest.js"></script> 1.15 + <script type="text/javascript" src="utils.js"></script> 1.16 + <link rel="stylesheet" type="text/css" 1.17 + href="/tests/SimpleTest/test.css" /> 1.18 +</head> 1.19 +<body onload="runNextTest()"> 1.20 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=517078"> 1.21 + Mozilla Bug 517078</a> - Plugin Stream Error Tests 1.22 +<p id="display"></p> 1.23 +<div id="content" style="display: none"> 1.24 + 1.25 +</div> 1.26 +<div id="test"> 1.27 +<script class="testbody" type="text/javascript"> 1.28 +//// 1.29 +// These tests verify that nothing "bad" happens when a plugin returns an 1.30 +// error from one of the NPP_ stream functions. "Bad" is defined here 1.31 +// as the plugin being terminated, or NPP_ stream functions being 1.32 +// called inappropriately by the browser after the plugin has returned 1.33 +// a stream error. 1.34 +// 1.35 + 1.36 +function $(id) { return document.getElementById(id); } 1.37 + 1.38 +SimpleTest.waitForExplicitFinish(); 1.39 +setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED); 1.40 + 1.41 + 1.42 +var tests = [ 1.43 + { 1.44 + "src": "loremipsum.txt", 1.45 + "streammode": "normal", 1.46 + "functiontofail": "npp_newstream", 1.47 + "failurecode": "1", 1.48 + "frame": "testframe" 1.49 + }, 1.50 + { 1.51 + "src": "loremipsum.txt", 1.52 + "streammode": "normal", 1.53 + "functiontofail": "npp_newstream", 1.54 + "failurecode": "3", 1.55 + "frame": "testframe" 1.56 + }, 1.57 + { 1.58 + "src": "loremipsum.txt", 1.59 + "streammode": "normal", 1.60 + "functiontofail": "npp_newstream", 1.61 + "failurecode": "5", 1.62 + "frame": "testframe" 1.63 + }, 1.64 + { 1.65 + "geturl": "loremipsum.txt", 1.66 + "streammode": "normal", 1.67 + "functiontofail": "npp_newstream", 1.68 + "failurecode": "1", 1.69 + "frame": "testframe" 1.70 + }, 1.71 + { 1.72 + "src": "loremipsum.txt", 1.73 + "streammode": "normal", 1.74 + "functiontofail": "npp_write", 1.75 + "frame": "testframe" 1.76 + }, 1.77 + { 1.78 + "src": "loremipsum.txt", 1.79 + "streammode": "asfile", 1.80 + "functiontofail": "npp_write", 1.81 + "frame": "testframe" 1.82 + }, 1.83 + { 1.84 + "src": "loremipsum.txt", 1.85 + "streammode": "normal", 1.86 + "functiontofail": "npp_destroystream", 1.87 + "failurecode": "1", 1.88 + "frame": "testframe" 1.89 + }, 1.90 +]; 1.91 + 1.92 +function iframeonload(evt) { 1.93 + var contentLength = evt.target.contentDocument.body.innerHTML.length; 1.94 + var plugin = gTestWindow.document.getElementById("embedtest"); 1.95 + var functionToFail = plugin.getAttribute("functiontofail"); 1.96 + if (contentLength > 0) { 1.97 + is(evt.target.contentDocument.body.innerHTML, "pass", 1.98 + "test frame has unexpected content"); 1.99 + setTimeout(function() { 1.100 + // This verifies that the plugin hasn't been unloaded, and that 1.101 + // no calls to NPP_ functions have been made unexpectedly. 1.102 + is(plugin.getError(), "pass", "plugin reported an error"); 1.103 + gTestWindow.close(); 1.104 + setTimeout(runNextTest, 10); 1.105 + }, functionToFail == "npp_newstream" ? 500 : 10); 1.106 + } 1.107 +} 1.108 + 1.109 +var index = 0; 1.110 +var gTestWindow; 1.111 +function runNextTest() { 1.112 + if (index == tests.length * 2) { 1.113 + SimpleTest.finish(); 1.114 + return; 1.115 + } 1.116 + 1.117 + gTestWindow = window.open("plugin_window.html", 1.118 + "", 1.119 + "width=620,height=320"); 1.120 +} 1.121 + 1.122 +function continueTest() { 1.123 + // We run each test as an embed and an object, as their initial stream 1.124 + // handling differs. 1.125 + var tag = index % 2 ? "embed" : "object"; 1.126 + var test = tests[Math.floor(index / 2)]; 1.127 + 1.128 + var p = gTestWindow.document.createElement("p"); 1.129 + p.innerHTML = "Plugin Stream Test " + index; 1.130 + gTestWindow.document.getElementById("test").appendChild(p); 1.131 + 1.132 + if (test.frame) { 1.133 + var iframe = gTestWindow.document.createElement("iframe"); 1.134 + iframe.name = test.frame; 1.135 + iframe.onload = iframeonload; 1.136 + gTestWindow.document.getElementById("test").appendChild(iframe); 1.137 + } 1.138 + 1.139 + var plugin = gTestWindow.document.createElement(tag); 1.140 + plugin.setAttribute("id", "embedtest"); 1.141 + plugin.setAttribute("style", "width: 400px; height: 100px;"); 1.142 + plugin.setAttribute("type", "application/x-test"); 1.143 + for (var name in test) { 1.144 + if (tag == "embed") { 1.145 + plugin.setAttribute(name, test[name]); 1.146 + } else if (name == "src") { 1.147 + plugin.setAttribute("data", test[name]); 1.148 + } else { 1.149 + var param = document.createElement("param"); 1.150 + param.name = name; 1.151 + param.value = test[name]; 1.152 + plugin.appendChild(param); 1.153 + } 1.154 + } 1.155 + gTestWindow.document.getElementById("test").appendChild(plugin); 1.156 + 1.157 + gTestWindow.document.getElementById("test") 1.158 + .appendChild(document.createElement("br")); 1.159 + 1.160 + index++; 1.161 +} 1.162 + 1.163 +</script> 1.164 +</div> 1.165 +</body> 1.166 +</html> 1.167 +