Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/test/test_support_ios.h" | |
| 6 | |
| 5 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 6 | 8 |
| 7 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/mac/scoped_nsautorelease_pool.h" | 11 #include "base/mac/scoped_nsautorelease_pool.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_pump_default.h" | 14 #include "base/message_loop/message_pump_default.h" |
| 13 #include "base/test/test_suite.h" | 15 #include "base/test/test_suite.h" |
| 14 #include "testing/coverage_util_ios.h" | 16 #include "testing/coverage_util_ios.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 NSLog(@"Writing contents of %@ to NSLog", path); | 150 NSLog(@"Writing contents of %@ to NSLog", path); |
| 149 for (NSString* line in lines) { | 151 for (NSString* line in lines) { |
| 150 NSLog(@"%@", line); | 152 NSLog(@"%@", line); |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 } | 155 } |
| 154 | 156 |
| 155 - (void)runTests { | 157 - (void)runTests { |
| 156 int exitStatus = g_test_suite->Run(); | 158 int exitStatus = g_test_suite->Run(); |
| 157 | 159 |
| 160 if (base::IsRunningWithXCTest()) { | |
| 161 // Do not kill the app when running in XCTest mode. XCTest will shut down | |
| 162 // the app itself. | |
| 163 return; | |
| 164 } | |
| 165 | |
| 158 if ([self shouldRedirectOutputToFile]) | 166 if ([self shouldRedirectOutputToFile]) |
| 159 [self writeOutputToNSLog]; | 167 [self writeOutputToNSLog]; |
| 160 | 168 |
| 161 // If a test app is too fast, it will exit before Instruments has has a | 169 // If a test app is too fast, it will exit before Instruments has has a |
| 162 // a chance to initialize and no test results will be seen. | 170 // a chance to initialize and no test results will be seen. |
| 163 // TODO(crbug.com/137010): Figure out how much time is actually needed, and | 171 // TODO(crbug.com/137010): Figure out how much time is actually needed, and |
| 164 // sleep only to make sure that much time has elapsed since launch. | 172 // sleep only to make sure that much time has elapsed since launch. |
| 165 [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]]; | 173 [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]]; |
| 166 window_.reset(); | 174 window_.reset(); |
| 167 | 175 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 static bool ran_hook = false; | 218 static bool ran_hook = false; |
| 211 if (!ran_hook) { | 219 if (!ran_hook) { |
| 212 ran_hook = true; | 220 ran_hook = true; |
| 213 mac::ScopedNSAutoreleasePool pool; | 221 mac::ScopedNSAutoreleasePool pool; |
| 214 int exit_status = UIApplicationMain(g_argc, g_argv, nil, | 222 int exit_status = UIApplicationMain(g_argc, g_argv, nil, |
| 215 @"ChromeUnitTestDelegate"); | 223 @"ChromeUnitTestDelegate"); |
| 216 exit(exit_status); | 224 exit(exit_status); |
| 217 } | 225 } |
| 218 } | 226 } |
| 219 | 227 |
| 228 bool IsRunningWithXCTest() { | |
| 229 // Under Xcode 7.3 and 8.0, the "XCTestConfigurationFilePath" environment | |
| 230 // variable is set when running XCTests. | |
| 231 NSDictionary* environment = [[NSProcessInfo processInfo] environment]; | |
|
Mark Mentovai
2016/08/08 20:55:44
return getenv("XCTestConfigurationFilePath") != nu
rohitrao (ping after 24h)
2016/08/09 11:40:23
Done.
| |
| 232 return environment[@"XCTestConfigurationFilePath"] != nil; | |
| 233 } | |
| 234 | |
| 220 } // namespace base | 235 } // namespace base |
| OLD | NEW |