dom/plugins/test/mochitest/test_hangui.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_hangui.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,267 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     1.7 +                 type="text/css"?>
     1.8 +<window title="Basic Plugin Tests"
     1.9 +  xmlns:html="http://www.w3.org/1999/xhtml"
    1.10 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +  <title>Plugin Hang UI Test</title>
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    1.14 +  <script type="application/javascript"
    1.15 +          src="utils.js" />
    1.16 +  <script type="application/javascript"
    1.17 +          src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hang_test.js" />
    1.18 +  <script type="application/javascript"
    1.19 +          src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hangui_common.js" />
    1.20 +
    1.21 +<body xmlns="http://www.w3.org/1999/xhtml">
    1.22 +  <iframe id="iframe1" src="hangui_subpage.html" width="400" height="400"></iframe>
    1.23 +</body>
    1.24 +<script class="testbody" type="application/javascript">
    1.25 +<![CDATA[
    1.26 +SimpleTest.waitForExplicitFinish();
    1.27 +setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    1.28 +
    1.29 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.30 +
    1.31 +const hangUITimeoutPref = "dom.ipc.plugins.hangUITimeoutSecs";
    1.32 +const hangUIMinDisplayPref = "dom.ipc.plugins.hangUIMinDisplaySecs";
    1.33 +const timeoutPref = "dom.ipc.plugins.timeoutSecs";
    1.34 +
    1.35 +var worker = new ChromeWorker("hangui_iface.js");
    1.36 +worker.onmessage = function(event) {
    1.37 +  var result = event.data;
    1.38 +  var params = result.params;
    1.39 +  var output = params.testName;
    1.40 +  if (result.msg) {
    1.41 +    output += ": " + result.msg;
    1.42 +  }
    1.43 +  ok(result.status, output);
    1.44 +  if (params.callback) {
    1.45 +    var cb = eval(params.callback);
    1.46 +    var timeout = setTimeout(function() { clearTimeout(timeout); cb(); }, 100);
    1.47 +  }
    1.48 +};
    1.49 +worker.onerror = function(event) {
    1.50 +  var output = "Error: " + event.message + " at " + event.filename + ":" + event.lineno;
    1.51 +  ok(false, output);
    1.52 +};
    1.53 +
    1.54 +var iframe;
    1.55 +var p;
    1.56 +var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
    1.57 +
    1.58 +function hanguiOperation(testName, timeoutSec, expectFind, expectClose, opCode,
    1.59 +                         commandId, check, cb) {
    1.60 +  var timeoutMs = timeoutSec * 1000 + EPSILON_MS;
    1.61 +  worker.postMessage({ "timeoutMs": timeoutMs, "expectToFind": expectFind,
    1.62 +                       "expectToClose": expectClose, "opCode": opCode,
    1.63 +                       "commandId": commandId, "check": check,
    1.64 +                       "testName": testName, "callback": cb });
    1.65 +}
    1.66 +
    1.67 +function hanguiExpect(testName, shouldBeShowing, shouldClose, cb) {
    1.68 +  var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    1.69 +  if (!shouldBeShowing && !timeoutSec) {
    1.70 +    timeoutSec = Services.prefs.getIntPref(timeoutPref);
    1.71 +  }
    1.72 +  hanguiOperation(testName, timeoutSec, shouldBeShowing, shouldClose, HANGUIOP_NOTHING, 0, false, cb);
    1.73 +}
    1.74 +
    1.75 +function hanguiContinue(testName, check, cb) {
    1.76 +  var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    1.77 +  hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_COMMAND, IDC_CONTINUE, check, cb);
    1.78 +}
    1.79 +
    1.80 +function hanguiStop(testName, check, cb) {
    1.81 +  var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    1.82 +  hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_COMMAND, IDC_STOP, check, cb);
    1.83 +}
    1.84 +
    1.85 +function hanguiCancel(testName, cb) {
    1.86 +  var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    1.87 +  hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_CANCEL, 0, false, cb);
    1.88 +}
    1.89 +
    1.90 +function finishTest() {
    1.91 +  if (obsCount > 0) {
    1.92 +    os.removeObserver(testObserver, "plugin-crashed");
    1.93 +    --obsCount;
    1.94 +  }
    1.95 +  SpecialPowers.clearUserPref(hangUITimeoutPref);
    1.96 +  SpecialPowers.clearUserPref(hangUIMinDisplayPref);
    1.97 +  SpecialPowers.clearUserPref(timeoutPref);
    1.98 +  SimpleTest.finish();
    1.99 +}
   1.100 +
   1.101 +function runTests() {
   1.102 +  if (!SimpleTest.testPluginIsOOP()) {
   1.103 +    ok(true, "Skipping this test when test plugin is not OOP.");
   1.104 +    SimpleTest.finish();
   1.105 +  }
   1.106 +
   1.107 +  resetVars();
   1.108 +
   1.109 +  hanguiOperation("Prime ChromeWorker", 0, false, false, HANGUIOP_NOTHING, 0,
   1.110 +                  false, "test1");
   1.111 +}
   1.112 +
   1.113 +window.frameLoaded = runTests;
   1.114 +
   1.115 +var obsCount = 0;
   1.116 +
   1.117 +function onPluginCrashedHangUI(aEvent) {
   1.118 +  ok(true, "Plugin crashed notification received");
   1.119 +  is(aEvent.type, "PluginCrashed", "event is correct type");
   1.120 +
   1.121 +  is(p, aEvent.target, "Plugin crashed event target is plugin element");
   1.122 +
   1.123 +  ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
   1.124 +     "plugin crashed event has the right interface");
   1.125 +
   1.126 +  var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
   1.127 +  var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
   1.128 +  isnot(pluginDumpID, "", "got a non-empty dump ID");
   1.129 +  var pluginName = propBag.getPropertyAsAString("pluginName");
   1.130 +  is(pluginName, "Test Plug-in", "got correct plugin name");
   1.131 +  var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
   1.132 +  isnot(pluginFilename, "", "got a non-empty filename");
   1.133 +  var didReport = propBag.getPropertyAsBool("submittedCrashReport");
   1.134 +  // The app itself may or may not have decided to submit the report, so
   1.135 +  // allow either true or false here.
   1.136 +  ok((didReport == true || didReport == false), "event said crash report was submitted");
   1.137 +  os.removeObserver(testObserver, "plugin-crashed");
   1.138 +  --obsCount;
   1.139 +}
   1.140 +
   1.141 +function resetVars() {
   1.142 +  iframe = document.getElementById('iframe1');
   1.143 +  p = iframe.contentDocument.getElementById("plugin1");
   1.144 +  if (obsCount == 0) {
   1.145 +    os.addObserver(testObserver, "plugin-crashed", true);
   1.146 +    ++obsCount;
   1.147 +  }
   1.148 +  iframe.contentDocument.addEventListener("PluginCrashed",
   1.149 +                                          onPluginCrashedHangUI,
   1.150 +                                          false);
   1.151 +}
   1.152 +
   1.153 +function test9b() {
   1.154 +  hanguiExpect("test9b: Plugin Hang UI is not showing (checkbox)", false);
   1.155 +  p.stall(STALL_DURATION);
   1.156 +  hanguiExpect("test9b: Plugin Hang UI is still not showing (checkbox)", false, false, "finishTest");
   1.157 +  p.stall(STALL_DURATION);
   1.158 +}
   1.159 +
   1.160 +function test9a() {
   1.161 +  resetVars();
   1.162 +  SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   1.163 +  SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
   1.164 +  SpecialPowers.setIntPref(timeoutPref, 45);
   1.165 +  hanguiContinue("test9a: Continue button works with checkbox", true, "test9b");
   1.166 +  p.stall(STALL_DURATION);
   1.167 +}
   1.168 +
   1.169 +function test9() {
   1.170 +  window.frameLoaded = test9a;
   1.171 +  iframe.contentWindow.location.reload();
   1.172 +}
   1.173 +
   1.174 +function test8a() {
   1.175 +  resetVars();
   1.176 +  SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   1.177 +  SpecialPowers.setIntPref(hangUIMinDisplayPref, 4);
   1.178 +  hanguiExpect("test8a: Plugin Hang UI is not showing (disabled due to hangUIMinDisplaySecs)", false, false, "test9");
   1.179 +  var exceptionThrown = false;
   1.180 +  try {
   1.181 +    p.hang();
   1.182 +  } catch(e) {
   1.183 +    exceptionThrown = true;
   1.184 +  }
   1.185 +  ok(exceptionThrown, "test8a: Exception thrown from hang() when plugin was terminated");
   1.186 +}
   1.187 +
   1.188 +function test8() {
   1.189 +  window.frameLoaded = test8a;
   1.190 +  iframe.contentWindow.location.reload();
   1.191 +}
   1.192 +
   1.193 +function test7a() {
   1.194 +  resetVars();
   1.195 +  SpecialPowers.setIntPref(hangUITimeoutPref, 0);
   1.196 +  hanguiExpect("test7a: Plugin Hang UI is not showing (disabled)", false, false, "test8");
   1.197 +  var exceptionThrown = false;
   1.198 +  try {
   1.199 +    p.hang();
   1.200 +  } catch(e) {
   1.201 +    exceptionThrown = true;
   1.202 +  }
   1.203 +  ok(exceptionThrown, "test7a: Exception thrown from hang() when plugin was terminated");
   1.204 +}
   1.205 +
   1.206 +function test7() {
   1.207 +  window.frameLoaded = test7a;
   1.208 +  iframe.contentWindow.location.reload();
   1.209 +}
   1.210 +
   1.211 +function test6() {
   1.212 +  SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   1.213 +  SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
   1.214 +  SpecialPowers.setIntPref(timeoutPref, 3);
   1.215 +  hanguiExpect("test6: Plugin Hang UI is showing", true, true, "test7");
   1.216 +  var exceptionThrown = false;
   1.217 +  try {
   1.218 +    p.hang();
   1.219 +  } catch(e) {
   1.220 +    exceptionThrown = true;
   1.221 +  }
   1.222 +  ok(exceptionThrown, "test6: Exception thrown from hang() when plugin was terminated (child timeout)");
   1.223 +}
   1.224 +
   1.225 +function test5a() {
   1.226 +  resetVars();
   1.227 +  hanguiCancel("test5a: Close button works", "test6");
   1.228 +  p.stall(STALL_DURATION);
   1.229 +}
   1.230 +
   1.231 +function test5() {
   1.232 +  window.frameLoaded = test5a;
   1.233 +  iframe.contentWindow.location.reload();
   1.234 +}
   1.235 +
   1.236 +function test4() {
   1.237 +  hanguiStop("test4: Stop button works", false, "test5");
   1.238 +  // We'll get an exception here because the plugin was terminated
   1.239 +  var exceptionThrown = false;
   1.240 +  try {
   1.241 +    p.hang();
   1.242 +  } catch(e) {
   1.243 +    exceptionThrown = true;
   1.244 +  }
   1.245 +  ok(exceptionThrown, "test4: Exception thrown from hang() when plugin was terminated");
   1.246 +}
   1.247 +
   1.248 +function test3() {
   1.249 +  hanguiContinue("test3: Continue button works", false, "test4");
   1.250 +  p.stall(STALL_DURATION);
   1.251 +}
   1.252 +
   1.253 +function test2() {
   1.254 +  // This test is identical to test1 because there were some bugs where the
   1.255 +  // Hang UI would show on the first hang but not on subsequent hangs
   1.256 +  hanguiExpect("test2: Plugin Hang UI is showing", true, true, "test3");
   1.257 +  p.stall(STALL_DURATION);
   1.258 +}
   1.259 +
   1.260 +function test1() {
   1.261 +  SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   1.262 +  SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
   1.263 +  SpecialPowers.setIntPref(timeoutPref, 45);
   1.264 +  hanguiExpect("test1: Plugin Hang UI is showing", true, true, "test2");
   1.265 +  p.stall(STALL_DURATION);
   1.266 +}
   1.267 +
   1.268 +]]>
   1.269 +</script>
   1.270 +</window>

mercurial