Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | Components.utils.import("resource://gre/modules/KeyValueParser.jsm"); |
michael@0 | 3 | |
michael@0 | 4 | const Cc = Components.classes; |
michael@0 | 5 | const Ci = Components.interfaces; |
michael@0 | 6 | |
michael@0 | 7 | var success = false; |
michael@0 | 8 | var observerFired = false; |
michael@0 | 9 | |
michael@0 | 10 | var testObserver = { |
michael@0 | 11 | idleHang: true, |
michael@0 | 12 | |
michael@0 | 13 | observe: function(subject, topic, data) { |
michael@0 | 14 | observerFired = true; |
michael@0 | 15 | ok(true, "Observer fired"); |
michael@0 | 16 | is(topic, "plugin-crashed", "Checking correct topic"); |
michael@0 | 17 | is(data, null, "Checking null data"); |
michael@0 | 18 | ok((subject instanceof Ci.nsIPropertyBag2), "got Propbag"); |
michael@0 | 19 | ok((subject instanceof Ci.nsIWritablePropertyBag2), "got writable Propbag"); |
michael@0 | 20 | |
michael@0 | 21 | var pluginId = subject.getPropertyAsAString("pluginDumpID"); |
michael@0 | 22 | isnot(pluginId, "", "got a non-empty plugin crash id"); |
michael@0 | 23 | |
michael@0 | 24 | // check plugin dump and extra files |
michael@0 | 25 | let directoryService = |
michael@0 | 26 | Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); |
michael@0 | 27 | let profD = directoryService.get("ProfD", Ci.nsIFile); |
michael@0 | 28 | profD.append("minidumps"); |
michael@0 | 29 | let pluginDumpFile = profD.clone(); |
michael@0 | 30 | pluginDumpFile.append(pluginId + ".dmp"); |
michael@0 | 31 | ok(pluginDumpFile.exists(), "plugin minidump exists"); |
michael@0 | 32 | |
michael@0 | 33 | let pluginExtraFile = profD.clone(); |
michael@0 | 34 | pluginExtraFile.append(pluginId + ".extra"); |
michael@0 | 35 | ok(pluginExtraFile.exists(), "plugin extra file exists"); |
michael@0 | 36 | |
michael@0 | 37 | let extraData = parseKeyValuePairsFromFile(pluginExtraFile); |
michael@0 | 38 | |
michael@0 | 39 | // check additional dumps |
michael@0 | 40 | |
michael@0 | 41 | ok("additional_minidumps" in extraData, "got field for additional minidumps"); |
michael@0 | 42 | let additionalDumps = extraData.additional_minidumps.split(','); |
michael@0 | 43 | ok(additionalDumps.indexOf('browser') >= 0, "browser in additional_minidumps"); |
michael@0 | 44 | |
michael@0 | 45 | let additionalDumpFiles = []; |
michael@0 | 46 | for (let name of additionalDumps) { |
michael@0 | 47 | let file = profD.clone(); |
michael@0 | 48 | file.append(pluginId + "-" + name + ".dmp"); |
michael@0 | 49 | ok(file.exists(), "additional dump '"+name+"' exists"); |
michael@0 | 50 | if (file.exists()) { |
michael@0 | 51 | additionalDumpFiles.push(file); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | // check cpu usage field |
michael@0 | 56 | |
michael@0 | 57 | ok("PluginCpuUsage" in extraData, "got extra field for plugin cpu usage"); |
michael@0 | 58 | let cpuUsage = parseFloat(extraData["PluginCpuUsage"]); |
michael@0 | 59 | if (this.idleHang) { |
michael@0 | 60 | ok(cpuUsage == 0, "plugin cpu usage is 0%"); |
michael@0 | 61 | } else { |
michael@0 | 62 | ok(cpuUsage > 0, "plugin cpu usage is >0%"); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | // check processor count field |
michael@0 | 66 | ok("NumberOfProcessors" in extraData, "got extra field for processor count"); |
michael@0 | 67 | ok(parseInt(extraData["NumberOfProcessors"]) > 0, "number of processors is >0"); |
michael@0 | 68 | |
michael@0 | 69 | // cleanup, to be nice |
michael@0 | 70 | pluginDumpFile.remove(false); |
michael@0 | 71 | pluginExtraFile.remove(false); |
michael@0 | 72 | for (let file of additionalDumpFiles) { |
michael@0 | 73 | file.remove(false); |
michael@0 | 74 | } |
michael@0 | 75 | }, |
michael@0 | 76 | |
michael@0 | 77 | QueryInterface: function(iid) { |
michael@0 | 78 | if (iid.equals(Ci.nsIObserver) || |
michael@0 | 79 | iid.equals(Ci.nsISupportsWeakReference) || |
michael@0 | 80 | iid.equals(Ci.nsISupports)) |
michael@0 | 81 | return this; |
michael@0 | 82 | throw Components.results.NS_NOINTERFACE; |
michael@0 | 83 | } |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | function onPluginCrashed(aEvent) { |
michael@0 | 88 | ok(true, "Plugin crashed notification received"); |
michael@0 | 89 | ok(observerFired, "Observer should have fired first"); |
michael@0 | 90 | is(aEvent.type, "PluginCrashed", "event is correct type"); |
michael@0 | 91 | |
michael@0 | 92 | var pluginElement = document.getElementById("plugin1"); |
michael@0 | 93 | is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element"); |
michael@0 | 94 | |
michael@0 | 95 | ok(aEvent instanceof Ci.nsIDOMCustomEvent, |
michael@0 | 96 | "plugin crashed event has the right interface"); |
michael@0 | 97 | |
michael@0 | 98 | var propBag = aEvent.detail.QueryInterface(Ci.nsIPropertyBag2); |
michael@0 | 99 | var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID"); |
michael@0 | 100 | isnot(pluginDumpID, "", "got a non-empty dump ID"); |
michael@0 | 101 | var pluginName = propBag.getPropertyAsAString("pluginName"); |
michael@0 | 102 | is(pluginName, "Test Plug-in", "got correct plugin name"); |
michael@0 | 103 | var pluginFilename = propBag.getPropertyAsAString("pluginFilename"); |
michael@0 | 104 | isnot(pluginFilename, "", "got a non-empty filename"); |
michael@0 | 105 | var didReport = propBag.getPropertyAsBool("submittedCrashReport"); |
michael@0 | 106 | // The app itself may or may not have decided to submit the report, so |
michael@0 | 107 | // allow either true or false here. |
michael@0 | 108 | ok((didReport == true || didReport == false), "event said crash report was submitted"); |
michael@0 | 109 | |
michael@0 | 110 | var os = Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 111 | getService(Ci.nsIObserverService); |
michael@0 | 112 | os.removeObserver(testObserver, "plugin-crashed"); |
michael@0 | 113 | |
michael@0 | 114 | SimpleTest.finish(); |
michael@0 | 115 | } |