dom/plugins/test/mochitest/test_crash_notify_no_report.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_crash_notify_no_report.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     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" src="utils.js"></script>
    1.13 +  <script type="application/javascript">
    1.14 +    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    1.15 +  </script>
    1.16 +<body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()">
    1.17 +<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
    1.18 +</body>
    1.19 +<script class="testbody" type="application/javascript">
    1.20 +<![CDATA[
    1.21 +SimpleTest.waitForExplicitFinish();
    1.22 +
    1.23 +var success = false;
    1.24 +
    1.25 +var observerFired = false;
    1.26 +
    1.27 +var testObserver = {
    1.28 +  observe: function(subject, topic, data) {
    1.29 +    observerFired = true;
    1.30 +    ok(true, "Observer fired");
    1.31 +    is(topic, "plugin-crashed", "Checking correct topic");
    1.32 +    is(data,  null, "Checking null data");
    1.33 +    ok((subject instanceof Components.interfaces.nsIPropertyBag2), "got Propbag");
    1.34 +    ok((subject instanceof Components.interfaces.nsIWritablePropertyBag2),
    1.35 +"got writable Propbag");
    1.36 +
    1.37 +    var id = subject.getPropertyAsAString("pluginDumpID");
    1.38 +    isnot(id, "", "got a non-empty crash id");
    1.39 +    let directoryService =
    1.40 +      Components.classes["@mozilla.org/file/directory_service;1"].
    1.41 +      getService(Components.interfaces.nsIProperties);
    1.42 +    let pendingD = directoryService.get("UAppData",
    1.43 +                                        Components.interfaces.nsIFile);
    1.44 +    pendingD.append("Crash Reports");
    1.45 +    pendingD.append("pending");
    1.46 +    let dumpFile = pendingD.clone();    
    1.47 +    dumpFile.append(id + ".dmp");
    1.48 +    ok(dumpFile.exists(), "minidump exists");
    1.49 +    let extraFile = pendingD.clone();
    1.50 +    extraFile.append(id + ".extra");
    1.51 +    ok(extraFile.exists(), "extra file exists");
    1.52 +    // cleanup, to be nice
    1.53 +    dumpFile.remove(false);
    1.54 +    extraFile.remove(false);
    1.55 +  },
    1.56 +
    1.57 +  QueryInterface: function(iid) {
    1.58 +    if (iid.equals(Components.interfaces.nsIObserver) ||
    1.59 +        iid.equals(Components.interfaces.nsISupportsWeakReference) ||
    1.60 +        iid.equals(Components.interfaces.nsISupports))
    1.61 +      return this;
    1.62 +    throw Components.results.NS_NOINTERFACE;
    1.63 +  }
    1.64 +};
    1.65 +
    1.66 +
    1.67 +function onPluginCrashed(aEvent) {
    1.68 +  ok(true, "Plugin crashed notification received");
    1.69 +  ok(observerFired, "Observer should have fired first");
    1.70 +  is(aEvent.type, "PluginCrashed", "event is correct type");
    1.71 +
    1.72 +  var pluginElement = document.getElementById("plugin1");
    1.73 +  is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
    1.74 +
    1.75 +  ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
    1.76 +     "plugin crashed event has the right interface");
    1.77 +  var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
    1.78 +  var pluginName = propBag.getPropertyAsAString("pluginName");
    1.79 +  is(pluginName, "Test Plug-in");
    1.80 +  var didReport = propBag.getPropertyAsBool("submittedCrashReport");
    1.81 +  // The app itself may or may not have decided to submit the report, so
    1.82 +  // allow either true or false here.
    1.83 +  ok((didReport == true || didReport == false), "event said crash report was submitted");
    1.84 +
    1.85 +  var os = Components.classes["@mozilla.org/observer-service;1"].
    1.86 +           getService(Components.interfaces.nsIObserverService);
    1.87 +  os.removeObserver(testObserver, "plugin-crashed");
    1.88 +
    1.89 +  // re-set MOZ_CRASHREPORTER_NO_REPORT
    1.90 +  let env = Components.classes["@mozilla.org/process/environment;1"]
    1.91 +                      .getService(Components.interfaces.nsIEnvironment);
    1.92 +  env.set("MOZ_CRASHREPORTER_NO_REPORT", "1");
    1.93 +  SimpleTest.finish();
    1.94 +}
    1.95 +
    1.96 +function runTests() {
    1.97 +  if (!SimpleTest.testPluginIsOOP()) {
    1.98 +    ok(true, "Skipping this test when test plugin is not OOP.");
    1.99 +    SimpleTest.finish();
   1.100 +    return;
   1.101 +  }
   1.102 +  // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT,
   1.103 +  // ensure that we can change the setting and have our minidumps
   1.104 +  // wind up in Crash Reports/pending
   1.105 +  let env = Components.classes["@mozilla.org/process/environment;1"]
   1.106 +                      .getService(Components.interfaces.nsIEnvironment);
   1.107 +  env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
   1.108 +
   1.109 +  var os = Components.classes["@mozilla.org/observer-service;1"].
   1.110 +           getService(Components.interfaces.nsIObserverService);
   1.111 +  os.addObserver(testObserver, "plugin-crashed", true);
   1.112 +  
   1.113 +  document.addEventListener("PluginCrashed", onPluginCrashed, false);
   1.114 +
   1.115 +  var pluginElement = document.getElementById("plugin1");
   1.116 +  try {
   1.117 +    pluginElement.crash();
   1.118 +  } catch (e) {
   1.119 +  }
   1.120 +}
   1.121 +]]>
   1.122 +</script>
   1.123 +</window>
   1.124 +

mercurial