dom/plugins/test/mochitest/test_hangui.xul

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 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
michael@0 4 type="text/css"?>
michael@0 5 <window title="Basic Plugin Tests"
michael@0 6 xmlns:html="http://www.w3.org/1999/xhtml"
michael@0 7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 8 <title>Plugin Hang UI Test</title>
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
michael@0 11 <script type="application/javascript"
michael@0 12 src="utils.js" />
michael@0 13 <script type="application/javascript"
michael@0 14 src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hang_test.js" />
michael@0 15 <script type="application/javascript"
michael@0 16 src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hangui_common.js" />
michael@0 17
michael@0 18 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 19 <iframe id="iframe1" src="hangui_subpage.html" width="400" height="400"></iframe>
michael@0 20 </body>
michael@0 21 <script class="testbody" type="application/javascript">
michael@0 22 <![CDATA[
michael@0 23 SimpleTest.waitForExplicitFinish();
michael@0 24 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
michael@0 25
michael@0 26 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 27
michael@0 28 const hangUITimeoutPref = "dom.ipc.plugins.hangUITimeoutSecs";
michael@0 29 const hangUIMinDisplayPref = "dom.ipc.plugins.hangUIMinDisplaySecs";
michael@0 30 const timeoutPref = "dom.ipc.plugins.timeoutSecs";
michael@0 31
michael@0 32 var worker = new ChromeWorker("hangui_iface.js");
michael@0 33 worker.onmessage = function(event) {
michael@0 34 var result = event.data;
michael@0 35 var params = result.params;
michael@0 36 var output = params.testName;
michael@0 37 if (result.msg) {
michael@0 38 output += ": " + result.msg;
michael@0 39 }
michael@0 40 ok(result.status, output);
michael@0 41 if (params.callback) {
michael@0 42 var cb = eval(params.callback);
michael@0 43 var timeout = setTimeout(function() { clearTimeout(timeout); cb(); }, 100);
michael@0 44 }
michael@0 45 };
michael@0 46 worker.onerror = function(event) {
michael@0 47 var output = "Error: " + event.message + " at " + event.filename + ":" + event.lineno;
michael@0 48 ok(false, output);
michael@0 49 };
michael@0 50
michael@0 51 var iframe;
michael@0 52 var p;
michael@0 53 var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
michael@0 54
michael@0 55 function hanguiOperation(testName, timeoutSec, expectFind, expectClose, opCode,
michael@0 56 commandId, check, cb) {
michael@0 57 var timeoutMs = timeoutSec * 1000 + EPSILON_MS;
michael@0 58 worker.postMessage({ "timeoutMs": timeoutMs, "expectToFind": expectFind,
michael@0 59 "expectToClose": expectClose, "opCode": opCode,
michael@0 60 "commandId": commandId, "check": check,
michael@0 61 "testName": testName, "callback": cb });
michael@0 62 }
michael@0 63
michael@0 64 function hanguiExpect(testName, shouldBeShowing, shouldClose, cb) {
michael@0 65 var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
michael@0 66 if (!shouldBeShowing && !timeoutSec) {
michael@0 67 timeoutSec = Services.prefs.getIntPref(timeoutPref);
michael@0 68 }
michael@0 69 hanguiOperation(testName, timeoutSec, shouldBeShowing, shouldClose, HANGUIOP_NOTHING, 0, false, cb);
michael@0 70 }
michael@0 71
michael@0 72 function hanguiContinue(testName, check, cb) {
michael@0 73 var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
michael@0 74 hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_COMMAND, IDC_CONTINUE, check, cb);
michael@0 75 }
michael@0 76
michael@0 77 function hanguiStop(testName, check, cb) {
michael@0 78 var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
michael@0 79 hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_COMMAND, IDC_STOP, check, cb);
michael@0 80 }
michael@0 81
michael@0 82 function hanguiCancel(testName, cb) {
michael@0 83 var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
michael@0 84 hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_CANCEL, 0, false, cb);
michael@0 85 }
michael@0 86
michael@0 87 function finishTest() {
michael@0 88 if (obsCount > 0) {
michael@0 89 os.removeObserver(testObserver, "plugin-crashed");
michael@0 90 --obsCount;
michael@0 91 }
michael@0 92 SpecialPowers.clearUserPref(hangUITimeoutPref);
michael@0 93 SpecialPowers.clearUserPref(hangUIMinDisplayPref);
michael@0 94 SpecialPowers.clearUserPref(timeoutPref);
michael@0 95 SimpleTest.finish();
michael@0 96 }
michael@0 97
michael@0 98 function runTests() {
michael@0 99 if (!SimpleTest.testPluginIsOOP()) {
michael@0 100 ok(true, "Skipping this test when test plugin is not OOP.");
michael@0 101 SimpleTest.finish();
michael@0 102 }
michael@0 103
michael@0 104 resetVars();
michael@0 105
michael@0 106 hanguiOperation("Prime ChromeWorker", 0, false, false, HANGUIOP_NOTHING, 0,
michael@0 107 false, "test1");
michael@0 108 }
michael@0 109
michael@0 110 window.frameLoaded = runTests;
michael@0 111
michael@0 112 var obsCount = 0;
michael@0 113
michael@0 114 function onPluginCrashedHangUI(aEvent) {
michael@0 115 ok(true, "Plugin crashed notification received");
michael@0 116 is(aEvent.type, "PluginCrashed", "event is correct type");
michael@0 117
michael@0 118 is(p, aEvent.target, "Plugin crashed event target is plugin element");
michael@0 119
michael@0 120 ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
michael@0 121 "plugin crashed event has the right interface");
michael@0 122
michael@0 123 var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
michael@0 124 var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
michael@0 125 isnot(pluginDumpID, "", "got a non-empty dump ID");
michael@0 126 var pluginName = propBag.getPropertyAsAString("pluginName");
michael@0 127 is(pluginName, "Test Plug-in", "got correct plugin name");
michael@0 128 var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
michael@0 129 isnot(pluginFilename, "", "got a non-empty filename");
michael@0 130 var didReport = propBag.getPropertyAsBool("submittedCrashReport");
michael@0 131 // The app itself may or may not have decided to submit the report, so
michael@0 132 // allow either true or false here.
michael@0 133 ok((didReport == true || didReport == false), "event said crash report was submitted");
michael@0 134 os.removeObserver(testObserver, "plugin-crashed");
michael@0 135 --obsCount;
michael@0 136 }
michael@0 137
michael@0 138 function resetVars() {
michael@0 139 iframe = document.getElementById('iframe1');
michael@0 140 p = iframe.contentDocument.getElementById("plugin1");
michael@0 141 if (obsCount == 0) {
michael@0 142 os.addObserver(testObserver, "plugin-crashed", true);
michael@0 143 ++obsCount;
michael@0 144 }
michael@0 145 iframe.contentDocument.addEventListener("PluginCrashed",
michael@0 146 onPluginCrashedHangUI,
michael@0 147 false);
michael@0 148 }
michael@0 149
michael@0 150 function test9b() {
michael@0 151 hanguiExpect("test9b: Plugin Hang UI is not showing (checkbox)", false);
michael@0 152 p.stall(STALL_DURATION);
michael@0 153 hanguiExpect("test9b: Plugin Hang UI is still not showing (checkbox)", false, false, "finishTest");
michael@0 154 p.stall(STALL_DURATION);
michael@0 155 }
michael@0 156
michael@0 157 function test9a() {
michael@0 158 resetVars();
michael@0 159 SpecialPowers.setIntPref(hangUITimeoutPref, 1);
michael@0 160 SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
michael@0 161 SpecialPowers.setIntPref(timeoutPref, 45);
michael@0 162 hanguiContinue("test9a: Continue button works with checkbox", true, "test9b");
michael@0 163 p.stall(STALL_DURATION);
michael@0 164 }
michael@0 165
michael@0 166 function test9() {
michael@0 167 window.frameLoaded = test9a;
michael@0 168 iframe.contentWindow.location.reload();
michael@0 169 }
michael@0 170
michael@0 171 function test8a() {
michael@0 172 resetVars();
michael@0 173 SpecialPowers.setIntPref(hangUITimeoutPref, 1);
michael@0 174 SpecialPowers.setIntPref(hangUIMinDisplayPref, 4);
michael@0 175 hanguiExpect("test8a: Plugin Hang UI is not showing (disabled due to hangUIMinDisplaySecs)", false, false, "test9");
michael@0 176 var exceptionThrown = false;
michael@0 177 try {
michael@0 178 p.hang();
michael@0 179 } catch(e) {
michael@0 180 exceptionThrown = true;
michael@0 181 }
michael@0 182 ok(exceptionThrown, "test8a: Exception thrown from hang() when plugin was terminated");
michael@0 183 }
michael@0 184
michael@0 185 function test8() {
michael@0 186 window.frameLoaded = test8a;
michael@0 187 iframe.contentWindow.location.reload();
michael@0 188 }
michael@0 189
michael@0 190 function test7a() {
michael@0 191 resetVars();
michael@0 192 SpecialPowers.setIntPref(hangUITimeoutPref, 0);
michael@0 193 hanguiExpect("test7a: Plugin Hang UI is not showing (disabled)", false, false, "test8");
michael@0 194 var exceptionThrown = false;
michael@0 195 try {
michael@0 196 p.hang();
michael@0 197 } catch(e) {
michael@0 198 exceptionThrown = true;
michael@0 199 }
michael@0 200 ok(exceptionThrown, "test7a: Exception thrown from hang() when plugin was terminated");
michael@0 201 }
michael@0 202
michael@0 203 function test7() {
michael@0 204 window.frameLoaded = test7a;
michael@0 205 iframe.contentWindow.location.reload();
michael@0 206 }
michael@0 207
michael@0 208 function test6() {
michael@0 209 SpecialPowers.setIntPref(hangUITimeoutPref, 1);
michael@0 210 SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
michael@0 211 SpecialPowers.setIntPref(timeoutPref, 3);
michael@0 212 hanguiExpect("test6: Plugin Hang UI is showing", true, true, "test7");
michael@0 213 var exceptionThrown = false;
michael@0 214 try {
michael@0 215 p.hang();
michael@0 216 } catch(e) {
michael@0 217 exceptionThrown = true;
michael@0 218 }
michael@0 219 ok(exceptionThrown, "test6: Exception thrown from hang() when plugin was terminated (child timeout)");
michael@0 220 }
michael@0 221
michael@0 222 function test5a() {
michael@0 223 resetVars();
michael@0 224 hanguiCancel("test5a: Close button works", "test6");
michael@0 225 p.stall(STALL_DURATION);
michael@0 226 }
michael@0 227
michael@0 228 function test5() {
michael@0 229 window.frameLoaded = test5a;
michael@0 230 iframe.contentWindow.location.reload();
michael@0 231 }
michael@0 232
michael@0 233 function test4() {
michael@0 234 hanguiStop("test4: Stop button works", false, "test5");
michael@0 235 // We'll get an exception here because the plugin was terminated
michael@0 236 var exceptionThrown = false;
michael@0 237 try {
michael@0 238 p.hang();
michael@0 239 } catch(e) {
michael@0 240 exceptionThrown = true;
michael@0 241 }
michael@0 242 ok(exceptionThrown, "test4: Exception thrown from hang() when plugin was terminated");
michael@0 243 }
michael@0 244
michael@0 245 function test3() {
michael@0 246 hanguiContinue("test3: Continue button works", false, "test4");
michael@0 247 p.stall(STALL_DURATION);
michael@0 248 }
michael@0 249
michael@0 250 function test2() {
michael@0 251 // This test is identical to test1 because there were some bugs where the
michael@0 252 // Hang UI would show on the first hang but not on subsequent hangs
michael@0 253 hanguiExpect("test2: Plugin Hang UI is showing", true, true, "test3");
michael@0 254 p.stall(STALL_DURATION);
michael@0 255 }
michael@0 256
michael@0 257 function test1() {
michael@0 258 SpecialPowers.setIntPref(hangUITimeoutPref, 1);
michael@0 259 SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
michael@0 260 SpecialPowers.setIntPref(timeoutPref, 45);
michael@0 261 hanguiExpect("test1: Plugin Hang UI is showing", true, true, "test2");
michael@0 262 p.stall(STALL_DURATION);
michael@0 263 }
michael@0 264
michael@0 265 ]]>
michael@0 266 </script>
michael@0 267 </window>

mercurial