Bug 1007534 - Part 6: xpcshell test for memory data in crash reporter. r=ted
authorDavid Major <dmajor@mozilla.com>
Sat, 30 Aug 2014 17:22:14 +1200
changeset 224203 bf78613407338b6412acf973ad456a924e3aff1a
parent 224202 bc7c6f1deaf1c6243ec3f6498113da74753d4705
child 224204 f1d621aa125ed251e055b24d3db34437b6f833d9
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1007534
milestone34.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 1007534 - Part 6: xpcshell test for memory data in crash reporter. r=ted
toolkit/crashreporter/test/unit/head_crashreporter.js
toolkit/crashreporter/test/unit/test_crash_with_memory_report.js
toolkit/crashreporter/test/unit/xpcshell.ini
--- a/toolkit/crashreporter/test/unit/head_crashreporter.js
+++ b/toolkit/crashreporter/test/unit/head_crashreporter.js
@@ -103,33 +103,40 @@ function handleMinidump(callback)
   }
 
   if (minidump == null)
     do_throw("No minidump found!");
 
   let extrafile = minidump.clone();
   extrafile.leafName = extrafile.leafName.slice(0, -4) + ".extra";
 
+  let memoryfile = minidump.clone();
+  memoryfile.leafName = memoryfile.leafName.slice(0, -4) + ".memory.json.gz";
+
   // Just in case, don't let these files linger.
   do_register_cleanup(function() {
           if (minidump.exists())
               minidump.remove(false);
           if (extrafile.exists())
               extrafile.remove(false);
+          if (memoryfile.exists())
+              memoryfile.remove(false);
       });
   do_check_true(extrafile.exists());
   let extra = parseKeyValuePairsFromFile(extrafile);
 
   if (callback)
     callback(minidump, extra);
 
   if (minidump.exists())
     minidump.remove(false);
   if (extrafile.exists())
     extrafile.remove(false);
+  if (memoryfile.exists())
+    memoryfile.remove(false);
 }
 
 function do_content_crash(setup, callback)
 {
   do_load_child_test_harness();
   do_test_pending();
 
   // Setting the minidump path won't work in the child, so we need to do
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/unit/test_crash_with_memory_report.js
@@ -0,0 +1,52 @@
+function run_test()
+{
+  if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) {
+    dump("INFO | test_crash_oom.js | Can't test crashreporter in a non-libxul build.\n");
+    return;
+  }
+
+  // This was shamelessly copied and stripped down from do_get_profile() in
+  // head.js so that nsICrashReporter::saveMemoryReport can use a profile
+  // within the crasher subprocess.
+
+  do_crash(
+   function() {
+      let Cc = Components.classes;
+      let Ci = Components.interfaces;
+
+      let env = Cc["@mozilla.org/process/environment;1"]
+                  .getService(Ci.nsIEnvironment);
+      let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
+      let file = Cc["@mozilla.org/file/local;1"]
+                   .createInstance(Ci.nsILocalFile);
+      file.initWithPath(profd);
+
+      let dirSvc = Cc["@mozilla.org/file/directory_service;1"]
+                     .getService(Ci.nsIProperties);
+      let provider = {
+        getFile: function(prop, persistent) {
+          persistent.value = true;
+              if (prop == "ProfD" || prop == "ProfLD" || prop == "ProfDS" ||
+              prop == "ProfLDS" || prop == "TmpD") {
+            return file.clone();
+          }
+          throw Components.results.NS_ERROR_FAILURE;
+        },
+        QueryInterface: function(iid) {
+          if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
+              iid.equals(Ci.nsISupports)) {
+            return this;
+          }
+          throw Components.results.NS_ERROR_NO_INTERFACE;
+        }
+      };
+      dirSvc.QueryInterface(Ci.nsIDirectoryService)
+            .registerProvider(provider);
+
+      crashReporter.saveMemoryReport();
+    },
+    function(mdump, extra) {
+      do_check_eq(extra.ContainsMemoryReport, "1");
+    },
+    true);
+}
--- a/toolkit/crashreporter/test/unit/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit/xpcshell.ini
@@ -9,21 +9,20 @@ support-files =
 [test_crash_purevirtual.js]
 [test_crash_runtimeabort.js]
 [test_crash_after_js_oom_reported.js]
 [test_crash_after_js_oom_recovered.js]
 [test_crash_after_js_oom_reported_2.js]
 [test_crash_after_js_large_allocation_failure.js]
 [test_crash_after_js_large_allocation_failure_reporting.js]
 [test_crash_oom.js]
-skip-if = os == 'win' && debug
-
 [test_crash_abort.js]
 skip-if = os == 'win'
 
+[test_crash_with_memory_report.js]
 [test_crashreporter.js]
 [test_crashreporter_crash.js]
 [test_crashreporter_crash_profile_lock.js]
 [test_override_exception_handler.js]
 run-if = os == 'win'
 
 [test_crashreporter_appmem.js]
 run-if = os == 'win' || os == 'linux'