Index: base/test/run_hook_ios.mm |
diff --git a/base/test/main_hook_ios.mm b/base/test/run_hook_ios.mm |
similarity index 74% |
rename from base/test/main_hook_ios.mm |
rename to base/test/run_hook_ios.mm |
index 6d7bc449e008aae10e4786cd1a6113889aea4f0b..ef2a41db5b3957daa1347e7c2fef1858037fcb80 100644 |
--- a/base/test/main_hook_ios.mm |
+++ b/base/test/run_hook_ios.mm |
@@ -1,8 +1,8 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/test/main_hook.h" |
+#include "base/test/run_hook_ios.h" |
#import <UIKit/UIKit.h> |
@@ -14,23 +14,17 @@ |
// Springboard will kill any iOS app that fails to check in after launch within |
// a given time. These two classes prevent this from happening. |
-// MainHook saves the chrome main() and calls UIApplicationMain(), |
-// providing an application delegate class: ChromeUnitTestDelegate. The delegate |
-// listens for UIApplicationDidFinishLaunchingNotification. When the |
-// notification is received, it fires main() again to have the real work done. |
- |
-// Example usage: |
-// int main(int argc, char** argv) { |
-// MainHook hook(main, argc, argv); |
-// // Testing code goes here. There should be no code above MainHook. If |
-// // there is, it will be run twice. |
-// } |
+// RunHook::Init saves the TestSuite and argc/argv, then invoking RunHook::Run |
+// calls UIApplicationMain(), providing an application delegate class: |
+// ChromeUnitTestDelegate. The delegate implements |
+// application:didFinishLaunchingWithOptions: to invoke the TestSuite's Run |
+// method. |
// Since the executable isn't likely to be a real iOS UI, the delegate puts up a |
// window displaying the app name. If a bunch of apps using MainHook are being |
// run in a row, this provides an indication of which one is currently running. |
-static MainHook::MainType g_main_func = NULL; |
+static base::TestSuite* g_test_suite = NULL; |
static int g_argc; |
static char** g_argv; |
@@ -39,7 +33,7 @@ static char** g_argv; |
@end |
@interface ChromeUnitTestDelegate : NSObject { |
-@private |
+ @private |
scoped_nsobject<UIWindow> window_; |
} |
- (void)runTests; |
@@ -70,7 +64,7 @@ static char** g_argv; |
} |
- (void)runTests { |
- int exitStatus = g_main_func(g_argc, g_argv); |
+ int exitStatus = g_test_suite->Run(); |
// If a test app is too fast, it will exit before Instruments has has a |
// a chance to initialize and no test results will be seen. |
@@ -91,17 +85,18 @@ static char** g_argv; |
#pragma mark - |
-MainHook::MainHook(MainType main_func, int argc, char* argv[]) { |
+void RunHook::Init(base::TestSuite* suite, int argc, char* argv[]) { |
+ g_test_suite = suite; |
+ g_argc = argc; |
+ g_argv = argv; |
+} |
+ |
+void RunHook::RunTestsFromApp() { |
static bool ran_hook = false; |
if (!ran_hook) { |
ran_hook = true; |
- |
- g_main_func = main_func; |
- g_argc = argc; |
- g_argv = argv; |
- |
base::mac::ScopedNSAutoreleasePool pool; |
- int exit_status = UIApplicationMain(argc, argv, nil, |
+ int exit_status = UIApplicationMain(g_argc, g_argv, nil, |
@"ChromeUnitTestDelegate"); |
exit(exit_status); |
} |