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