| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ios/chrome/app/main_application_delegate.h" | 5 #include "ios/chrome/app/main_application_delegate.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_nsobject.h" | |
| 11 #import "ios/chrome/app/chrome_overlay_window_testing.h" | 10 #import "ios/chrome/app/chrome_overlay_window_testing.h" |
| 12 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 13 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 14 #import "third_party/ocmock/OCMock/OCMock.h" | 13 #import "third_party/ocmock/OCMock/OCMock.h" |
| 15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
| 16 // Tests that the application does not crash if |applicationDidEnterBackground| | 19 // Tests that the application does not crash if |applicationDidEnterBackground| |
| 17 // is called when the application is launched in background. | 20 // is called when the application is launched in background. |
| 18 // http://crbug.com/437307 | 21 // http://crbug.com/437307 |
| 19 TEST(MainApplicationDelegateTest, CrashIfNotInitialized) { | 22 TEST(MainApplicationDelegateTest, CrashIfNotInitialized) { |
| 20 // Save both ChromeBrowserProvider as MainController register new instance. | 23 // Save both ChromeBrowserProvider as MainController register new instance. |
| 21 ios::ChromeBrowserProvider* stashed_chrome_browser_provider = | 24 ios::ChromeBrowserProvider* stashed_chrome_browser_provider = |
| 22 ios::GetChromeBrowserProvider(); | 25 ios::GetChromeBrowserProvider(); |
| 23 | 26 |
| 24 id application = [OCMockObject niceMockForClass:[UIApplication class]]; | 27 id application = [OCMockObject niceMockForClass:[UIApplication class]]; |
| 25 UIApplicationState backgroundState = UIApplicationStateBackground; | 28 UIApplicationState backgroundState = UIApplicationStateBackground; |
| 26 [[[application stub] andReturnValue:OCMOCK_VALUE(backgroundState)] | 29 [[[application stub] andReturnValue:OCMOCK_VALUE(backgroundState)] |
| 27 applicationState]; | 30 applicationState]; |
| 28 | 31 |
| 29 MainApplicationDelegate* delegate = | 32 MainApplicationDelegate* delegate = [[MainApplicationDelegate alloc] init]; |
| 30 [[[MainApplicationDelegate alloc] init] autorelease]; | |
| 31 [delegate application:application didFinishLaunchingWithOptions:nil]; | 33 [delegate application:application didFinishLaunchingWithOptions:nil]; |
| 32 [delegate applicationDidEnterBackground:application]; | 34 [delegate applicationDidEnterBackground:application]; |
| 33 | 35 |
| 34 // Clean up the size class recorder, which is created by the main window via | 36 // Clean up the size class recorder, which is created by the main window via |
| 35 // a previous call to |application:didFinishLaunchingWithOptions:|, to prevent | 37 // a previous call to |application:didFinishLaunchingWithOptions:|, to prevent |
| 36 // it from interfering with subsequent tests. | 38 // it from interfering with subsequent tests. |
| 37 ChromeOverlayWindow* mainWindow = | 39 ChromeOverlayWindow* mainWindow = |
| 38 base::mac::ObjCCastStrict<ChromeOverlayWindow>([delegate window]); | 40 base::mac::ObjCCastStrict<ChromeOverlayWindow>([delegate window]); |
| 39 [mainWindow unsetSizeClassRecorder]; | 41 [mainWindow unsetSizeClassRecorder]; |
| 40 | 42 |
| 41 // Restore both ChromeBrowserProvider to its original value and destroy | 43 // Restore both ChromeBrowserProvider to its original value and destroy |
| 42 // instances created by MainController. | 44 // instances created by MainController. |
| 43 DCHECK_NE(ios::GetChromeBrowserProvider(), stashed_chrome_browser_provider); | 45 DCHECK_NE(ios::GetChromeBrowserProvider(), stashed_chrome_browser_provider); |
| 44 delete ios::GetChromeBrowserProvider(); | 46 delete ios::GetChromeBrowserProvider(); |
| 45 ios::SetChromeBrowserProvider(stashed_chrome_browser_provider); | 47 ios::SetChromeBrowserProvider(stashed_chrome_browser_provider); |
| 46 } | 48 } |
| OLD | NEW |