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 108114 4cbb3a34f040f0a6dde2245ab76fc0cdadacb44c
parent 108113 42b4cad82f1af1b8be3b2a91863b00c5baf48117
child 108115 eae123c9c88434a7987082ce155d25dcd7cdad76
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersehsan
bugs792850
milestone18.0a1
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'