1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_crash_notify.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 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), "got writable Propbag"); 1.35 + 1.36 + var id = subject.getPropertyAsAString("pluginDumpID"); 1.37 + isnot(id, "", "got a non-empty crash id"); 1.38 + let directoryService = 1.39 + Components.classes["@mozilla.org/file/directory_service;1"]. 1.40 + getService(Components.interfaces.nsIProperties); 1.41 + let profD = directoryService.get("ProfD", Components.interfaces.nsIFile); 1.42 + profD.append("minidumps"); 1.43 + let dumpFile = profD.clone(); 1.44 + dumpFile.append(id + ".dmp"); 1.45 + ok(dumpFile.exists(), "minidump exists"); 1.46 + let extraFile = profD.clone(); 1.47 + extraFile.append(id + ".extra"); 1.48 + ok(extraFile.exists(), "extra file exists"); 1.49 + // cleanup, to be nice 1.50 + dumpFile.remove(false); 1.51 + extraFile.remove(false); 1.52 + }, 1.53 + 1.54 + QueryInterface: function(iid) { 1.55 + if (iid.equals(Components.interfaces.nsIObserver) || 1.56 + iid.equals(Components.interfaces.nsISupportsWeakReference) || 1.57 + iid.equals(Components.interfaces.nsISupports)) 1.58 + return this; 1.59 + throw Components.results.NS_NOINTERFACE; 1.60 + } 1.61 +}; 1.62 + 1.63 + 1.64 +function onPluginCrashed(aEvent) { 1.65 + ok(true, "Plugin crashed notification received"); 1.66 + ok(observerFired, "Observer should have fired first"); 1.67 + is(aEvent.type, "PluginCrashed", "event is correct type"); 1.68 + 1.69 + var pluginElement = document.getElementById("plugin1"); 1.70 + is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element"); 1.71 + 1.72 + ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent, 1.73 + "plugin crashed event has the right interface"); 1.74 + 1.75 + var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2); 1.76 + var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID"); 1.77 + isnot(pluginDumpID, "", "got a non-empty dump ID"); 1.78 + var pluginName = propBag.getPropertyAsAString("pluginName"); 1.79 + is(pluginName, "Test Plug-in", "got correct plugin name"); 1.80 + var pluginFilename = propBag.getPropertyAsAString("pluginFilename"); 1.81 + isnot(pluginFilename, "", "got a non-empty filename"); 1.82 + var didReport = propBag.getPropertyAsBool("submittedCrashReport"); 1.83 + // The app itself may or may not have decided to submit the report, so 1.84 + // allow either true or false here. 1.85 + ok((didReport == true || didReport == false), "event said crash report was submitted"); 1.86 + 1.87 + var os = Components.classes["@mozilla.org/observer-service;1"]. 1.88 + getService(Components.interfaces.nsIObserverService); 1.89 + os.removeObserver(testObserver, "plugin-crashed"); 1.90 + 1.91 + SimpleTest.finish(); 1.92 +} 1.93 + 1.94 +function runTests() { 1.95 + if (!SimpleTest.testPluginIsOOP()) { 1.96 + ok(true, "Skipping this test when test plugin is not OOP."); 1.97 + SimpleTest.finish(); 1.98 + return; 1.99 + } 1.100 + 1.101 + var os = Components.classes["@mozilla.org/observer-service;1"]. 1.102 + getService(Components.interfaces.nsIObserverService); 1.103 + os.addObserver(testObserver, "plugin-crashed", true); 1.104 + 1.105 + document.addEventListener("PluginCrashed", onPluginCrashed, false); 1.106 + 1.107 + var pluginElement = document.getElementById("plugin1"); 1.108 + try { 1.109 + pluginElement.crash(); 1.110 + } catch (e) { 1.111 + } 1.112 +} 1.113 +]]> 1.114 +</script> 1.115 +</window> 1.116 +