dom/plugins/test/mochitest/test_crash_notify.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial