dom/plugins/test/mochitest/test_crash_notify.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), "got writable Propbag");
    33     var id = subject.getPropertyAsAString("pluginDumpID");
    34     isnot(id, "", "got a non-empty crash id");
    35     let directoryService =
    36       Components.classes["@mozilla.org/file/directory_service;1"].
    37       getService(Components.interfaces.nsIProperties);
    38     let profD = directoryService.get("ProfD", Components.interfaces.nsIFile);
    39     profD.append("minidumps");
    40     let dumpFile = profD.clone();
    41     dumpFile.append(id + ".dmp");
    42     ok(dumpFile.exists(), "minidump exists");
    43     let extraFile = profD.clone();
    44     extraFile.append(id + ".extra");
    45     ok(extraFile.exists(), "extra file exists");
    46     // cleanup, to be nice
    47     dumpFile.remove(false);
    48     extraFile.remove(false);
    49   },
    51   QueryInterface: function(iid) {
    52     if (iid.equals(Components.interfaces.nsIObserver) ||
    53         iid.equals(Components.interfaces.nsISupportsWeakReference) ||
    54         iid.equals(Components.interfaces.nsISupports))
    55       return this;
    56     throw Components.results.NS_NOINTERFACE;
    57   }
    58 };
    61 function onPluginCrashed(aEvent) {
    62   ok(true, "Plugin crashed notification received");
    63   ok(observerFired, "Observer should have fired first");
    64   is(aEvent.type, "PluginCrashed", "event is correct type");
    66   var pluginElement = document.getElementById("plugin1");
    67   is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
    69   ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
    70      "plugin crashed event has the right interface");
    72   var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
    73   var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
    74   isnot(pluginDumpID, "", "got a non-empty dump ID");
    75   var pluginName = propBag.getPropertyAsAString("pluginName");
    76   is(pluginName, "Test Plug-in", "got correct plugin name");
    77   var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
    78   isnot(pluginFilename, "", "got a non-empty filename");
    79   var didReport = propBag.getPropertyAsBool("submittedCrashReport");
    80   // The app itself may or may not have decided to submit the report, so
    81   // allow either true or false here.
    82   ok((didReport == true || didReport == false), "event said crash report was submitted");
    84   var os = Components.classes["@mozilla.org/observer-service;1"].
    85            getService(Components.interfaces.nsIObserverService);
    86   os.removeObserver(testObserver, "plugin-crashed");
    88   SimpleTest.finish();
    89 }
    91 function runTests() {
    92   if (!SimpleTest.testPluginIsOOP()) {
    93     ok(true, "Skipping this test when test plugin is not OOP.");
    94     SimpleTest.finish();
    95     return;
    96   }
    98   var os = Components.classes["@mozilla.org/observer-service;1"].
    99            getService(Components.interfaces.nsIObserverService);
   100   os.addObserver(testObserver, "plugin-crashed", true);
   102   document.addEventListener("PluginCrashed", onPluginCrashed, false);
   104   var pluginElement = document.getElementById("plugin1");
   105   try {
   106     pluginElement.crash();
   107   } catch (e) {
   108   }
   109 }
   110 ]]>
   111 </script>
   112 </window>

mercurial