| Index: ios/chrome/app/main_application_delegate_unittest.mm
|
| diff --git a/ios/chrome/app/main_application_delegate_unittest.mm b/ios/chrome/app/main_application_delegate_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ba947d29f2e9b04795991ff45db5977137fffa13
|
| --- /dev/null
|
| +++ b/ios/chrome/app/main_application_delegate_unittest.mm
|
| @@ -0,0 +1,46 @@
|
| +// Copyright 2012 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 "ios/chrome/app/main_application_delegate.h"
|
| +
|
| +#import <Foundation/Foundation.h>
|
| +
|
| +#import "base/mac/foundation_util.h"
|
| +#include "base/mac/scoped_nsobject.h"
|
| +#import "ios/chrome/app/chrome_overlay_window_testing.h"
|
| +#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
|
| +#include "testing/platform_test.h"
|
| +#import "third_party/ocmock/OCMock/OCMock.h"
|
| +
|
| +// Tests that the application does not crash if |applicationDidEnterBackground|
|
| +// is called when the application is launched in background.
|
| +// http://crbug.com/437307
|
| +TEST(MainApplicationDelegateTest, CrashIfNotInitialized) {
|
| + // Save both ChromeBrowserProvider as MainController register new instance.
|
| + ios::ChromeBrowserProvider* stashed_chrome_browser_provider =
|
| + ios::GetChromeBrowserProvider();
|
| +
|
| + id application = [OCMockObject niceMockForClass:[UIApplication class]];
|
| + UIApplicationState backgroundState = UIApplicationStateBackground;
|
| + [[[application stub] andReturnValue:OCMOCK_VALUE(backgroundState)]
|
| + applicationState];
|
| +
|
| + MainApplicationDelegate* delegate =
|
| + [[[MainApplicationDelegate alloc] init] autorelease];
|
| + [delegate application:application didFinishLaunchingWithOptions:nil];
|
| + [delegate applicationDidEnterBackground:application];
|
| +
|
| + // Clean up the size class recorder, which is created by the main window via
|
| + // a previous call to |application:didFinishLaunchingWithOptions:|, to prevent
|
| + // it from interfering with subsequent tests.
|
| + ChromeOverlayWindow* mainWindow =
|
| + base::mac::ObjCCastStrict<ChromeOverlayWindow>([delegate window]);
|
| + [mainWindow unsetSizeClassRecorder];
|
| +
|
| + // Restore both ChromeBrowserProvider to its original value and destroy
|
| + // instances created by MainController.
|
| + DCHECK_NE(ios::GetChromeBrowserProvider(), stashed_chrome_browser_provider);
|
| + delete ios::GetChromeBrowserProvider();
|
| + ios::SetChromeBrowserProvider(stashed_chrome_browser_provider);
|
| +}
|
|
|