bug 792850 - add an xpcshell test for our SetUnhandledExceptionFilter hook. r=ehsan
☠☠ backed out by c1e97e2838a7 ☠ ☠
authorTed Mielczarek <ted.mielczarek@gmail.com>
Thu, 20 Sep 2012 10:57:08 -0400
changeset 107752 1e7050c52cb992d0b65f7d14cee28b1e3318acf0
parent 107751 776f7325952bdfb9527636007b01ad27d7cf6c33
child 107753 b7a70792a39d5fc023fd1bde84eec7031547f89a
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/google-breakpad/src/third_party/glog/src/glog/log_severity.h
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'