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

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),
michael@0 32 "got writable Propbag");
michael@0 33
michael@0 34 var id = subject.getPropertyAsAString("pluginDumpID");
michael@0 35 isnot(id, "", "got a non-empty crash id");
michael@0 36 let directoryService =
michael@0 37 Components.classes["@mozilla.org/file/directory_service;1"].
michael@0 38 getService(Components.interfaces.nsIProperties);
michael@0 39 let pendingD = directoryService.get("UAppData",
michael@0 40 Components.interfaces.nsIFile);
michael@0 41 pendingD.append("Crash Reports");
michael@0 42 pendingD.append("pending");
michael@0 43 let dumpFile = pendingD.clone();
michael@0 44 dumpFile.append(id + ".dmp");
michael@0 45 ok(dumpFile.exists(), "minidump exists");
michael@0 46 let extraFile = pendingD.clone();
michael@0 47 extraFile.append(id + ".extra");
michael@0 48 ok(extraFile.exists(), "extra file exists");
michael@0 49 // cleanup, to be nice
michael@0 50 dumpFile.remove(false);
michael@0 51 extraFile.remove(false);
michael@0 52 },
michael@0 53
michael@0 54 QueryInterface: function(iid) {
michael@0 55 if (iid.equals(Components.interfaces.nsIObserver) ||
michael@0 56 iid.equals(Components.interfaces.nsISupportsWeakReference) ||
michael@0 57 iid.equals(Components.interfaces.nsISupports))
michael@0 58 return this;
michael@0 59 throw Components.results.NS_NOINTERFACE;
michael@0 60 }
michael@0 61 };
michael@0 62
michael@0 63
michael@0 64 function onPluginCrashed(aEvent) {
michael@0 65 ok(true, "Plugin crashed notification received");
michael@0 66 ok(observerFired, "Observer should have fired first");
michael@0 67 is(aEvent.type, "PluginCrashed", "event is correct type");
michael@0 68
michael@0 69 var pluginElement = document.getElementById("plugin1");
michael@0 70 is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
michael@0 71
michael@0 72 ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
michael@0 73 "plugin crashed event has the right interface");
michael@0 74 var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
michael@0 75 var pluginName = propBag.getPropertyAsAString("pluginName");
michael@0 76 is(pluginName, "Test Plug-in");
michael@0 77 var didReport = propBag.getPropertyAsBool("submittedCrashReport");
michael@0 78 // The app itself may or may not have decided to submit the report, so
michael@0 79 // allow either true or false here.
michael@0 80 ok((didReport == true || didReport == false), "event said crash report was submitted");
michael@0 81
michael@0 82 var os = Components.classes["@mozilla.org/observer-service;1"].
michael@0 83 getService(Components.interfaces.nsIObserverService);
michael@0 84 os.removeObserver(testObserver, "plugin-crashed");
michael@0 85
michael@0 86 // re-set MOZ_CRASHREPORTER_NO_REPORT
michael@0 87 let env = Components.classes["@mozilla.org/process/environment;1"]
michael@0 88 .getService(Components.interfaces.nsIEnvironment);
michael@0 89 env.set("MOZ_CRASHREPORTER_NO_REPORT", "1");
michael@0 90 SimpleTest.finish();
michael@0 91 }
michael@0 92
michael@0 93 function runTests() {
michael@0 94 if (!SimpleTest.testPluginIsOOP()) {
michael@0 95 ok(true, "Skipping this test when test plugin is not OOP.");
michael@0 96 SimpleTest.finish();
michael@0 97 return;
michael@0 98 }
michael@0 99 // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT,
michael@0 100 // ensure that we can change the setting and have our minidumps
michael@0 101 // wind up in Crash Reports/pending
michael@0 102 let env = Components.classes["@mozilla.org/process/environment;1"]
michael@0 103 .getService(Components.interfaces.nsIEnvironment);
michael@0 104 env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
michael@0 105
michael@0 106 var os = Components.classes["@mozilla.org/observer-service;1"].
michael@0 107 getService(Components.interfaces.nsIObserverService);
michael@0 108 os.addObserver(testObserver, "plugin-crashed", true);
michael@0 109
michael@0 110 document.addEventListener("PluginCrashed", onPluginCrashed, false);
michael@0 111
michael@0 112 var pluginElement = document.getElementById("plugin1");
michael@0 113 try {
michael@0 114 pluginElement.crash();
michael@0 115 } catch (e) {
michael@0 116 }
michael@0 117 }
michael@0 118 ]]>
michael@0 119 </script>
michael@0 120 </window>
michael@0 121

mercurial