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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 | 6 |
7 #import "base/mac/bind_objc_block.h" | |
8 #include "base/threading/thread.h" | 7 #include "base/threading/thread.h" |
9 #import "ios/chrome/app/application_delegate/app_state.h" | 8 #import "ios/chrome/app/application_delegate/app_state.h" |
10 #import "ios/chrome/app/application_delegate/url_opener.h" | 9 #import "ios/chrome/app/application_delegate/url_opener.h" |
11 #include "ios/chrome/app/main_controller_private.h" | 10 #include "ios/chrome/app/main_controller_private.h" |
12 #import "ios/chrome/browser/tabs/tab_model.h" | 11 #import "ios/chrome/browser/tabs/tab_model.h" |
13 #import "ios/chrome/test/base/scoped_block_swizzler.h" | 12 #import "ios/chrome/test/base/scoped_block_swizzler.h" |
14 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
15 #import "third_party/ocmock/OCMock/OCMock.h" | 14 #import "third_party/ocmock/OCMock/OCMock.h" |
16 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
17 #pragma mark - MainController Testing Additions | 20 #pragma mark - MainController Testing Additions |
18 | 21 |
19 @interface MainController (TestingAdditions) | 22 @interface MainController (TestingAdditions) |
20 - (id)initForTesting; | 23 - (id)initForTesting; |
21 @end | 24 @end |
22 | 25 |
23 @implementation MainController (TestingAdditions) | 26 @implementation MainController (TestingAdditions) |
24 - (id)initForTesting { | 27 - (id)initForTesting { |
25 self = [self init]; | 28 self = [self init]; |
26 if (self) { | 29 if (self) { |
(...skipping 26 matching lines...) Expand all Loading... |
53 | 56 |
54 class TabOpenerTest : public PlatformTest { | 57 class TabOpenerTest : public PlatformTest { |
55 protected: | 58 protected: |
56 BOOL swizzleHasBeenCalled() { return swizzle_block_executed_; } | 59 BOOL swizzleHasBeenCalled() { return swizzle_block_executed_; } |
57 | 60 |
58 void swizzleHandleLaunchOptions( | 61 void swizzleHandleLaunchOptions( |
59 NSDictionary* expectedLaunchOptions, | 62 NSDictionary* expectedLaunchOptions, |
60 id<StartupInformation> expectedStartupInformation, | 63 id<StartupInformation> expectedStartupInformation, |
61 AppState* expectedAppState) { | 64 AppState* expectedAppState) { |
62 swizzle_block_executed_ = NO; | 65 swizzle_block_executed_ = NO; |
63 swizzle_block_.reset( | 66 swizzle_block_ = |
64 [^(id self, NSDictionary* options, BOOL applicationActive, | 67 [^(id self, NSDictionary* options, BOOL applicationActive, |
65 id<TabOpening> tabOpener, id<StartupInformation> startupInformation, | 68 id<TabOpening> tabOpener, id<StartupInformation> startupInformation, |
66 AppState* appState) { | 69 AppState* appState) { |
67 swizzle_block_executed_ = YES; | 70 swizzle_block_executed_ = YES; |
68 EXPECT_EQ(expectedLaunchOptions, options); | 71 EXPECT_EQ(expectedLaunchOptions, options); |
69 EXPECT_EQ(expectedStartupInformation, startupInformation); | 72 EXPECT_EQ(expectedStartupInformation, startupInformation); |
70 EXPECT_EQ(main_controller_.get(), tabOpener); | 73 EXPECT_EQ(main_controller_, tabOpener); |
71 EXPECT_EQ(expectedAppState, appState); | 74 EXPECT_EQ(expectedAppState, appState); |
72 } copy]); | 75 } copy]; |
73 URL_opening_handle_launch_swizzler_.reset(new ScopedBlockSwizzler( | 76 URL_opening_handle_launch_swizzler_.reset(new ScopedBlockSwizzler( |
74 [URLOpener class], @selector(handleLaunchOptions: | 77 [URLOpener class], @selector(handleLaunchOptions: |
75 applicationActive: | 78 applicationActive: |
76 tabOpener: | 79 tabOpener: |
77 startupInformation: | 80 startupInformation: |
78 appState:), | 81 appState:), |
79 swizzle_block_)); | 82 swizzle_block_)); |
80 } | 83 } |
81 | 84 |
82 MainController* GetMainController() { | 85 MainController* GetMainController() { |
83 if (!main_controller_.get()) { | 86 if (!main_controller_) { |
84 main_controller_.reset([[MainController alloc] initForTesting]); | 87 main_controller_ = [[MainController alloc] initForTesting]; |
85 } | 88 } |
86 return main_controller_.get(); | 89 return main_controller_; |
87 } | 90 } |
88 | 91 |
89 private: | 92 private: |
90 base::scoped_nsobject<MainController> main_controller_; | 93 MainController* main_controller_; |
91 __block BOOL swizzle_block_executed_; | 94 __block BOOL swizzle_block_executed_; |
92 base::mac::ScopedBlock<HandleLaunchOptions> swizzle_block_; | 95 HandleLaunchOptions swizzle_block_; |
93 std::unique_ptr<ScopedBlockSwizzler> URL_opening_handle_launch_swizzler_; | 96 std::unique_ptr<ScopedBlockSwizzler> URL_opening_handle_launch_swizzler_; |
94 }; | 97 }; |
95 | 98 |
96 #pragma mark - Tests. | 99 #pragma mark - Tests. |
97 | 100 |
98 // Tests that -newTabFromLaunchOptions calls +handleLaunchOption and reset | 101 // Tests that -newTabFromLaunchOptions calls +handleLaunchOption and reset |
99 // options. | 102 // options. |
100 TEST_F(TabOpenerTest, openTabFromLaunchOptionsWithOptions) { | 103 TEST_F(TabOpenerTest, openTabFromLaunchOptionsWithOptions) { |
101 // Setup. | 104 // Setup. |
102 NSString* sourceApplication = @"com.apple.mobilesafari"; | 105 NSString* sourceApplication = @"com.apple.mobilesafari"; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 137 |
135 // Action. | 138 // Action. |
136 [tabOpener openTabFromLaunchOptions:nil | 139 [tabOpener openTabFromLaunchOptions:nil |
137 startupInformation:startupInformationMock | 140 startupInformation:startupInformationMock |
138 appState:appStateMock]; | 141 appState:appStateMock]; |
139 | 142 |
140 // Test. | 143 // Test. |
141 EXPECT_FALSE(swizzleHasBeenCalled()); | 144 EXPECT_FALSE(swizzleHasBeenCalled()); |
142 } | 145 } |
143 } // namespace | 146 } // namespace |
OLD | NEW |