Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: chrome/browser/mac/exception_processor_unittest.mm

Issue 2649253003: [Mac] Sinkhole __NSFireDelayedPerform and _CFXNotificationPost in the exception preprocessor. (Closed)
Patch Set: DVLOG Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/mac/exception_processor.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/mac/exception_processor.h" 5 #import "chrome/browser/mac/exception_processor.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/wait.h> 9 #include <sys/wait.h>
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Tests that exceptions can still be caught when the preprocessor is enabled. 147 // Tests that exceptions can still be caught when the preprocessor is enabled.
148 TEST(ExceptionProcessorTest, ThrowAndCatchExceptionInRunLoop) { 148 TEST(ExceptionProcessorTest, ThrowAndCatchExceptionInRunLoop) {
149 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; 149 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
150 EXPECT_EXIT(ThrowAndCatchExceptionInRunLoop(), 150 EXPECT_EXIT(ThrowAndCatchExceptionInRunLoop(),
151 [](int exit_code) -> bool { 151 [](int exit_code) -> bool {
152 return WEXITSTATUS(exit_code) == 0; 152 return WEXITSTATUS(exit_code) == 0;
153 }, 153 },
154 ".*TEST PASS.*"); 154 ".*TEST PASS.*");
155 } 155 }
156 156
157 void ThrowExceptionFromSelector() {
158 base::mac::DisableOSCrashDumps();
159 chrome::InstallObjcExceptionPreprocessor();
160
161 NSException* exception = [NSException exceptionWithName:@"ThrowFromSelector"
162 reason:@""
163 userInfo:nil];
164
165 [exception performSelector:@selector(raise) withObject:nil afterDelay:0.1];
166
167 [[NSRunLoop currentRunLoop] runUntilDate:
168 [NSDate dateWithTimeIntervalSinceNow:10]];
169
170 fprintf(stderr, "TEST FAILED\n");
171 exit(1);
172 }
173
174 TEST(ExceptionProcessorTest, ThrowExceptionFromSelector) {
175 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
176 EXPECT_DEATH(ThrowExceptionFromSelector(),
177 ".*FATAL:exception_processor\\.mm.*"
178 "Terminating from Objective-C exception:.*");
179 }
180
181 void ThrowInNotificationObserver() {
182 base::mac::DisableOSCrashDumps();
183 chrome::InstallObjcExceptionPreprocessor();
184
185 NSNotification* notification =
186 [NSNotification notificationWithName:@"TestExceptionInObserver"
187 object:nil];
188
189 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
190 [center addObserverForName:[notification name]
191 object:nil
192 queue:nil
193 usingBlock:^(NSNotification*) {
194 [NSException raise:@"ThrowInNotificationObserver"
195 format:@""];
196 }];
197
198 [center performSelector:@selector(postNotification:)
199 withObject:notification
200 afterDelay:0];
201
202 [[NSRunLoop currentRunLoop] runUntilDate:
203 [NSDate dateWithTimeIntervalSinceNow:10]];
204
205 fprintf(stderr, "TEST FAILED\n");
206 exit(1);
207 }
208
209 TEST(ExceptionProcessorTest, ThrowInNotificationObserver) {
210 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
211 EXPECT_DEATH(ThrowInNotificationObserver(),
212 ".*FATAL:exception_processor\\.mm.*"
213 "Terminating from Objective-C exception:.*");
214 }
215
157 void ThrowExceptionInRunLoopWithoutProcessor() { 216 void ThrowExceptionInRunLoopWithoutProcessor() {
158 base::mac::DisableOSCrashDumps(); 217 base::mac::DisableOSCrashDumps();
159 chrome::UninstallObjcExceptionPreprocessor(); 218 chrome::UninstallObjcExceptionPreprocessor();
160 219
161 @try { 220 @try {
162 RaiseExceptionInRunLoop(); 221 RaiseExceptionInRunLoop();
163 } @catch (id exception) { 222 } @catch (id exception) {
164 fprintf(stderr, "TEST PASS\n"); 223 fprintf(stderr, "TEST PASS\n");
165 exit(0); 224 exit(0);
166 } 225 }
167 226
168 fprintf(stderr, "TEST FAILED\n"); 227 fprintf(stderr, "TEST FAILED\n");
169 exit(1); 228 exit(1);
170 } 229 }
171 230
172 // Tests basic exception handling when the preprocessor is disabled. 231 // Tests basic exception handling when the preprocessor is disabled.
173 TEST(ExceptionProcessorTest, ThrowExceptionInRunLoopWithoutProcessor) { 232 TEST(ExceptionProcessorTest, ThrowExceptionInRunLoopWithoutProcessor) {
174 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; 233 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
175 EXPECT_EXIT(ThrowExceptionInRunLoopWithoutProcessor(), 234 EXPECT_EXIT(ThrowExceptionInRunLoopWithoutProcessor(),
176 [](int exit_code) -> bool { 235 [](int exit_code) -> bool {
177 return WEXITSTATUS(exit_code) == 0; 236 return WEXITSTATUS(exit_code) == 0;
178 }, 237 },
179 ".*TEST PASS.*"); 238 ".*TEST PASS.*");
180 } 239 }
181 240
182 } // namespace chrome 241 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/mac/exception_processor.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698