OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/app/application_delegate/app_state.h" | 5 #import "ios/chrome/app/application_delegate/app_state.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/ios/block_types.h" | 9 #include "base/ios/block_types.h" |
10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
11 #import "base/mac/scoped_nsobject.h" | |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
14 #import "ios/chrome/app/application_delegate/app_navigation.h" | 13 #import "ios/chrome/app/application_delegate/app_navigation.h" |
15 #import "ios/chrome/app/application_delegate/app_state_testing.h" | 14 #import "ios/chrome/app/application_delegate/app_state_testing.h" |
16 #import "ios/chrome/app/application_delegate/browser_launcher.h" | 15 #import "ios/chrome/app/application_delegate/browser_launcher.h" |
17 #import "ios/chrome/app/application_delegate/fake_startup_information.h" | 16 #import "ios/chrome/app/application_delegate/fake_startup_information.h" |
18 #import "ios/chrome/app/application_delegate/memory_warning_helper.h" | 17 #import "ios/chrome/app/application_delegate/memory_warning_helper.h" |
19 #import "ios/chrome/app/application_delegate/metrics_mediator.h" | 18 #import "ios/chrome/app/application_delegate/metrics_mediator.h" |
20 #import "ios/chrome/app/application_delegate/mock_tab_opener.h" | 19 #import "ios/chrome/app/application_delegate/mock_tab_opener.h" |
21 #import "ios/chrome/app/application_delegate/startup_information.h" | 20 #import "ios/chrome/app/application_delegate/startup_information.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
37 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi der.h" | 36 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi der.h" |
38 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" | 37 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" |
39 #include "ios/public/provider/chrome/browser/user_feedback/test_user_feedback_pr ovider.h" | 38 #include "ios/public/provider/chrome/browser/user_feedback/test_user_feedback_pr ovider.h" |
40 #import "ios/testing/ocmock_complex_type_helper.h" | 39 #import "ios/testing/ocmock_complex_type_helper.h" |
41 #include "ios/web/net/request_tracker_impl.h" | 40 #include "ios/web/net/request_tracker_impl.h" |
42 #include "ios/web/public/test/test_web_thread_bundle.h" | 41 #include "ios/web/public/test/test_web_thread_bundle.h" |
43 #include "testing/platform_test.h" | 42 #include "testing/platform_test.h" |
44 #import "third_party/ocmock/OCMock/OCMock.h" | 43 #import "third_party/ocmock/OCMock/OCMock.h" |
45 #include "third_party/ocmock/gtest_support.h" | 44 #include "third_party/ocmock/gtest_support.h" |
46 | 45 |
46 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
47 #error "This file requires ARC support." | |
48 #endif | |
49 | |
47 #pragma mark - Class definition. | 50 #pragma mark - Class definition. |
48 | 51 |
49 namespace { | 52 namespace { |
50 | 53 |
51 // A block that takes self as argument and return a BOOL. | 54 // A block that takes self as argument and return a BOOL. |
52 typedef BOOL (^DecisionBlock)(id self); | 55 typedef BOOL (^DecisionBlock)(id self); |
53 // A block that takes the arguments of UserActivityHandler's | 56 // A block that takes the arguments of UserActivityHandler's |
54 // +handleStartupParametersWithTabOpener. | 57 // +handleStartupParametersWithTabOpener. |
55 typedef void (^HandleStartupParam)( | 58 typedef void (^HandleStartupParam)( |
56 id self, | 59 id self, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 } | 155 } |
153 | 156 |
154 void stubNullBrowserState(id BVC) { | 157 void stubNullBrowserState(id BVC) { |
155 [[[BVC stub] andDo:^(NSInvocation* invocation) { | 158 [[[BVC stub] andDo:^(NSInvocation* invocation) { |
156 ios::ChromeBrowserState* browserState = nullptr; | 159 ios::ChromeBrowserState* browserState = nullptr; |
157 [invocation setReturnValue:&browserState]; | 160 [invocation setReturnValue:&browserState]; |
158 }] browserState]; | 161 }] browserState]; |
159 } | 162 } |
160 | 163 |
161 void swizzleSafeModeShouldStart(BOOL shouldStart) { | 164 void swizzleSafeModeShouldStart(BOOL shouldStart) { |
162 safe_mode_swizzle_block_.reset([^BOOL(id self) { | 165 safe_mode_swizzle_block_ = [^BOOL(id self) { |
163 return shouldStart; | 166 return shouldStart; |
164 } copy]); | 167 } copy]; |
sdefresne
2017/02/20 16:00:33
nit: you don't need to copy blocks with ARC
stkhapugin
2017/02/20 16:09:03
Done.
| |
165 safe_mode_swizzler_.reset(new ScopedBlockSwizzler( | 168 safe_mode_swizzler_.reset(new ScopedBlockSwizzler( |
166 [SafeModeCoordinator class], @selector(shouldStart), | 169 [SafeModeCoordinator class], @selector(shouldStart), |
167 safe_mode_swizzle_block_)); | 170 safe_mode_swizzle_block_)); |
168 } | 171 } |
169 | 172 |
170 void swizzleMetricsMediatorDisableReporting() { | 173 void swizzleMetricsMediatorDisableReporting() { |
171 metrics_mediator_called_ = NO; | 174 metrics_mediator_called_ = NO; |
172 | 175 |
173 metrics_mediator_swizzle_block_.reset([^(id self) { | 176 metrics_mediator_swizzle_block_ = [^(id self) { |
174 metrics_mediator_called_ = YES; | 177 metrics_mediator_called_ = YES; |
175 } copy]); | 178 } copy]; |
176 | 179 |
177 metrics_mediator_swizzler_.reset(new ScopedBlockSwizzler( | 180 metrics_mediator_swizzler_.reset(new ScopedBlockSwizzler( |
178 [MetricsMediator class], @selector(disableReporting), | 181 [MetricsMediator class], @selector(disableReporting), |
179 metrics_mediator_swizzle_block_)); | 182 metrics_mediator_swizzle_block_)); |
180 } | 183 } |
181 | 184 |
182 void swizzleHandleStartupParameters( | 185 void swizzleHandleStartupParameters( |
183 id<TabOpening> expectedTabOpener, | 186 id<TabOpening> expectedTabOpener, |
184 id<BrowserViewInformation> expectedBrowserViewInformation) { | 187 id<BrowserViewInformation> expectedBrowserViewInformation) { |
185 handle_startup_swizzle_block_.reset( | 188 handle_startup_swizzle_block_ = |
186 ^(id self, id<TabOpening> tabOpener, | 189 ^(id self, id<TabOpening> tabOpener, |
187 id<StartupInformation> startupInformation, | 190 id<StartupInformation> startupInformation, |
188 id<BrowserViewInformation> browserViewInformation) { | 191 id<BrowserViewInformation> browserViewInformation) { |
189 ASSERT_EQ(startup_information_mock_, startupInformation); | 192 ASSERT_EQ(startup_information_mock_, startupInformation); |
190 ASSERT_EQ(expectedTabOpener, tabOpener); | 193 ASSERT_EQ(expectedTabOpener, tabOpener); |
191 ASSERT_EQ(expectedBrowserViewInformation, browserViewInformation); | 194 ASSERT_EQ(expectedBrowserViewInformation, browserViewInformation); |
192 }, | 195 }; |
193 base::scoped_policy::RETAIN); | |
194 | 196 |
195 handle_startup_swizzler_.reset(new ScopedBlockSwizzler( | 197 handle_startup_swizzler_.reset(new ScopedBlockSwizzler( |
196 [UserActivityHandler class], | 198 [UserActivityHandler class], |
197 @selector(handleStartupParametersWithTabOpener: | 199 @selector(handleStartupParametersWithTabOpener: |
198 startupInformation: | 200 startupInformation: |
199 browserViewInformation:), | 201 browserViewInformation:), |
200 handle_startup_swizzle_block_)); | 202 handle_startup_swizzle_block_)); |
201 } | 203 } |
202 | 204 |
203 AppState* getAppStateWithOpenNTPAndIncognitoBlock(BOOL shouldOpenNTP, | 205 AppState* getAppStateWithOpenNTPAndIncognitoBlock(BOOL shouldOpenNTP, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 tabOpener:tabOpener | 237 tabOpener:tabOpener |
236 appNavigation:appNavigation]; | 238 appNavigation:appNavigation]; |
237 | 239 |
238 initializeIncognitoBlocker(window); | 240 initializeIncognitoBlocker(window); |
239 | 241 |
240 return appState; | 242 return appState; |
241 } | 243 } |
242 | 244 |
243 AppState* getAppStateWithMock() { | 245 AppState* getAppStateWithMock() { |
244 if (!app_state_) { | 246 if (!app_state_) { |
245 app_state_.reset([[AppState alloc] | 247 app_state_ = |
246 initWithBrowserLauncher:browser_launcher_mock_ | 248 [[AppState alloc] initWithBrowserLauncher:browser_launcher_mock_ |
247 startupInformation:startup_information_mock_ | 249 startupInformation:startup_information_mock_ |
248 applicationDelegate:main_application_delegate_]); | 250 applicationDelegate:main_application_delegate_]; |
249 [app_state_ setWindow:window_]; | 251 [app_state_ setWindow:window_]; |
250 } | 252 } |
251 return app_state_; | 253 return app_state_; |
252 } | 254 } |
253 | 255 |
254 AppState* getAppStateWithRealWindow(UIWindow* window) { | 256 AppState* getAppStateWithRealWindow(UIWindow* window) { |
255 if (!app_state_) { | 257 if (!app_state_) { |
256 app_state_.reset([[AppState alloc] | 258 app_state_ = |
257 initWithBrowserLauncher:browser_launcher_mock_ | 259 [[AppState alloc] initWithBrowserLauncher:browser_launcher_mock_ |
258 startupInformation:startup_information_mock_ | 260 startupInformation:startup_information_mock_ |
259 applicationDelegate:main_application_delegate_]); | 261 applicationDelegate:main_application_delegate_]; |
260 [app_state_ setWindow:window]; | 262 [app_state_ setWindow:window]; |
261 } | 263 } |
262 return app_state_; | 264 return app_state_; |
263 } | 265 } |
264 | 266 |
265 id getBrowserLauncherMock() { return browser_launcher_mock_; } | 267 id getBrowserLauncherMock() { return browser_launcher_mock_; } |
266 id getStartupInformationMock() { return startup_information_mock_; } | 268 id getStartupInformationMock() { return startup_information_mock_; } |
267 id getApplicationDelegateMock() { return main_application_delegate_; } | 269 id getApplicationDelegateMock() { return main_application_delegate_; } |
268 id getWindowMock() { return window_; } | 270 id getWindowMock() { return window_; } |
269 id getBrowserViewInformationMock() { return browser_view_information_; } | 271 id getBrowserViewInformationMock() { return browser_view_information_; } |
270 | 272 |
271 BOOL metricsMediatorHasBeenCalled() { return metrics_mediator_called_; } | 273 BOOL metricsMediatorHasBeenCalled() { return metrics_mediator_called_; } |
272 | 274 |
273 private: | 275 private: |
274 base::scoped_nsobject<AppState> app_state_; | 276 AppState* app_state_; |
275 id browser_launcher_mock_; | 277 id browser_launcher_mock_; |
276 id startup_information_mock_; | 278 id startup_information_mock_; |
277 id main_application_delegate_; | 279 id main_application_delegate_; |
278 id window_; | 280 id window_; |
279 id browser_view_information_; | 281 id browser_view_information_; |
280 base::mac::ScopedBlock<DecisionBlock> safe_mode_swizzle_block_; | 282 DecisionBlock safe_mode_swizzle_block_; |
281 base::mac::ScopedBlock<HandleStartupParam> handle_startup_swizzle_block_; | 283 HandleStartupParam handle_startup_swizzle_block_; |
282 base::mac::ScopedBlock<ProceduralBlock> metrics_mediator_swizzle_block_; | 284 ProceduralBlock metrics_mediator_swizzle_block_; |
283 std::unique_ptr<ScopedBlockSwizzler> safe_mode_swizzler_; | 285 std::unique_ptr<ScopedBlockSwizzler> safe_mode_swizzler_; |
284 std::unique_ptr<ScopedBlockSwizzler> handle_startup_swizzler_; | 286 std::unique_ptr<ScopedBlockSwizzler> handle_startup_swizzler_; |
285 std::unique_ptr<ScopedBlockSwizzler> metrics_mediator_swizzler_; | 287 std::unique_ptr<ScopedBlockSwizzler> metrics_mediator_swizzler_; |
286 __block BOOL metrics_mediator_called_; | 288 __block BOOL metrics_mediator_called_; |
287 }; | 289 }; |
288 | 290 |
289 // TODO(crbug.com/585700): remove this. | 291 // TODO(crbug.com/585700): remove this. |
sdefresne
2017/02/20 16:00:33
I think this can be removed now. Can you do this a
stkhapugin
2017/02/20 16:09:03
I will try to remove this in a follow-up CL. Howev
| |
290 // Creates a requestTracker, needed for teardown. | 292 // Creates a requestTracker, needed for teardown. |
291 void createTracker(BOOL* created, base::Lock* lock) { | 293 void createTracker(BOOL* created, base::Lock* lock) { |
292 web::RequestTrackerImpl::GetTrackerForRequestGroupID(@"test"); | 294 web::RequestTrackerImpl::GetTrackerForRequestGroupID(@"test"); |
293 base::AutoLock scoped_lock(*lock); | 295 base::AutoLock scoped_lock(*lock); |
294 *created = YES; | 296 *created = YES; |
295 } | 297 } |
296 | 298 |
297 // Used to have a thread handling the closing of the IO threads. | 299 // Used to have a thread handling the closing of the IO threads. |
298 class AppStateWithThreadTest : public PlatformTest { | 300 class AppStateWithThreadTest : public PlatformTest { |
299 protected: | 301 protected: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 [OCMockObject mockForProtocol:@protocol(BrowserLauncher)]; | 463 [OCMockObject mockForProtocol:@protocol(BrowserLauncher)]; |
462 [[[browserLauncher stub] andReturnValue:@(INITIALIZATION_STAGE_FOREGROUND)] | 464 [[[browserLauncher stub] andReturnValue:@(INITIALIZATION_STAGE_FOREGROUND)] |
463 browserInitializationStage]; | 465 browserInitializationStage]; |
464 [[[browserLauncher stub] andReturn:browserViewInformation] | 466 [[[browserLauncher stub] andReturn:browserViewInformation] |
465 browserViewInformation]; | 467 browserViewInformation]; |
466 | 468 |
467 id applicationDelegate = | 469 id applicationDelegate = |
468 [OCMockObject mockForClass:[MainApplicationDelegate class]]; | 470 [OCMockObject mockForClass:[MainApplicationDelegate class]]; |
469 id window = [OCMockObject mockForClass:[UIWindow class]]; | 471 id window = [OCMockObject mockForClass:[UIWindow class]]; |
470 | 472 |
471 base::scoped_nsobject<FakeStartupInformation> startupInformation( | 473 FakeStartupInformation* startupInformation = |
472 [[FakeStartupInformation alloc] init]); | 474 [[FakeStartupInformation alloc] init]; |
473 [startupInformation setIsColdStart:YES]; | 475 [startupInformation setIsColdStart:YES]; |
474 | 476 |
475 base::scoped_nsobject<AppState> appState([[AppState alloc] | 477 AppState* appState = |
476 initWithBrowserLauncher:browserLauncher | 478 [[AppState alloc] initWithBrowserLauncher:browserLauncher |
477 startupInformation:startupInformation | 479 startupInformation:startupInformation |
478 applicationDelegate:applicationDelegate]); | 480 applicationDelegate:applicationDelegate]; |
479 [appState setWindow:window]; | 481 [appState setWindow:window]; |
480 | 482 |
481 ASSERT_TRUE([startupInformation isColdStart]); | 483 ASSERT_TRUE([startupInformation isColdStart]); |
482 | 484 |
483 // Action. | 485 // Action. |
484 [appState willResignActiveTabModel]; | 486 [appState willResignActiveTabModel]; |
485 | 487 |
486 // Test. | 488 // Test. |
487 EXPECT_FALSE([startupInformation isColdStart]); | 489 EXPECT_FALSE([startupInformation isColdStart]); |
488 EXPECT_OCMOCK_VERIFY(tabModel); | 490 EXPECT_OCMOCK_VERIFY(tabModel); |
(...skipping 25 matching lines...) Expand all Loading... | |
514 settingsNavigationController]; | 516 settingsNavigationController]; |
515 [[appNavigation expect] closeSettingsAnimated:NO completion:nil]; | 517 [[appNavigation expect] closeSettingsAnimated:NO completion:nil]; |
516 | 518 |
517 [[browserViewInformation expect] cleanDeviceSharingManager]; | 519 [[browserViewInformation expect] cleanDeviceSharingManager]; |
518 [[browserViewInformation expect] haltAllTabs]; | 520 [[browserViewInformation expect] haltAllTabs]; |
519 | 521 |
520 id startupInformation = | 522 id startupInformation = |
521 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 523 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
522 [[startupInformation expect] stopChromeMain]; | 524 [[startupInformation expect] stopChromeMain]; |
523 | 525 |
524 base::scoped_nsobject<AppState> appState([[AppState alloc] | 526 AppState* appState = |
525 initWithBrowserLauncher:browserLauncher | 527 [[AppState alloc] initWithBrowserLauncher:browserLauncher |
526 startupInformation:startupInformation | 528 startupInformation:startupInformation |
527 applicationDelegate:applicationDelegate]); | 529 applicationDelegate:applicationDelegate]; |
528 [appState setWindow:window]; | 530 [appState setWindow:window]; |
529 | 531 |
530 id application = [OCMockObject mockForClass:[UIApplication class]]; | 532 id application = [OCMockObject mockForClass:[UIApplication class]]; |
531 [[application expect] setMinimumBackgroundFetchInterval: | 533 [[application expect] setMinimumBackgroundFetchInterval: |
532 UIApplicationBackgroundFetchIntervalNever]; | 534 UIApplicationBackgroundFetchIntervalNever]; |
533 | 535 |
534 // Action. | 536 // Action. |
535 [appState applicationWillTerminate:application | 537 [appState applicationWillTerminate:application |
536 applicationNavigation:appNavigation]; | 538 applicationNavigation:appNavigation]; |
537 | 539 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; | 574 id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; |
573 | 575 |
574 // BrowserViewInformation. | 576 // BrowserViewInformation. |
575 id mainTabModel = [OCMockObject mockForClass:[TabModel class]]; | 577 id mainTabModel = [OCMockObject mockForClass:[TabModel class]]; |
576 [[mainTabModel expect] resetSessionMetrics]; | 578 [[mainTabModel expect] resetSessionMetrics]; |
577 [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; | 579 [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; |
578 | 580 |
579 // Swizzle Startup Parameters. | 581 // Swizzle Startup Parameters. |
580 swizzleHandleStartupParameters(tabOpener, browserViewInformation); | 582 swizzleHandleStartupParameters(tabOpener, browserViewInformation); |
581 | 583 |
582 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 584 UIWindow* window = [[UIWindow alloc] init]; |
583 AppState* appState = getAppStateWithOpenNTPAndIncognitoBlock(NO, window); | 585 AppState* appState = getAppStateWithOpenNTPAndIncognitoBlock(NO, window); |
584 | 586 |
585 ASSERT_EQ(NSUInteger(1), [window subviews].count); | 587 ASSERT_EQ(NSUInteger(1), [window subviews].count); |
586 | 588 |
587 // Action. | 589 // Action. |
588 [appState resumeSessionWithTabOpener:tabOpener tabSwitcher:tabSwitcher]; | 590 [appState resumeSessionWithTabOpener:tabOpener tabSwitcher:tabSwitcher]; |
589 | 591 |
590 // Test. | 592 // Test. |
591 EXPECT_EQ(NSUInteger(0), [window subviews].count); | 593 EXPECT_EQ(NSUInteger(0), [window subviews].count); |
592 EXPECT_OCMOCK_VERIFY(mainTabModel); | 594 EXPECT_OCMOCK_VERIFY(mainTabModel); |
(...skipping 21 matching lines...) Expand all Loading... | |
614 | 616 |
615 // BrowserViewInformation. | 617 // BrowserViewInformation. |
616 id mainTabModel = [OCMockObject mockForClass:[TabModel class]]; | 618 id mainTabModel = [OCMockObject mockForClass:[TabModel class]]; |
617 [[mainTabModel expect] resetSessionMetrics]; | 619 [[mainTabModel expect] resetSessionMetrics]; |
618 [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; | 620 [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; |
619 | 621 |
620 // TabSwitcher. | 622 // TabSwitcher. |
621 id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; | 623 id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; |
622 [[[tabSwitcher stub] andReturnValue:@YES] openNewTabFromTabSwitcher]; | 624 [[[tabSwitcher stub] andReturnValue:@YES] openNewTabFromTabSwitcher]; |
623 | 625 |
624 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 626 UIWindow* window = [[UIWindow alloc] init]; |
625 AppState* appState = getAppStateWithOpenNTPAndIncognitoBlock(YES, window); | 627 AppState* appState = getAppStateWithOpenNTPAndIncognitoBlock(YES, window); |
626 | 628 |
627 ASSERT_EQ(NSUInteger(1), [window subviews].count); | 629 ASSERT_EQ(NSUInteger(1), [window subviews].count); |
628 | 630 |
629 // Action. | 631 // Action. |
630 [appState resumeSessionWithTabOpener:tabOpener tabSwitcher:tabSwitcher]; | 632 [appState resumeSessionWithTabOpener:tabOpener tabSwitcher:tabSwitcher]; |
631 | 633 |
632 // Test. | 634 // Test. |
633 EXPECT_EQ(NSUInteger(0), [window subviews].count); | 635 EXPECT_EQ(NSUInteger(0), [window subviews].count); |
634 EXPECT_OCMOCK_VERIFY(mainTabModel); | 636 EXPECT_OCMOCK_VERIFY(mainTabModel); |
(...skipping 26 matching lines...) Expand all Loading... | |
661 [[currentBVC expect] newTab:nil]; | 663 [[currentBVC expect] newTab:nil]; |
662 stubNullBrowserState(currentBVC); | 664 stubNullBrowserState(currentBVC); |
663 | 665 |
664 [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; | 666 [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; |
665 [[[browserViewInformation stub] andReturn:currentBVC] currentBVC]; | 667 [[[browserViewInformation stub] andReturn:currentBVC] currentBVC]; |
666 | 668 |
667 // TabSwitcher. | 669 // TabSwitcher. |
668 id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; | 670 id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; |
669 [[[tabSwitcher stub] andReturnValue:@NO] openNewTabFromTabSwitcher]; | 671 [[[tabSwitcher stub] andReturnValue:@NO] openNewTabFromTabSwitcher]; |
670 | 672 |
671 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 673 UIWindow* window = [[UIWindow alloc] init]; |
672 AppState* appState = getAppStateWithOpenNTPAndIncognitoBlock(YES, window); | 674 AppState* appState = getAppStateWithOpenNTPAndIncognitoBlock(YES, window); |
673 | 675 |
674 // incognitoBlocker. | 676 // incognitoBlocker. |
675 ASSERT_EQ(NSUInteger(1), [window subviews].count); | 677 ASSERT_EQ(NSUInteger(1), [window subviews].count); |
676 | 678 |
677 // Action. | 679 // Action. |
678 [appState resumeSessionWithTabOpener:tabOpener tabSwitcher:tabSwitcher]; | 680 [appState resumeSessionWithTabOpener:tabOpener tabSwitcher:tabSwitcher]; |
679 | 681 |
680 // Test. | 682 // Test. |
681 EXPECT_EQ(NSUInteger(0), [window subviews].count); | 683 EXPECT_EQ(NSUInteger(0), [window subviews].count); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; | 811 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; |
810 id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)]; | 812 id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)]; |
811 id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)]; | 813 id appNavigation = [OCMockObject mockForProtocol:@protocol(AppNavigation)]; |
812 | 814 |
813 BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND; | 815 BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND; |
814 [[[getBrowserLauncherMock() stub] andReturnValue:@(stage)] | 816 [[[getBrowserLauncherMock() stub] andReturnValue:@(stage)] |
815 browserInitializationStage]; | 817 browserInitializationStage]; |
816 | 818 |
817 AppState* appState = getAppStateWithMock(); | 819 AppState* appState = getAppStateWithMock(); |
818 | 820 |
819 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 821 UIWindow* window = [[UIWindow alloc] init]; |
820 appState.safeModeCoordinator = | 822 appState.safeModeCoordinator = |
821 [[[SafeModeCoordinator alloc] initWithWindow:window] autorelease]; | 823 [[SafeModeCoordinator alloc] initWithWindow:window]; |
822 | 824 |
823 ASSERT_TRUE([appState isInSafeMode]); | 825 ASSERT_TRUE([appState isInSafeMode]); |
824 | 826 |
825 // Actions. | 827 // Actions. |
826 [appState applicationWillEnterForeground:application | 828 [appState applicationWillEnterForeground:application |
827 metricsMediator:metricsMediator | 829 metricsMediator:metricsMediator |
828 memoryHelper:memoryHelper | 830 memoryHelper:memoryHelper |
829 tabOpener:tabOpener | 831 tabOpener:tabOpener |
830 appNavigation:appNavigation]; | 832 appNavigation:appNavigation]; |
831 } | 833 } |
832 | 834 |
833 // Tests that -applicationDidEnterBackground creates an incognito blocker. | 835 // Tests that -applicationDidEnterBackground creates an incognito blocker. |
834 TEST_F(AppStateTest, applicationDidEnterBackgroundIncognito) { | 836 TEST_F(AppStateTest, applicationDidEnterBackgroundIncognito) { |
835 // Setup. | 837 // Setup. |
836 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 838 UIWindow* window = [[UIWindow alloc] init]; |
837 id application = [OCMockObject niceMockForClass:[UIApplication class]]; | 839 id application = [OCMockObject niceMockForClass:[UIApplication class]]; |
838 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; | 840 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; |
839 id browserViewInformation = getBrowserViewInformationMock(); | 841 id browserViewInformation = getBrowserViewInformationMock(); |
840 id tabModel = [OCMockObject mockForClass:[TabModel class]]; | 842 id tabModel = [OCMockObject mockForClass:[TabModel class]]; |
841 id startupInformation = getStartupInformationMock(); | 843 id startupInformation = getStartupInformationMock(); |
842 id browserLauncher = getBrowserLauncherMock(); | 844 id browserLauncher = getBrowserLauncherMock(); |
843 BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND; | 845 BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND; |
844 | 846 |
845 AppState* appState = getAppStateWithRealWindow(window); | 847 AppState* appState = getAppStateWithRealWindow(window); |
846 | 848 |
(...skipping 19 matching lines...) Expand all Loading... | |
866 // Tests. | 868 // Tests. |
867 EXPECT_OCMOCK_VERIFY(startupInformation); | 869 EXPECT_OCMOCK_VERIFY(startupInformation); |
868 EXPECT_TRUE(metricsMediatorHasBeenCalled()); | 870 EXPECT_TRUE(metricsMediatorHasBeenCalled()); |
869 EXPECT_EQ(NSUInteger(1), [window subviews].count); | 871 EXPECT_EQ(NSUInteger(1), [window subviews].count); |
870 } | 872 } |
871 | 873 |
872 // Tests that -applicationDidEnterBackground do nothing if the application has | 874 // Tests that -applicationDidEnterBackground do nothing if the application has |
873 // never been in a Foreground stage. | 875 // never been in a Foreground stage. |
874 TEST_F(AppStateTest, applicationDidEnterBackgroundStageBackground) { | 876 TEST_F(AppStateTest, applicationDidEnterBackgroundStageBackground) { |
875 // Setup. | 877 // Setup. |
876 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 878 UIWindow* window = [[UIWindow alloc] init]; |
877 id application = [OCMockObject mockForClass:[UIApplication class]]; | 879 id application = [OCMockObject mockForClass:[UIApplication class]]; |
878 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; | 880 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; |
879 id browserLauncher = getBrowserLauncherMock(); | 881 id browserLauncher = getBrowserLauncherMock(); |
880 BrowserInitializationStageType stage = INITIALIZATION_STAGE_BACKGROUND; | 882 BrowserInitializationStageType stage = INITIALIZATION_STAGE_BACKGROUND; |
881 | 883 |
882 [[[browserLauncher stub] andReturnValue:@(stage)] browserInitializationStage]; | 884 [[[browserLauncher stub] andReturnValue:@(stage)] browserInitializationStage]; |
883 | 885 |
884 ASSERT_EQ(NSUInteger(0), [window subviews].count); | 886 ASSERT_EQ(NSUInteger(0), [window subviews].count); |
885 | 887 |
886 // Action. | 888 // Action. |
887 [getAppStateWithRealWindow(window) applicationDidEnterBackground:application | 889 [getAppStateWithRealWindow(window) applicationDidEnterBackground:application |
888 memoryHelper:memoryHelper | 890 memoryHelper:memoryHelper |
889 tabSwitcherIsActive:YES]; | 891 tabSwitcherIsActive:YES]; |
890 | 892 |
891 // Tests. | 893 // Tests. |
892 EXPECT_EQ(NSUInteger(0), [window subviews].count); | 894 EXPECT_EQ(NSUInteger(0), [window subviews].count); |
893 } | 895 } |
894 | 896 |
895 // Tests that -applicationDidEnterBackground does not create an incognito | 897 // Tests that -applicationDidEnterBackground does not create an incognito |
896 // blocker if there is no incognito tab. | 898 // blocker if there is no incognito tab. |
897 TEST_F(AppStateTest, applicationDidEnterBackgroundNoIncognitoBlocker) { | 899 TEST_F(AppStateTest, applicationDidEnterBackgroundNoIncognitoBlocker) { |
898 // Setup. | 900 // Setup. |
899 UIWindow* window = [[[UIWindow alloc] init] autorelease]; | 901 UIWindow* window = [[UIWindow alloc] init]; |
900 id application = [OCMockObject niceMockForClass:[UIApplication class]]; | 902 id application = [OCMockObject niceMockForClass:[UIApplication class]]; |
901 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; | 903 id memoryHelper = [OCMockObject mockForClass:[MemoryWarningHelper class]]; |
902 id browserViewInformation = getBrowserViewInformationMock(); | 904 id browserViewInformation = getBrowserViewInformationMock(); |
903 id tabModel = [OCMockObject mockForClass:[TabModel class]]; | 905 id tabModel = [OCMockObject mockForClass:[TabModel class]]; |
904 id startupInformation = getStartupInformationMock(); | 906 id startupInformation = getStartupInformationMock(); |
905 id browserLauncher = getBrowserLauncherMock(); | 907 id browserLauncher = getBrowserLauncherMock(); |
906 BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND; | 908 BrowserInitializationStageType stage = INITIALIZATION_STAGE_FOREGROUND; |
907 | 909 |
908 AppState* appState = getAppStateWithRealWindow(window); | 910 AppState* appState = getAppStateWithRealWindow(window); |
909 | 911 |
(...skipping 14 matching lines...) Expand all Loading... | |
924 // Action. | 926 // Action. |
925 [appState applicationDidEnterBackground:application | 927 [appState applicationDidEnterBackground:application |
926 memoryHelper:memoryHelper | 928 memoryHelper:memoryHelper |
927 tabSwitcherIsActive:YES]; | 929 tabSwitcherIsActive:YES]; |
928 | 930 |
929 // Tests. | 931 // Tests. |
930 EXPECT_OCMOCK_VERIFY(startupInformation); | 932 EXPECT_OCMOCK_VERIFY(startupInformation); |
931 EXPECT_TRUE(metricsMediatorHasBeenCalled()); | 933 EXPECT_TRUE(metricsMediatorHasBeenCalled()); |
932 EXPECT_EQ(NSUInteger(0), [window subviews].count); | 934 EXPECT_EQ(NSUInteger(0), [window subviews].count); |
933 } | 935 } |
OLD | NEW |