Bug 1061821 - Ensure CrashManager contains the crash and submission in test_{crash,hang}_submit.xul. r=bsmedberg
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 02 Sep 2014 10:38:01 -0700
changeset 203630 9a1769480c9fbb2c736c648803d95c06cd52681a
parent 203629 565868ef8a29a3a369018b4e1e5c4700e24c9ac1
child 203631 1f9dbb8ea24d5aa4a3c35976d1674476b128b9c0
push id27433
push userkwierso@gmail.com
push dateFri, 05 Sep 2014 01:31:29 +0000
treeherdermozilla-central@db7212847c14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1061821
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1061821 - Ensure CrashManager contains the crash and submission in test_{crash,hang}_submit.xul. r=bsmedberg
dom/plugins/test/mochitest/test_crash_submit.xul
dom/plugins/test/mochitest/test_hang_submit.xul
--- a/dom/plugins/test/mochitest/test_crash_submit.xul
+++ b/dom/plugins/test/mochitest/test_crash_submit.xul
@@ -17,66 +17,93 @@
 </body>
 <script class="testbody" type="application/javascript">
 <![CDATA[
 SimpleTest.waitForExplicitFinish();
 SimpleTest.ignoreAllUncaughtExceptions();
 
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/Task.jsm");
 
 var crashReporter =
   Components.classes["@mozilla.org/toolkit/crash-reporter;1"]
     .getService(Components.interfaces.nsICrashReporter);
 var oldServerURL = crashReporter.serverURL;
 
 const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
 
 var testObserver = {
   observe: function(subject, topic, data) {
     if (data == "submitting") // not done yet
       return;
     is(data, "success", "report should have been submitted successfully");
     is(topic, "crash-report-status", "Checking correct topic");
     ok(subject instanceof Components.interfaces.nsIPropertyBag2,
        "Subject should be a property bag");
+
+    ok(subject.hasKey("minidumpID"), "Should have a local crash ID");
+    let crashID = subject.getPropertyAsAString("minidumpID");
+    isnot(crashID, "", "Local crash ID should not be an empty string");
+
     ok(subject.hasKey("serverCrashID"), "Should have a server crash ID");
-    let crashid = subject.getPropertyAsAString("serverCrashID");
-    isnot(crashid, "", "Server crash ID should not be an empty string");
+    let remoteID = subject.getPropertyAsAString("serverCrashID");
+    isnot(remoteID, "", "Server crash ID should not be an empty string");
 
     // Verify the data. The SJS script will return the data that was POSTed
     let req = new XMLHttpRequest();
-    req.open("GET", SERVER_URL + "?id=" + crashid, false);
+    req.open("GET", SERVER_URL + "?id=" + remoteID, false);
     req.send(null);
     is(req.status, 200, "Server response should be 200 OK");
     let submitted = JSON.parse(req.responseText);
     ok(!("Throttleable" in submitted), "Submit request should not be Throttleable");
     is(submitted.ProcessType, "plugin", "Should specify ProcessType=plugin");
 
     // Cleanup
     // First remove our fake submitted report
     let file = Services.dirsvc.get("UAppData", Components.interfaces.nsILocalFile);
     file.append("Crash Reports");
     file.append("submitted");
-    file.append(crashid + ".txt");
+    file.append(remoteID + ".txt");
     file.remove(false);
 
     // Next unregister our observer
     var os = Components.classes["@mozilla.org/observer-service;1"].
              getService(Components.interfaces.nsIObserverService);
     os.removeObserver(testObserver, "crash-report-status");
 
     // Then re-set MOZ_CRASHREPORTER_NO_REPORT
     let env = Components.classes["@mozilla.org/process/environment;1"]
                         .getService(Components.interfaces.nsIEnvironment);
     env.set("MOZ_CRASHREPORTER_NO_REPORT", "1");
 
     // Finally re-set crashreporter URL
     crashReporter.serverURL = oldServerURL;
-    SimpleTest.finish();
+
+    // Check and cleanup CrashManager.
+    Task.spawn(function* () {
+      let cm = Services.crashmanager;
+      let store = yield cm._getStore();
+      is(store.crashesCount, 1, "Store should have only 1 item");
+
+      let crash = store.getCrash(crashID);
+      ok(!!crash, "Store should have the crash record");
+      ok(crash.isOfType(cm.PROCESS_TYPE_PLUGIN, cm.CRASH_TYPE_CRASH),
+         "Crash type should be plugin-crash");
+      is(crash.remoteID, remoteID, "Crash remoteID should match");
+
+      is(crash.submissions.size, 1, "Crash should have a submission");
+      let submission = crash.submissions.values().next().value;
+      is(submission.result, cm.SUBMISSION_RESULT_OK,
+         "Submission should be successful");
+
+      store.reset();
+
+      SimpleTest.finish();
+    });
   },
 
   QueryInterface: function(iid) {
     if (iid.equals(Components.interfaces.nsIObserver) ||
         iid.equals(Components.interfaces.nsISupportsWeakReference) ||
         iid.equals(Components.interfaces.nsISupports))
       return this;
     throw Components.results.NS_NOINTERFACE;
@@ -115,15 +142,22 @@ function runTests() {
   var os = Components.classes["@mozilla.org/observer-service;1"].
            getService(Components.interfaces.nsIObserverService);
   os.addObserver(testObserver, "crash-report-status", true);
   
   document.addEventListener("PluginCrashed", onPluginCrashed, false);
 
   var pluginElement = document.getElementById("plugin1");
   try {
-    pluginElement.crash();
+    Task.spawn(function* () {
+      // Clear data in CrashManager in case previous tests caused something
+      // to be added.
+      let store = yield Services.crashmanager._getStore();
+      store.reset();
+
+      pluginElement.crash();
+    });
   } catch (e) {
   }
 }
 ]]>
 </script>
 </window>
--- a/dom/plugins/test/mochitest/test_hang_submit.xul
+++ b/dom/plugins/test/mochitest/test_hang_submit.xul
@@ -17,16 +17,17 @@
 </body>
 <script class="testbody" type="application/javascript">
 <![CDATA[
 SimpleTest.waitForExplicitFinish();
 SimpleTest.ignoreAllUncaughtExceptions();
 
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/Task.jsm");
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 const crashReporter = Cc["@mozilla.org/toolkit/crash-reporter;1"].getService(Ci.nsICrashReporter);
 const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
 
 const serverPrefName = "toolkit.crashreporter.pluginHangSubmitURL";
@@ -42,23 +43,28 @@ const oldTimeoutPref = Services.prefs.ge
 
 var testObserver = {
   observe: function(subject, topic, data) {
     if (data == "submitting") // not done yet
       return;
     is(data, "success", "report should have been submitted successfully");
     is(topic, "crash-report-status", "Checking correct topic");
     ok(subject instanceof Ci.nsIPropertyBag2, "Subject should be a property bag");
+
+    ok(subject.hasKey("minidumpID"), "Should have a local crash ID");
+    let crashID = subject.getPropertyAsAString("minidumpID");
+    isnot(crashID, "", "Local crash ID should not be an empty string");
+
     ok(subject.hasKey("serverCrashID"), "Should have a server crash ID");
-    let crashid = subject.getPropertyAsAString("serverCrashID");
-    isnot(crashid, "", "Server crash ID should not be an empty string");
+    let remoteID = subject.getPropertyAsAString("serverCrashID");
+    isnot(remoteID, "", "Server crash ID should not be an empty string");
 
     // Verify the data. The SJS script will return the data that was POSTed
     let req = new XMLHttpRequest();
-    req.open("GET", SERVER_URL + "?id=" + crashid, false);
+    req.open("GET", SERVER_URL + "?id=" + remoteID, false);
     req.send(null);
     is(req.status, 200, "Server response should be 200 OK");
     let submitted = JSON.parse(req.responseText);
 
     ok(!("Throttleable" in submitted), "Submit request should not be Throttleable");
     is(submitted.ProcessType, "plugin", "Should specify ProcessType=plugin");
     ok("PluginHang" in submitted, "Request should contain PluginHang field");
     ok("additional_minidumps" in submitted, "Request should contain additional_minidumps field");
@@ -68,17 +74,17 @@ var testObserver = {
     ok("upload_file_minidump" in submitted, "Request should contain upload_file_minidump field");
     ok("upload_file_minidump_browser" in submitted, "Request should contain upload_file_minidump_browser field");
 
     // Cleanup
     // First remove our fake submitted report
     let file = Services.dirsvc.get("UAppData", Ci.nsILocalFile);
     file.append("Crash Reports");
     file.append("submitted");
-    file.append(crashid + ".txt");
+    file.append(remoteID + ".txt");
     file.remove(false);
 
     // Next unregister our observer
     Services.obs.removeObserver(testObserver, "crash-report-status");
 
     // Then re-set MOZ_CRASHREPORTER_NO_REPORT
     let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
     env.set("MOZ_CRASHREPORTER_NO_REPORT", "1");
@@ -86,17 +92,38 @@ var testObserver = {
     // Finally re-set prefs
     if (oldServerPref === undefined) {
       Services.prefs.clearUserPref(serverPrefName);
     }
     else {
       Services.prefs.setCharPref(serverPrefName, oldServerPref);
     }
     Services.prefs.setIntPref("dom.ipc.plugins.timeoutSecs", oldTimeoutPref);
-    SimpleTest.finish();
+
+    // Check and cleanup CrashManager.
+    Task.spawn(function* () {
+      let cm = Services.crashmanager;
+      let store = yield cm._getStore();
+      is(store.crashesCount, 1, "Store should have only 1 item");
+
+      let crash = store.getCrash(crashID);
+      ok(!!crash, "Store should have the crash record");
+      ok(crash.isOfType(cm.PROCESS_TYPE_PLUGIN, cm.CRASH_TYPE_HANG),
+         "Crash type should be plugin-hang");
+      is(crash.remoteID, remoteID, "Crash remoteID should match");
+
+      is(crash.submissions.size, 1, "Crash should have a submission");
+      let submission = crash.submissions.values().next().value;
+      is(submission.result, cm.SUBMISSION_RESULT_OK,
+         "Submission should be successful");
+
+      store.reset();
+
+      SimpleTest.finish();
+    });
   },
 
   QueryInterface: function(iid) {
     if (iid.equals(Ci.nsIObserver) ||
         iid.equals(Ci.nsISupportsWeakReference) ||
         iid.equals(Ci.nsISupports))
       return this;
     throw Components.results.NS_NOINTERFACE;
@@ -135,15 +162,22 @@ function runTests() {
   Services.prefs.setCharPref("toolkit.crashreporter.pluginHangSubmitURL", SERVER_URL);
 
   // Hook into plugin crash events
   Services.obs.addObserver(testObserver, "crash-report-status", true);
   document.addEventListener("PluginCrashed", onPluginCrashed, false);
 
   var pluginElement = document.getElementById("plugin1");
   try {
-    pluginElement.hang();
+    Task.spawn(function* () {
+      // Clear data in CrashManager in case previous tests caused something
+      // to be added.
+      let store = yield Services.crashmanager._getStore();
+      store.reset();
+
+      pluginElement.hang();
+    });
   } catch (e) {
   }
 }
 ]]>
 </script>
 </window>