dom/plugins/test/mochitest/test_crash_notify_no_report.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

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     4                  type="text/css"?>
     5 <window title="Basic Plugin Tests"
     6   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     7   <script type="application/javascript"
     8           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
     9   <script type="application/javascript" src="utils.js"></script>
    10   <script type="application/javascript">
    11     setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    12   </script>
    13 <body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()">
    14 <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
    15 </body>
    16 <script class="testbody" type="application/javascript">
    17 <![CDATA[
    18 SimpleTest.waitForExplicitFinish();
    20 var success = false;
    22 var observerFired = false;
    24 var testObserver = {
    25   observe: function(subject, topic, data) {
    26     observerFired = true;
    27     ok(true, "Observer fired");
    28     is(topic, "plugin-crashed", "Checking correct topic");
    29     is(data,  null, "Checking null data");
    30     ok((subject instanceof Components.interfaces.nsIPropertyBag2), "got Propbag");
    31     ok((subject instanceof Components.interfaces.nsIWritablePropertyBag2),
    32 "got writable Propbag");
    34     var id = subject.getPropertyAsAString("pluginDumpID");
    35     isnot(id, "", "got a non-empty crash id");
    36     let directoryService =
    37       Components.classes["@mozilla.org/file/directory_service;1"].
    38       getService(Components.interfaces.nsIProperties);
    39     let pendingD = directoryService.get("UAppData",
    40                                         Components.interfaces.nsIFile);
    41     pendingD.append("Crash Reports");
    42     pendingD.append("pending");
    43     let dumpFile = pendingD.clone();    
    44     dumpFile.append(id + ".dmp");
    45     ok(dumpFile.exists(), "minidump exists");
    46     let extraFile = pendingD.clone();
    47     extraFile.append(id + ".extra");
    48     ok(extraFile.exists(), "extra file exists");
    49     // cleanup, to be nice
    50     dumpFile.remove(false);
    51     extraFile.remove(false);
    52   },
    54   QueryInterface: function(iid) {
    55     if (iid.equals(Components.interfaces.nsIObserver) ||
    56         iid.equals(Components.interfaces.nsISupportsWeakReference) ||
    57         iid.equals(Components.interfaces.nsISupports))
    58       return this;
    59     throw Components.results.NS_NOINTERFACE;
    60   }
    61 };
    64 function onPluginCrashed(aEvent) {
    65   ok(true, "Plugin crashed notification received");
    66   ok(observerFired, "Observer should have fired first");
    67   is(aEvent.type, "PluginCrashed", "event is correct type");
    69   var pluginElement = document.getElementById("plugin1");
    70   is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
    72   ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
    73      "plugin crashed event has the right interface");
    74   var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
    75   var pluginName = propBag.getPropertyAsAString("pluginName");
    76   is(pluginName, "Test Plug-in");
    77   var didReport = propBag.getPropertyAsBool("submittedCrashReport");
    78   // The app itself may or may not have decided to submit the report, so
    79   // allow either true or false here.
    80   ok((didReport == true || didReport == false), "event said crash report was submitted");
    82   var os = Components.classes["@mozilla.org/observer-service;1"].
    83            getService(Components.interfaces.nsIObserverService);
    84   os.removeObserver(testObserver, "plugin-crashed");
    86   // re-set MOZ_CRASHREPORTER_NO_REPORT
    87   let env = Components.classes["@mozilla.org/process/environment;1"]
    88                       .getService(Components.interfaces.nsIEnvironment);
    89   env.set("MOZ_CRASHREPORTER_NO_REPORT", "1");
    90   SimpleTest.finish();
    91 }
    93 function runTests() {
    94   if (!SimpleTest.testPluginIsOOP()) {
    95     ok(true, "Skipping this test when test plugin is not OOP.");
    96     SimpleTest.finish();
    97     return;
    98   }
    99   // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT,
   100   // ensure that we can change the setting and have our minidumps
   101   // wind up in Crash Reports/pending
   102   let env = Components.classes["@mozilla.org/process/environment;1"]
   103                       .getService(Components.interfaces.nsIEnvironment);
   104   env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
   106   var os = Components.classes["@mozilla.org/observer-service;1"].
   107            getService(Components.interfaces.nsIObserverService);
   108   os.addObserver(testObserver, "plugin-crashed", true);
   110   document.addEventListener("PluginCrashed", onPluginCrashed, false);
   112   var pluginElement = document.getElementById("plugin1");
   113   try {
   114     pluginElement.crash();
   115   } catch (e) {
   116   }
   117 }
   118 ]]>
   119 </script>
   120 </window>

mercurial