dom/plugins/test/mochitest/hang_test.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/hang_test.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +
     1.5 +Components.utils.import("resource://gre/modules/KeyValueParser.jsm");
     1.6 +
     1.7 +const Cc = Components.classes;
     1.8 +const Ci = Components.interfaces;
     1.9 +
    1.10 +var success = false;
    1.11 +var observerFired = false;
    1.12 +
    1.13 +var testObserver = {
    1.14 +  idleHang: true,
    1.15 +
    1.16 +  observe: function(subject, topic, data) {
    1.17 +    observerFired = true;
    1.18 +    ok(true, "Observer fired");
    1.19 +    is(topic, "plugin-crashed", "Checking correct topic");
    1.20 +    is(data,  null, "Checking null data");
    1.21 +    ok((subject instanceof Ci.nsIPropertyBag2), "got Propbag");
    1.22 +    ok((subject instanceof Ci.nsIWritablePropertyBag2), "got writable Propbag");
    1.23 +
    1.24 +    var pluginId = subject.getPropertyAsAString("pluginDumpID");
    1.25 +    isnot(pluginId, "", "got a non-empty plugin crash id");
    1.26 +
    1.27 +    // check plugin dump and extra files
    1.28 +    let directoryService =
    1.29 +      Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    1.30 +    let profD = directoryService.get("ProfD", Ci.nsIFile);
    1.31 +    profD.append("minidumps");
    1.32 +    let pluginDumpFile = profD.clone();
    1.33 +    pluginDumpFile.append(pluginId + ".dmp");
    1.34 +    ok(pluginDumpFile.exists(), "plugin minidump exists");
    1.35 +
    1.36 +    let pluginExtraFile = profD.clone();
    1.37 +    pluginExtraFile.append(pluginId + ".extra");
    1.38 +    ok(pluginExtraFile.exists(), "plugin extra file exists");
    1.39 +
    1.40 +    let extraData = parseKeyValuePairsFromFile(pluginExtraFile);
    1.41 +
    1.42 +    // check additional dumps
    1.43 +
    1.44 +    ok("additional_minidumps" in extraData, "got field for additional minidumps");
    1.45 +    let additionalDumps = extraData.additional_minidumps.split(',');
    1.46 +    ok(additionalDumps.indexOf('browser') >= 0, "browser in additional_minidumps");
    1.47 +
    1.48 +    let additionalDumpFiles = [];
    1.49 +    for (let name of additionalDumps) {
    1.50 +      let file = profD.clone();
    1.51 +      file.append(pluginId + "-" + name + ".dmp");
    1.52 +      ok(file.exists(), "additional dump '"+name+"' exists");
    1.53 +      if (file.exists()) {
    1.54 +        additionalDumpFiles.push(file);
    1.55 +      }
    1.56 +    }
    1.57 +
    1.58 +    // check cpu usage field
    1.59 +
    1.60 +    ok("PluginCpuUsage" in extraData, "got extra field for plugin cpu usage");
    1.61 +    let cpuUsage = parseFloat(extraData["PluginCpuUsage"]);
    1.62 +    if (this.idleHang) {
    1.63 +      ok(cpuUsage == 0, "plugin cpu usage is 0%");
    1.64 +    } else {
    1.65 +      ok(cpuUsage > 0, "plugin cpu usage is >0%");
    1.66 +    }
    1.67 +
    1.68 +    // check processor count field
    1.69 +    ok("NumberOfProcessors" in extraData, "got extra field for processor count");
    1.70 +    ok(parseInt(extraData["NumberOfProcessors"]) > 0, "number of processors is >0");
    1.71 +
    1.72 +    // cleanup, to be nice
    1.73 +    pluginDumpFile.remove(false);
    1.74 +    pluginExtraFile.remove(false);
    1.75 +    for (let file of additionalDumpFiles) {
    1.76 +      file.remove(false);
    1.77 +    }
    1.78 +  },
    1.79 +
    1.80 +  QueryInterface: function(iid) {
    1.81 +    if (iid.equals(Ci.nsIObserver) ||
    1.82 +        iid.equals(Ci.nsISupportsWeakReference) ||
    1.83 +        iid.equals(Ci.nsISupports))
    1.84 +      return this;
    1.85 +    throw Components.results.NS_NOINTERFACE;
    1.86 +  }
    1.87 +};
    1.88 +
    1.89 +
    1.90 +function onPluginCrashed(aEvent) {
    1.91 +  ok(true, "Plugin crashed notification received");
    1.92 +  ok(observerFired, "Observer should have fired first");
    1.93 +  is(aEvent.type, "PluginCrashed", "event is correct type");
    1.94 +
    1.95 +  var pluginElement = document.getElementById("plugin1");
    1.96 +  is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
    1.97 +
    1.98 +  ok(aEvent instanceof Ci.nsIDOMCustomEvent,
    1.99 +     "plugin crashed event has the right interface");
   1.100 +
   1.101 +  var propBag = aEvent.detail.QueryInterface(Ci.nsIPropertyBag2);
   1.102 +  var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
   1.103 +  isnot(pluginDumpID, "", "got a non-empty dump ID");
   1.104 +  var pluginName = propBag.getPropertyAsAString("pluginName");
   1.105 +  is(pluginName, "Test Plug-in", "got correct plugin name");
   1.106 +  var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
   1.107 +  isnot(pluginFilename, "", "got a non-empty filename");
   1.108 +  var didReport = propBag.getPropertyAsBool("submittedCrashReport");
   1.109 +  // The app itself may or may not have decided to submit the report, so
   1.110 +  // allow either true or false here.
   1.111 +  ok((didReport == true || didReport == false), "event said crash report was submitted");
   1.112 +
   1.113 +  var os = Cc["@mozilla.org/observer-service;1"].
   1.114 +           getService(Ci.nsIObserverService);
   1.115 +  os.removeObserver(testObserver, "plugin-crashed");
   1.116 +
   1.117 +  SimpleTest.finish();
   1.118 +}

mercurial