dom/plugins/test/mochitest/test_hang_submit.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_hang_submit.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     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="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.10 +  <script type="application/javascript"
    1.11 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
    1.14 +  <script type="application/javascript" src="utils.js"></script>
    1.15 +  <script type="application/javascript">
    1.16 +    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    1.17 +  </script>
    1.18 +<body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()">
    1.19 +<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
    1.20 +</body>
    1.21 +<script class="testbody" type="application/javascript">
    1.22 +<![CDATA[
    1.23 +SimpleTest.waitForExplicitFinish();
    1.24 +SimpleTest.ignoreAllUncaughtExceptions();
    1.25 +
    1.26 +Components.utils.import("resource://gre/modules/NetUtil.jsm");
    1.27 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.28 +
    1.29 +const Cc = Components.classes;
    1.30 +const Ci = Components.interfaces;
    1.31 +
    1.32 +const crashReporter = Cc["@mozilla.org/toolkit/crash-reporter;1"].getService(Ci.nsICrashReporter);
    1.33 +const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
    1.34 +
    1.35 +const serverPrefName = "toolkit.crashreporter.pluginHangSubmitURL";
    1.36 +
    1.37 +var oldServerPref;
    1.38 +try {
    1.39 +  oldServerPref = Services.prefs.getCharPref(serverPrefName);
    1.40 +}
    1.41 +catch(e) {
    1.42 +}
    1.43 +
    1.44 +const oldTimeoutPref = Services.prefs.getIntPref("dom.ipc.plugins.timeoutSecs");
    1.45 +
    1.46 +var testObserver = {
    1.47 +  observe: function(subject, topic, data) {
    1.48 +    if (data == "submitting") // not done yet
    1.49 +      return;
    1.50 +    is(data, "success", "report should have been submitted successfully");
    1.51 +    is(topic, "crash-report-status", "Checking correct topic");
    1.52 +    ok(subject instanceof Ci.nsIPropertyBag2, "Subject should be a property bag");
    1.53 +    ok(subject.hasKey("serverCrashID"), "Should have a server crash ID");
    1.54 +    let crashid = subject.getPropertyAsAString("serverCrashID");
    1.55 +    isnot(crashid, "", "Server crash ID should not be an empty string");
    1.56 +
    1.57 +    // Verify the data. The SJS script will return the data that was POSTed
    1.58 +    let req = new XMLHttpRequest();
    1.59 +    req.open("GET", SERVER_URL + "?id=" + crashid, false);
    1.60 +    req.send(null);
    1.61 +    is(req.status, 200, "Server response should be 200 OK");
    1.62 +    let submitted = JSON.parse(req.responseText);
    1.63 +
    1.64 +    ok(!("Throttleable" in submitted), "Submit request should not be Throttleable");
    1.65 +    is(submitted.ProcessType, "plugin", "Should specify ProcessType=plugin");
    1.66 +    ok("PluginHang" in submitted, "Request should contain PluginHang field");
    1.67 +    ok("additional_minidumps" in submitted, "Request should contain additional_minidumps field");
    1.68 +    let dumpNames = submitted.additional_minidumps.split(',');
    1.69 +    ok(dumpNames.indexOf("browser") != -1, "additional_minidumps should contain browser");
    1.70 +    info("additional_minidumps="+submitted.additional_minidumps);
    1.71 +    ok("upload_file_minidump" in submitted, "Request should contain upload_file_minidump field");
    1.72 +    ok("upload_file_minidump_browser" in submitted, "Request should contain upload_file_minidump_browser field");
    1.73 +
    1.74 +    // Cleanup
    1.75 +    // First remove our fake submitted report
    1.76 +    let file = Services.dirsvc.get("UAppData", Ci.nsILocalFile);
    1.77 +    file.append("Crash Reports");
    1.78 +    file.append("submitted");
    1.79 +    file.append(crashid + ".txt");
    1.80 +    file.remove(false);
    1.81 +
    1.82 +    // Next unregister our observer
    1.83 +    Services.obs.removeObserver(testObserver, "crash-report-status");
    1.84 +
    1.85 +    // Then re-set MOZ_CRASHREPORTER_NO_REPORT
    1.86 +    let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
    1.87 +    env.set("MOZ_CRASHREPORTER_NO_REPORT", "1");
    1.88 +
    1.89 +    // Finally re-set prefs
    1.90 +    if (oldServerPref === undefined) {
    1.91 +      Services.prefs.clearUserPref(serverPrefName);
    1.92 +    }
    1.93 +    else {
    1.94 +      Services.prefs.setCharPref(serverPrefName, oldServerPref);
    1.95 +    }
    1.96 +    Services.prefs.setIntPref("dom.ipc.plugins.timeoutSecs", oldTimeoutPref);
    1.97 +    SimpleTest.finish();
    1.98 +  },
    1.99 +
   1.100 +  QueryInterface: function(iid) {
   1.101 +    if (iid.equals(Ci.nsIObserver) ||
   1.102 +        iid.equals(Ci.nsISupportsWeakReference) ||
   1.103 +        iid.equals(Ci.nsISupports))
   1.104 +      return this;
   1.105 +    throw Components.results.NS_NOINTERFACE;
   1.106 +  }
   1.107 +};
   1.108 +
   1.109 +function onPluginCrashed(aEvent) {
   1.110 +  ok(true, "Plugin crashed notification received");
   1.111 +  is(aEvent.type, "PluginCrashed", "event is correct type");
   1.112 +
   1.113 +  let submitButton = document.getAnonymousElementByAttribute(aEvent.target,
   1.114 +                                                             "class",
   1.115 +                                                             "submitButton");
   1.116 +  // try to submit this report
   1.117 +  sendMouseEvent({type:'click'}, submitButton, window);
   1.118 +}
   1.119 +
   1.120 +function runTests() {
   1.121 +  if (!SimpleTest.testPluginIsOOP()) {
   1.122 +    todo(false, "Skipping this test when test plugin is not OOP.");
   1.123 +    SimpleTest.finish();
   1.124 +    return;
   1.125 +  }
   1.126 +
   1.127 +  // Default plugin hang timeout is too high for mochitests
   1.128 +  Services.prefs.setIntPref("dom.ipc.plugins.timeoutSecs", 1);
   1.129 +
   1.130 +  // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT,
   1.131 +  // ensure that we can change the setting and have our minidumps
   1.132 +  // wind up in Crash Reports/pending
   1.133 +  let env = Cc["@mozilla.org/process/environment;1"]
   1.134 +                      .getService(Ci.nsIEnvironment);
   1.135 +  env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
   1.136 +
   1.137 +  // Override the crash reporter URL to send to our fake server
   1.138 +  Services.prefs.setCharPref("toolkit.crashreporter.pluginHangSubmitURL", SERVER_URL);
   1.139 +
   1.140 +  // Hook into plugin crash events
   1.141 +  Services.obs.addObserver(testObserver, "crash-report-status", true);
   1.142 +  document.addEventListener("PluginCrashed", onPluginCrashed, false);
   1.143 +
   1.144 +  var pluginElement = document.getElementById("plugin1");
   1.145 +  try {
   1.146 +    pluginElement.hang();
   1.147 +  } catch (e) {
   1.148 +  }
   1.149 +}
   1.150 +]]>
   1.151 +</script>
   1.152 +</window>

mercurial