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 #import <UIKit/UIKit.h> | 5 #import <UIKit/UIKit.h> |
6 | 6 |
7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/scoped_nsautorelease_pool.h" | 9 #include "base/mac/scoped_nsautorelease_pool.h" |
10 #include "base/memory/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/message_loop/message_pump_default.h" | 12 #include "base/message_loop/message_pump_default.h" |
13 #include "base/test/test_suite.h" | 13 #include "base/test/test_suite.h" |
14 | 14 |
15 // Springboard will kill any iOS app that fails to check in after launch within | 15 // Springboard will kill any iOS app that fails to check in after launch within |
16 // a given time. Starting a UIApplication before invoking TestSuite::Run | 16 // a given time. Starting a UIApplication before invoking TestSuite::Run |
17 // prevents this from happening. | 17 // prevents this from happening. |
18 | 18 |
19 // InitIOSRunHook saves the TestSuite and argc/argv, then invoking | 19 // InitIOSRunHook saves the TestSuite and argc/argv, then invoking |
20 // RunTestsFromIOSApp calls UIApplicationMain(), providing an application | 20 // RunTestsFromIOSApp calls UIApplicationMain(), providing an application |
21 // delegate class: ChromeUnitTestDelegate. The delegate implements | 21 // delegate class: ChromeUnitTestDelegate. The delegate implements |
22 // application:didFinishLaunchingWithOptions: to invoke the TestSuite's Run | 22 // application:didFinishLaunchingWithOptions: to invoke the TestSuite's Run |
23 // method. | 23 // method. |
24 | 24 |
25 // Since the executable isn't likely to be a real iOS UI, the delegate puts up a | 25 // Since the executable isn't likely to be a real iOS UI, the delegate puts up a |
26 // window displaying the app name. If a bunch of apps using MainHook are being | 26 // window displaying the app name. If a bunch of apps using MainHook are being |
27 // run in a row, this provides an indication of which one is currently running. | 27 // run in a row, this provides an indication of which one is currently running. |
28 | 28 |
29 static base::TestSuite* g_test_suite = NULL; | 29 static base::TestSuite* g_test_suite = NULL; |
30 static int g_argc; | 30 static int g_argc; |
31 static char** g_argv; | 31 static char** g_argv; |
32 | 32 |
33 @interface UIApplication (Testing) | 33 @interface UIApplication (Testing) |
34 - (void) _terminateWithStatus:(int)status; | 34 - (void) _terminateWithStatus:(int)status; |
35 @end | 35 @end |
36 | 36 |
37 @interface ChromeUnitTestDelegate : NSObject { | 37 @interface ChromeUnitTestDelegate : NSObject { |
38 @private | 38 @private |
39 scoped_nsobject<UIWindow> window_; | 39 base::scoped_nsobject<UIWindow> window_; |
40 } | 40 } |
41 - (void)runTests; | 41 - (void)runTests; |
42 @end | 42 @end |
43 | 43 |
44 @implementation ChromeUnitTestDelegate | 44 @implementation ChromeUnitTestDelegate |
45 | 45 |
46 - (BOOL)application:(UIApplication *)application | 46 - (BOOL)application:(UIApplication *)application |
47 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | 47 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
48 | 48 |
49 CGRect bounds = [[UIScreen mainScreen] bounds]; | 49 CGRect bounds = [[UIScreen mainScreen] bounds]; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (!ran_hook) { | 179 if (!ran_hook) { |
180 ran_hook = true; | 180 ran_hook = true; |
181 mac::ScopedNSAutoreleasePool pool; | 181 mac::ScopedNSAutoreleasePool pool; |
182 int exit_status = UIApplicationMain(g_argc, g_argv, nil, | 182 int exit_status = UIApplicationMain(g_argc, g_argv, nil, |
183 @"ChromeUnitTestDelegate"); | 183 @"ChromeUnitTestDelegate"); |
184 exit(exit_status); | 184 exit(exit_status); |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 } // namespace base | 188 } // namespace base |
OLD | NEW |