bug 792850 - add an xpcshell test for our SetUnhandledExceptionFilter hook. r=ehsan
authorTed Mielczarek <ted.mielczarek@gmail.com>
Thu, 20 Sep 2012 10:57:08 -0400
changeset 107998 4cbb3a34f040f0a6dde2245ab76fc0cdadacb44c
parent 107997 42b4cad82f1af1b8be3b2a91863b00c5baf48117
child 107999 eae123c9c88434a7987082ce155d25dcd7cdad76
push id15319
push usertmielczarek@mozilla.com
push dateTue, 25 Sep 2012 11:53:50 +0000
treeherdermozilla-inbound@4cbb3a34f040 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs792850
milestone18.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 792850 - add an xpcshell test for our SetUnhandledExceptionFilter hook. r=ehsan
toolkit/crashreporter/test/CrashTestUtils.jsm
toolkit/crashreporter/test/nsTestCrasher.cpp
toolkit/crashreporter/test/unit/test_override_exception_handler.js
toolkit/crashreporter/test/unit/xpcshell.ini
--- a/toolkit/crashreporter/test/CrashTestUtils.jsm
+++ b/toolkit/crashreporter/test/CrashTestUtils.jsm
@@ -37,16 +37,23 @@ CrashTestUtils.saveAppMemory = lib.decla
                                            ctypes.uint64_t);
 
 CrashTestUtils.lockDir = lib.declare("LockDir",
                                      ctypes.default_abi,
                                      ctypes.voidptr_t,   // nsILocalFile*
                                      ctypes.voidptr_t);  // nsISupports*
 
 
+try {
+  CrashTestUtils.TryOverrideExceptionHandler = lib.declare("TryOverrideExceptionHandler",
+                                                           ctypes.default_abi,
+                                                           ctypes.void_t);
+}
+catch(ex) {}
+
 CrashTestUtils.dumpHasStream = lib.declare("DumpHasStream",
                                            ctypes.default_abi,
                                            ctypes.bool,
                                            ctypes.char.ptr,
                                            ctypes.uint32_t);
 
 CrashTestUtils.dumpHasInstructionPointerMemory =
   lib.declare("DumpHasInstructionPointerMemory",
--- a/toolkit/crashreporter/test/nsTestCrasher.cpp
+++ b/toolkit/crashreporter/test/nsTestCrasher.cpp
@@ -99,8 +99,22 @@ uint64_t SaveAppMemory()
   FILE *fp = fopen("crash-addr", "w");
   if (!fp)
     return 0;
   fprintf(fp, "%p\n", (void *)testData);
   fclose(fp);
 
   return (int64_t)testData;
 }
+
+#ifdef XP_WIN32
+static LONG WINAPI HandleException(EXCEPTION_POINTERS* exinfo)
+{
+  TerminateProcess(GetCurrentProcess(), 0);
+  return 0;
+}
+
+extern "C" NS_EXPORT
+void TryOverrideExceptionHandler()
+{
+  SetUnhandledExceptionFilter(HandleException);
+}
+#endif
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/unit/test_override_exception_handler.js
@@ -0,0 +1,12 @@
+function run_test()
+{
+  // Ensure that attempting to override the exception handler doesn't cause
+  // us to lose our exception handler.
+  do_crash(
+    function() {
+        CrashTestUtils.TryOverrideExceptionHandler();
+    },
+    function(mdump, extra) {
+    },
+    true);
+}
--- a/toolkit/crashreporter/test/unit/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit/xpcshell.ini
@@ -6,11 +6,13 @@ tail =
 [test_crash_purevirtual.js]
 [test_crash_runtimeabort.js]
 [test_crash_oom.js]
 skip-if = os == 'win' && debug
 
 [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'