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 #include "ios/chrome/app/application_delegate/user_activity_handler.h" | 5 #include "ios/chrome/app/application_delegate/user_activity_handler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import <CoreSpotlight/CoreSpotlight.h> | 9 #import <CoreSpotlight/CoreSpotlight.h> |
10 | 10 |
11 #include "base/ios/ios_util.h" | 11 #include "base/ios/ios_util.h" |
12 #include "base/mac/scoped_block.h" | 12 #include "base/mac/scoped_block.h" |
13 #include "base/mac/scoped_nsobject.h" | |
14 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
15 #include "base/test/scoped_command_line.h" | 14 #include "base/test/scoped_command_line.h" |
16 #include "components/handoff/handoff_utility.h" | 15 #include "components/handoff/handoff_utility.h" |
17 #include "ios/chrome/app/application_delegate/fake_startup_information.h" | 16 #include "ios/chrome/app/application_delegate/fake_startup_information.h" |
18 #include "ios/chrome/app/application_delegate/mock_tab_opener.h" | 17 #include "ios/chrome/app/application_delegate/mock_tab_opener.h" |
19 #include "ios/chrome/app/application_delegate/startup_information.h" | 18 #include "ios/chrome/app/application_delegate/startup_information.h" |
20 #include "ios/chrome/app/application_delegate/tab_opening.h" | 19 #include "ios/chrome/app/application_delegate/tab_opening.h" |
21 #include "ios/chrome/app/application_mode.h" | 20 #include "ios/chrome/app/application_mode.h" |
22 #include "ios/chrome/app/main_controller.h" | 21 #include "ios/chrome/app/main_controller.h" |
23 #include "ios/chrome/app/spotlight/actions_spotlight_manager.h" | 22 #include "ios/chrome/app/spotlight/actions_spotlight_manager.h" |
24 #import "ios/chrome/app/spotlight/spotlight_util.h" | 23 #import "ios/chrome/app/spotlight/spotlight_util.h" |
25 #include "ios/chrome/browser/app_startup_parameters.h" | 24 #include "ios/chrome/browser/app_startup_parameters.h" |
26 #include "ios/chrome/browser/chrome_switches.h" | 25 #include "ios/chrome/browser/chrome_switches.h" |
27 #include "ios/chrome/browser/chrome_url_constants.h" | 26 #include "ios/chrome/browser/chrome_url_constants.h" |
28 #import "ios/chrome/browser/tabs/tab.h" | 27 #import "ios/chrome/browser/tabs/tab.h" |
29 #import "ios/chrome/browser/tabs/tab_model.h" | 28 #import "ios/chrome/browser/tabs/tab_model.h" |
30 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 29 #import "ios/chrome/browser/tabs/tab_model_observer.h" |
31 #import "ios/chrome/browser/u2f/u2f_controller.h" | 30 #import "ios/chrome/browser/u2f/u2f_controller.h" |
32 #import "ios/chrome/test/base/scoped_block_swizzler.h" | 31 #import "ios/chrome/test/base/scoped_block_swizzler.h" |
33 #import "net/base/mac/url_conversions.h" | 32 #import "net/base/mac/url_conversions.h" |
34 #include "net/test/gtest_util.h" | 33 #include "net/test/gtest_util.h" |
35 #include "testing/platform_test.h" | 34 #include "testing/platform_test.h" |
36 #import "third_party/ocmock/OCMock/OCMock.h" | 35 #import "third_party/ocmock/OCMock/OCMock.h" |
37 #include "third_party/ocmock/gtest_support.h" | 36 #include "third_party/ocmock/gtest_support.h" |
38 #include "ui/base/page_transition_types.h" | 37 #include "ui/base/page_transition_types.h" |
39 #include "url/gurl.h" | 38 #include "url/gurl.h" |
40 | 39 |
40 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
41 #error "This file requires ARC support." | |
42 #endif | |
43 | |
41 #pragma mark - Tab Mock | 44 #pragma mark - Tab Mock |
42 | 45 |
43 // Tab mock for using in UserActivity tests. | 46 // Tab mock for using in UserActivity tests. |
44 @interface UserActivityHandlerTabMock : NSObject | 47 @interface UserActivityHandlerTabMock : NSObject |
45 | 48 |
46 @property(nonatomic, readonly) GURL url; | 49 @property(nonatomic, readonly) GURL url; |
47 @property(nonatomic, readonly) NSString* tabId; | 50 @property(copy, nonatomic, readonly) NSString* tabId; |
sdefresne
2017/02/20 16:00:33
please put "nonatomic" first
stkhapugin
2017/02/20 16:09:03
Done.
| |
48 | 51 |
49 @end | 52 @end |
50 | 53 |
51 @implementation UserActivityHandlerTabMock | 54 @implementation UserActivityHandlerTabMock |
52 @synthesize url = _url; | 55 @synthesize url = _url; |
53 @synthesize tabId = _tabId; | 56 @synthesize tabId = _tabId; |
54 | 57 |
55 - (void)evaluateU2FResultFromURL:(const GURL&)url { | 58 - (void)evaluateU2FResultFromURL:(const GURL&)url { |
56 _url = url; | 59 _url = url; |
57 } | 60 } |
58 | 61 |
59 @end | 62 @end |
60 | 63 |
61 #pragma mark - TabModel Mock | 64 #pragma mark - TabModel Mock |
62 | 65 |
63 // TabModel mock for using in UserActivity tests. | 66 // TabModel mock for using in UserActivity tests. |
64 @interface UserActivityHandlerTabModelMock : NSObject<NSFastEnumeration> { | 67 @interface UserActivityHandlerTabModelMock : NSObject<NSFastEnumeration> { |
65 @private | 68 @private |
66 base::scoped_nsobject<NSMutableArray> _tabs; | 69 NSMutableArray* _tabs; |
67 } | 70 } |
68 | 71 |
69 - (void)addTab:(Tab*)tab; | 72 - (void)addTab:(Tab*)tab; |
70 - (void)addObserver:(id<TabModelObserver>)observer; | 73 - (void)addObserver:(id<TabModelObserver>)observer; |
71 - (void)removeObserver:(id<TabModelObserver>)observer; | 74 - (void)removeObserver:(id<TabModelObserver>)observer; |
72 | 75 |
73 @end | 76 @end |
74 | 77 |
75 @implementation UserActivityHandlerTabModelMock | 78 @implementation UserActivityHandlerTabModelMock |
76 | 79 |
77 - (instancetype)init { | 80 - (instancetype)init { |
78 if ((self = [super init])) { | 81 if ((self = [super init])) { |
79 _tabs.reset([[NSMutableArray alloc] init]); | 82 _tabs = [[NSMutableArray alloc] init]; |
80 } | 83 } |
81 return self; | 84 return self; |
82 } | 85 } |
83 | 86 |
84 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state | 87 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state |
85 objects:(id*)stackbuf | 88 objects: |
89 (__unsafe_unretained id _Nonnull*)stackbuf | |
86 count:(NSUInteger)len { | 90 count:(NSUInteger)len { |
87 return [_tabs countByEnumeratingWithState:state objects:stackbuf count:len]; | 91 return [_tabs countByEnumeratingWithState:state objects:stackbuf count:len]; |
88 } | 92 } |
89 | 93 |
90 - (void)addTab:(Tab*)tab { | 94 - (void)addTab:(Tab*)tab { |
91 [_tabs addObject:tab]; | 95 [_tabs addObject:tab]; |
92 } | 96 } |
93 | 97 |
94 - (void)addObserver:(id<TabModelObserver>)observer { | 98 - (void)addObserver:(id<TabModelObserver>)observer { |
95 // Empty. | 99 // Empty. |
(...skipping 14 matching lines...) Expand all Loading... | |
110 id<StartupInformation>, | 114 id<StartupInformation>, |
111 id<BrowserViewInformation>); | 115 id<BrowserViewInformation>); |
112 | 116 |
113 // A block that takes a BOOL argument and returns nothing. | 117 // A block that takes a BOOL argument and returns nothing. |
114 typedef void (^conditionBlock)(BOOL); | 118 typedef void (^conditionBlock)(BOOL); |
115 | 119 |
116 class UserActivityHandlerTest : public PlatformTest { | 120 class UserActivityHandlerTest : public PlatformTest { |
117 protected: | 121 protected: |
118 void swizzleHandleStartupParameters() { | 122 void swizzleHandleStartupParameters() { |
119 handle_startup_parameters_has_been_called_ = NO; | 123 handle_startup_parameters_has_been_called_ = NO; |
120 swizzle_block_.reset([^(id self) { | 124 swizzle_block_ = [^(id self) { |
121 handle_startup_parameters_has_been_called_ = YES; | 125 handle_startup_parameters_has_been_called_ = YES; |
122 } copy]); | 126 } copy]; |
123 user_activity_handler_swizzler_.reset(new ScopedBlockSwizzler( | 127 user_activity_handler_swizzler_.reset(new ScopedBlockSwizzler( |
124 [UserActivityHandler class], | 128 [UserActivityHandler class], |
125 @selector(handleStartupParametersWithTabOpener: | 129 @selector(handleStartupParametersWithTabOpener: |
126 startupInformation: | 130 startupInformation: |
127 browserViewInformation:), | 131 browserViewInformation:), |
128 swizzle_block_)); | 132 swizzle_block_)); |
129 } | 133 } |
130 | 134 |
131 BOOL getHandleStartupParametersHasBeenCalled() { | 135 BOOL getHandleStartupParametersHasBeenCalled() { |
132 return handle_startup_parameters_has_been_called_; | 136 return handle_startup_parameters_has_been_called_; |
133 } | 137 } |
134 | 138 |
135 void resetHandleStartupParametersHasBeenCalled() { | 139 void resetHandleStartupParametersHasBeenCalled() { |
136 handle_startup_parameters_has_been_called_ = NO; | 140 handle_startup_parameters_has_been_called_ = NO; |
137 } | 141 } |
138 | 142 |
139 conditionBlock getCompletionHandler() { | 143 conditionBlock getCompletionHandler() { |
140 if (!completion_block_) { | 144 if (!completion_block_) { |
141 block_executed_ = NO; | 145 block_executed_ = NO; |
142 completion_block_.reset([^(BOOL arg) { | 146 completion_block_ = [^(BOOL arg) { |
143 block_executed_ = YES; | 147 block_executed_ = YES; |
144 block_argument_ = arg; | 148 block_argument_ = arg; |
145 } copy]); | 149 } copy]; |
146 } | 150 } |
147 return completion_block_; | 151 return completion_block_; |
148 } | 152 } |
149 | 153 |
150 BOOL completionHandlerExecuted() { return block_executed_; } | 154 BOOL completionHandlerExecuted() { return block_executed_; } |
151 | 155 |
152 BOOL completionHandlerArgument() { return block_argument_; } | 156 BOOL completionHandlerArgument() { return block_argument_; } |
153 | 157 |
154 private: | 158 private: |
155 __block BOOL block_executed_; | 159 __block BOOL block_executed_; |
156 __block BOOL block_argument_; | 160 __block BOOL block_argument_; |
157 std::unique_ptr<ScopedBlockSwizzler> user_activity_handler_swizzler_; | 161 std::unique_ptr<ScopedBlockSwizzler> user_activity_handler_swizzler_; |
158 base::mac::ScopedBlock<startupParameterBlock> swizzle_block_; | 162 startupParameterBlock swizzle_block_; |
159 base::mac::ScopedBlock<conditionBlock> completion_block_; | 163 conditionBlock completion_block_; |
160 __block BOOL handle_startup_parameters_has_been_called_; | 164 __block BOOL handle_startup_parameters_has_been_called_; |
161 }; | 165 }; |
162 | 166 |
163 #pragma mark - Tests. | 167 #pragma mark - Tests. |
164 | 168 |
165 // Tests that Chrome notifies the user if we are passing a correct | 169 // Tests that Chrome notifies the user if we are passing a correct |
166 // userActivityType. | 170 // userActivityType. |
167 TEST(UserActivityHandlerNoFixtureTest, | 171 TEST(UserActivityHandlerNoFixtureTest, |
168 willContinueUserActivityCorrectActivity) { | 172 willContinueUserActivityCorrectActivity) { |
169 EXPECT_TRUE([UserActivityHandler | 173 EXPECT_TRUE([UserActivityHandler |
(...skipping 26 matching lines...) Expand all Loading... | |
196 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityFromGarbage) { | 200 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityFromGarbage) { |
197 // Setup. | 201 // Setup. |
198 NSString* handoffWithSuffix = | 202 NSString* handoffWithSuffix = |
199 [handoff::kChromeHandoffActivityType stringByAppendingString:@"test"]; | 203 [handoff::kChromeHandoffActivityType stringByAppendingString:@"test"]; |
200 NSString* handoffWithPrefix = | 204 NSString* handoffWithPrefix = |
201 [@"test" stringByAppendingString:handoff::kChromeHandoffActivityType]; | 205 [@"test" stringByAppendingString:handoff::kChromeHandoffActivityType]; |
202 NSArray* userActivityTypes = @[ | 206 NSArray* userActivityTypes = @[ |
203 @"thisIsGarbage", @"it.does.not.work", handoffWithSuffix, handoffWithPrefix | 207 @"thisIsGarbage", @"it.does.not.work", handoffWithSuffix, handoffWithPrefix |
204 ]; | 208 ]; |
205 for (NSString* userActivityType in userActivityTypes) { | 209 for (NSString* userActivityType in userActivityTypes) { |
206 base::scoped_nsobject<NSUserActivity> userActivity( | 210 NSUserActivity* userActivity = |
207 [[NSUserActivity alloc] initWithActivityType:userActivityType]); | 211 [[NSUserActivity alloc] initWithActivityType:userActivityType]; |
208 [userActivity setWebpageURL:[NSURL URLWithString:@"http://www.google.com"]]; | 212 [userActivity setWebpageURL:[NSURL URLWithString:@"http://www.google.com"]]; |
209 | 213 |
210 // The test will fail is a method of those objects is called. | 214 // The test will fail is a method of those objects is called. |
211 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; | 215 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; |
212 id startupInformationMock = | 216 id startupInformationMock = |
213 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 217 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
214 | 218 |
215 // Action. | 219 // Action. |
216 BOOL result = | 220 BOOL result = |
217 [UserActivityHandler continueUserActivity:userActivity | 221 [UserActivityHandler continueUserActivity:userActivity |
218 applicationIsActive:NO | 222 applicationIsActive:NO |
219 tabOpener:tabOpenerMock | 223 tabOpener:tabOpenerMock |
220 startupInformation:startupInformationMock]; | 224 startupInformation:startupInformationMock]; |
221 | 225 |
222 // Tests. | 226 // Tests. |
223 EXPECT_FALSE(result); | 227 EXPECT_FALSE(result); |
224 } | 228 } |
225 } | 229 } |
226 | 230 |
227 // Tests that Chrome does not continue the activity if the webpage url is not | 231 // Tests that Chrome does not continue the activity if the webpage url is not |
228 // set. | 232 // set. |
229 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityNoWebpage) { | 233 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityNoWebpage) { |
230 // Setup. | 234 // Setup. |
231 base::scoped_nsobject<NSUserActivity> userActivity([[NSUserActivity alloc] | 235 NSUserActivity* userActivity = [[NSUserActivity alloc] |
232 initWithActivityType:handoff::kChromeHandoffActivityType]); | 236 initWithActivityType:handoff::kChromeHandoffActivityType]; |
233 | 237 |
234 // The test will fail is a method of those objects is called. | 238 // The test will fail is a method of those objects is called. |
235 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; | 239 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; |
236 id startupInformationMock = | 240 id startupInformationMock = |
237 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 241 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
238 | 242 |
239 // Action. | 243 // Action. |
240 BOOL result = | 244 BOOL result = |
241 [UserActivityHandler continueUserActivity:userActivity | 245 [UserActivityHandler continueUserActivity:userActivity |
242 applicationIsActive:NO | 246 applicationIsActive:NO |
243 tabOpener:tabOpenerMock | 247 tabOpener:tabOpenerMock |
244 startupInformation:startupInformationMock]; | 248 startupInformation:startupInformationMock]; |
245 | 249 |
246 // Tests. | 250 // Tests. |
247 EXPECT_FALSE(result); | 251 EXPECT_FALSE(result); |
248 } | 252 } |
249 | 253 |
250 // Tests that Chrome does not continue the activity if the activity is a | 254 // Tests that Chrome does not continue the activity if the activity is a |
251 // Spotlight action of an unknown type. | 255 // Spotlight action of an unknown type. |
252 TEST(UserActivityHandlerNoFixtureTest, | 256 TEST(UserActivityHandlerNoFixtureTest, |
253 continueUserActivitySpotlightActionFromGarbage) { | 257 continueUserActivitySpotlightActionFromGarbage) { |
254 // Only test Spotlight if it is enabled and available on the device. | 258 // Only test Spotlight if it is enabled and available on the device. |
255 if (!spotlight::IsSpotlightAvailable()) { | 259 if (!spotlight::IsSpotlightAvailable()) { |
256 return; | 260 return; |
257 } | 261 } |
258 // Setup. | 262 // Setup. |
259 base::scoped_nsobject<NSUserActivity> userActivity( | 263 NSUserActivity* userActivity = |
260 [[NSUserActivity alloc] initWithActivityType:CSSearchableItemActionType]); | 264 [[NSUserActivity alloc] initWithActivityType:CSSearchableItemActionType]; |
261 NSString* invalidAction = | 265 NSString* invalidAction = |
262 [NSString stringWithFormat:@"%@.invalidAction", | 266 [NSString stringWithFormat:@"%@.invalidAction", |
263 spotlight::StringFromSpotlightDomain( | 267 spotlight::StringFromSpotlightDomain( |
264 spotlight::DOMAIN_ACTIONS)]; | 268 spotlight::DOMAIN_ACTIONS)]; |
265 NSDictionary* userInfo = | 269 NSDictionary* userInfo = |
266 @{CSSearchableItemActivityIdentifier : invalidAction}; | 270 @{CSSearchableItemActivityIdentifier : invalidAction}; |
267 [userActivity addUserInfoEntriesFromDictionary:userInfo]; | 271 [userActivity addUserInfoEntriesFromDictionary:userInfo]; |
268 | 272 |
269 // Enable the SpotlightActions experiment. | 273 // Enable the SpotlightActions experiment. |
270 base::test::ScopedCommandLine scoped_command_line; | 274 base::test::ScopedCommandLine scoped_command_line; |
(...skipping 12 matching lines...) Expand all Loading... | |
283 startupInformation:startupInformationMock]; | 287 startupInformation:startupInformationMock]; |
284 | 288 |
285 // Tests. | 289 // Tests. |
286 EXPECT_FALSE(result); | 290 EXPECT_FALSE(result); |
287 } | 291 } |
288 | 292 |
289 // Tests that Chrome continues the activity if the application is in background | 293 // Tests that Chrome continues the activity if the application is in background |
290 // by saving the url to startupParameters. | 294 // by saving the url to startupParameters. |
291 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityBackground) { | 295 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityBackground) { |
292 // Setup. | 296 // Setup. |
293 base::scoped_nsobject<NSUserActivity> userActivity([[NSUserActivity alloc] | 297 NSUserActivity* userActivity = [[NSUserActivity alloc] |
294 initWithActivityType:handoff::kChromeHandoffActivityType]); | 298 initWithActivityType:handoff::kChromeHandoffActivityType]; |
295 NSURL* nsurl = [NSURL URLWithString:@"http://www.google.com"]; | 299 NSURL* nsurl = [NSURL URLWithString:@"http://www.google.com"]; |
296 [userActivity setWebpageURL:nsurl]; | 300 [userActivity setWebpageURL:nsurl]; |
297 | 301 |
298 id startupInformationMock = | 302 id startupInformationMock = |
299 [OCMockObject niceMockForProtocol:@protocol(StartupInformation)]; | 303 [OCMockObject niceMockForProtocol:@protocol(StartupInformation)]; |
300 [[startupInformationMock expect] | 304 [[startupInformationMock expect] |
301 setStartupParameters:[OCMArg checkWithBlock:^BOOL(id value) { | 305 setStartupParameters:[OCMArg checkWithBlock:^BOOL(id value) { |
302 EXPECT_TRUE([value isKindOfClass:[AppStartupParameters class]]); | 306 EXPECT_TRUE([value isKindOfClass:[AppStartupParameters class]]); |
303 | 307 |
304 AppStartupParameters* startupParameters = (AppStartupParameters*)value; | 308 AppStartupParameters* startupParameters = (AppStartupParameters*)value; |
(...skipping 13 matching lines...) Expand all Loading... | |
318 | 322 |
319 // Test. | 323 // Test. |
320 EXPECT_OCMOCK_VERIFY(startupInformationMock); | 324 EXPECT_OCMOCK_VERIFY(startupInformationMock); |
321 EXPECT_TRUE(result); | 325 EXPECT_TRUE(result); |
322 } | 326 } |
323 | 327 |
324 // Tests that Chrome continues the activity if the application is in foreground | 328 // Tests that Chrome continues the activity if the application is in foreground |
325 // by opening a new tab. | 329 // by opening a new tab. |
326 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityForeground) { | 330 TEST(UserActivityHandlerNoFixtureTest, continueUserActivityForeground) { |
327 // Setup. | 331 // Setup. |
328 base::scoped_nsobject<NSUserActivity> userActivity([[NSUserActivity alloc] | 332 NSUserActivity* userActivity = [[NSUserActivity alloc] |
329 initWithActivityType:handoff::kChromeHandoffActivityType]); | 333 initWithActivityType:handoff::kChromeHandoffActivityType]; |
330 NSURL* nsurl = [NSURL URLWithString:@"http://www.google.com"]; | 334 NSURL* nsurl = [NSURL URLWithString:@"http://www.google.com"]; |
331 [userActivity setWebpageURL:nsurl]; | 335 [userActivity setWebpageURL:nsurl]; |
332 | 336 |
333 base::scoped_nsobject<MockTabOpener> tabOpener([[MockTabOpener alloc] init]); | 337 MockTabOpener* tabOpener = [[MockTabOpener alloc] init]; |
334 | 338 |
335 id startupInformationMock = | 339 id startupInformationMock = |
336 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 340 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
337 [[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI]; | 341 [[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI]; |
338 | 342 |
339 base::scoped_nsobject<AppStartupParameters> startupParams( | 343 AppStartupParameters* startupParams = [[AppStartupParameters alloc] |
340 [[AppStartupParameters alloc] | 344 initWithExternalURL:(GURL("http://www.google.com"))]; |
341 initWithExternalURL:(GURL("http://www.google.com"))]); | |
342 [[[startupInformationMock stub] andReturn:startupParams] startupParameters]; | 345 [[[startupInformationMock stub] andReturn:startupParams] startupParameters]; |
343 | 346 |
344 // Action. | 347 // Action. |
345 BOOL result = | 348 BOOL result = |
346 [UserActivityHandler continueUserActivity:userActivity | 349 [UserActivityHandler continueUserActivity:userActivity |
347 applicationIsActive:YES | 350 applicationIsActive:YES |
348 tabOpener:tabOpener | 351 tabOpener:tabOpener |
349 startupInformation:startupInformationMock]; | 352 startupInformation:startupInformationMock]; |
350 | 353 |
351 // Test. | 354 // Test. |
352 EXPECT_EQ(net::GURLWithNSURL(nsurl), [tabOpener url]); | 355 EXPECT_EQ(net::GURLWithNSURL(nsurl), [tabOpener url]); |
353 EXPECT_TRUE(result); | 356 EXPECT_TRUE(result); |
354 } | 357 } |
355 | 358 |
356 // Tests that a new tab is created when application is started via Universal | 359 // Tests that a new tab is created when application is started via Universal |
357 // Link. | 360 // Link. |
358 TEST_F(UserActivityHandlerTest, continueUserActivityBrowsingWeb) { | 361 TEST_F(UserActivityHandlerTest, continueUserActivityBrowsingWeb) { |
359 base::scoped_nsobject<NSUserActivity> userActivity([[NSUserActivity alloc] | 362 NSUserActivity* userActivity = [[NSUserActivity alloc] |
360 initWithActivityType:NSUserActivityTypeBrowsingWeb]); | 363 initWithActivityType:NSUserActivityTypeBrowsingWeb]; |
361 // This URL is passed to application by iOS but is not used in this part | 364 // This URL is passed to application by iOS but is not used in this part |
362 // of application logic. | 365 // of application logic. |
363 NSURL* nsurl = [NSURL URLWithString:@"http://goo.gl/foo/bar"]; | 366 NSURL* nsurl = [NSURL URLWithString:@"http://goo.gl/foo/bar"]; |
364 [userActivity setWebpageURL:nsurl]; | 367 [userActivity setWebpageURL:nsurl]; |
365 | 368 |
366 base::scoped_nsobject<MockTabOpener> tabOpener([[MockTabOpener alloc] init]); | 369 MockTabOpener* tabOpener = [[MockTabOpener alloc] init]; |
367 | 370 |
368 // Use an object to capture the startup paramters set by UserActivityHandler. | 371 // Use an object to capture the startup paramters set by UserActivityHandler. |
369 base::scoped_nsobject<FakeStartupInformation> fakeStartupInformation( | 372 FakeStartupInformation* fakeStartupInformation = |
370 [[FakeStartupInformation alloc] init]); | 373 [[FakeStartupInformation alloc] init]; |
371 [fakeStartupInformation setIsPresentingFirstRunUI:NO]; | 374 [fakeStartupInformation setIsPresentingFirstRunUI:NO]; |
372 | 375 |
373 BOOL result = | 376 BOOL result = |
374 [UserActivityHandler continueUserActivity:userActivity | 377 [UserActivityHandler continueUserActivity:userActivity |
375 applicationIsActive:YES | 378 applicationIsActive:YES |
376 tabOpener:tabOpener | 379 tabOpener:tabOpener |
377 startupInformation:fakeStartupInformation]; | 380 startupInformation:fakeStartupInformation]; |
378 | 381 |
379 GURL newTabURL(kChromeUINewTabURL); | 382 GURL newTabURL(kChromeUINewTabURL); |
380 EXPECT_EQ(newTabURL, [tabOpener url]); | 383 EXPECT_EQ(newTabURL, [tabOpener url]); |
381 // AppStartupParameters default to opening pages in non-Incognito mode. | 384 // AppStartupParameters default to opening pages in non-Incognito mode. |
382 EXPECT_EQ(ApplicationMode::NORMAL, [tabOpener applicationMode]); | 385 EXPECT_EQ(ApplicationMode::NORMAL, [tabOpener applicationMode]); |
383 EXPECT_TRUE(result); | 386 EXPECT_TRUE(result); |
384 // Verifies that a new tab is being requested. | 387 // Verifies that a new tab is being requested. |
385 EXPECT_EQ(newTabURL, | 388 EXPECT_EQ(newTabURL, |
386 [[fakeStartupInformation startupParameters] externalURL]); | 389 [[fakeStartupInformation startupParameters] externalURL]); |
387 } | 390 } |
388 | 391 |
389 // Tests that continueUserActivity sets startupParameters accordingly to the | 392 // Tests that continueUserActivity sets startupParameters accordingly to the |
390 // Spotlight action used. | 393 // Spotlight action used. |
391 TEST_F(UserActivityHandlerTest, continueUserActivityShortcutActions) { | 394 TEST_F(UserActivityHandlerTest, continueUserActivityShortcutActions) { |
392 // Only test Spotlight if it is enabled and available on the device. | 395 // Only test Spotlight if it is enabled and available on the device. |
393 if (!spotlight::IsSpotlightAvailable()) { | 396 if (!spotlight::IsSpotlightAvailable()) { |
394 return; | 397 return; |
395 } | 398 } |
396 // Setup. | 399 // Setup. |
397 GURL gurlNewTab(kChromeUINewTabURL); | 400 GURL gurlNewTab(kChromeUINewTabURL); |
398 base::scoped_nsobject<FakeStartupInformation> fakeStartupInformation( | 401 FakeStartupInformation* fakeStartupInformation = |
399 [[FakeStartupInformation alloc] init]); | 402 [[FakeStartupInformation alloc] init]; |
400 | 403 |
401 NSArray* parametersToTest = @[ | 404 NSArray* parametersToTest = @[ |
402 @[ | 405 @[ |
403 base::SysUTF8ToNSString(spotlight::kSpotlightActionNewTab), @NO, @NO, @NO | 406 base::SysUTF8ToNSString(spotlight::kSpotlightActionNewTab), @NO, @NO, @NO |
404 ], | 407 ], |
405 @[ | 408 @[ |
406 base::SysUTF8ToNSString(spotlight::kSpotlightActionNewIncognitoTab), @YES, | 409 base::SysUTF8ToNSString(spotlight::kSpotlightActionNewIncognitoTab), @YES, |
407 @NO, @NO | 410 @NO, @NO |
408 ], | 411 ], |
409 @[ | 412 @[ |
410 base::SysUTF8ToNSString(spotlight::kSpotlightActionVoiceSearch), @NO, | 413 base::SysUTF8ToNSString(spotlight::kSpotlightActionVoiceSearch), @NO, |
411 @YES, @NO | 414 @YES, @NO |
412 ], | 415 ], |
413 @[ | 416 @[ |
414 base::SysUTF8ToNSString(spotlight::kSpotlightActionQRScanner), @NO, @NO, | 417 base::SysUTF8ToNSString(spotlight::kSpotlightActionQRScanner), @NO, @NO, |
415 @YES | 418 @YES |
416 ] | 419 ] |
417 ]; | 420 ]; |
418 | 421 |
419 // Enable the Spotlight Actions experiment. | 422 // Enable the Spotlight Actions experiment. |
420 base::test::ScopedCommandLine scoped_command_line; | 423 base::test::ScopedCommandLine scoped_command_line; |
421 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 424 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
422 switches::kEnableSpotlightActions); | 425 switches::kEnableSpotlightActions); |
423 | 426 |
424 for (id parameters in parametersToTest) { | 427 for (id parameters in parametersToTest) { |
425 base::scoped_nsobject<NSUserActivity> userActivity([[NSUserActivity alloc] | 428 NSUserActivity* userActivity = [[NSUserActivity alloc] |
426 initWithActivityType:CSSearchableItemActionType]); | 429 initWithActivityType:CSSearchableItemActionType]; |
427 NSString* action = [NSString | 430 NSString* action = [NSString |
428 stringWithFormat:@"%@.%@", spotlight::StringFromSpotlightDomain( | 431 stringWithFormat:@"%@.%@", spotlight::StringFromSpotlightDomain( |
429 spotlight::DOMAIN_ACTIONS), | 432 spotlight::DOMAIN_ACTIONS), |
430 parameters[0]]; | 433 parameters[0]]; |
431 NSDictionary* userInfo = @{CSSearchableItemActivityIdentifier : action}; | 434 NSDictionary* userInfo = @{CSSearchableItemActivityIdentifier : action}; |
432 [userActivity addUserInfoEntriesFromDictionary:userInfo]; | 435 [userActivity addUserInfoEntriesFromDictionary:userInfo]; |
433 | 436 |
434 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; | 437 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; |
435 | 438 |
436 // Action. | 439 // Action. |
(...skipping 14 matching lines...) Expand all Loading... | |
451 EXPECT_EQ([parameters[3] boolValue], | 454 EXPECT_EQ([parameters[3] boolValue], |
452 [fakeStartupInformation startupParameters].launchQRScanner); | 455 [fakeStartupInformation startupParameters].launchQRScanner); |
453 } | 456 } |
454 } | 457 } |
455 | 458 |
456 // Tests that handleStartupParameters with a non-U2F url opens a new tab. | 459 // Tests that handleStartupParameters with a non-U2F url opens a new tab. |
457 TEST(UserActivityHandlerNoFixtureTest, handleStartupParamsNonU2F) { | 460 TEST(UserActivityHandlerNoFixtureTest, handleStartupParamsNonU2F) { |
458 // Setup. | 461 // Setup. |
459 GURL gurl("http://www.google.com"); | 462 GURL gurl("http://www.google.com"); |
460 | 463 |
461 base::scoped_nsobject<AppStartupParameters> startupParams( | 464 AppStartupParameters* startupParams = |
462 [[AppStartupParameters alloc] initWithExternalURL:gurl]); | 465 [[AppStartupParameters alloc] initWithExternalURL:gurl]; |
463 [startupParams setLaunchInIncognito:YES]; | 466 [startupParams setLaunchInIncognito:YES]; |
464 | 467 |
465 id startupInformationMock = | 468 id startupInformationMock = |
466 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 469 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
467 [[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI]; | 470 [[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI]; |
468 [[[startupInformationMock stub] andReturn:startupParams] startupParameters]; | 471 [[[startupInformationMock stub] andReturn:startupParams] startupParameters]; |
469 [[startupInformationMock expect] setStartupParameters:nil]; | 472 [[startupInformationMock expect] setStartupParameters:nil]; |
470 | 473 |
471 base::scoped_nsobject<MockTabOpener> tabOpener([[MockTabOpener alloc] init]); | 474 MockTabOpener* tabOpener = [[MockTabOpener alloc] init]; |
472 | 475 |
473 // The test will fail is a method of this object is called. | 476 // The test will fail is a method of this object is called. |
474 id browserViewMock = | 477 id browserViewMock = |
475 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; | 478 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; |
476 | 479 |
477 // Action. | 480 // Action. |
478 [UserActivityHandler | 481 [UserActivityHandler |
479 handleStartupParametersWithTabOpener:tabOpener | 482 handleStartupParametersWithTabOpener:tabOpener |
480 startupInformation:startupInformationMock | 483 startupInformation:startupInformationMock |
481 browserViewInformation:browserViewMock]; | 484 browserViewInformation:browserViewMock]; |
482 [tabOpener completionBlock](); | 485 [tabOpener completionBlock](); |
483 | 486 |
484 // Tests. | 487 // Tests. |
485 EXPECT_OCMOCK_VERIFY(startupInformationMock); | 488 EXPECT_OCMOCK_VERIFY(startupInformationMock); |
486 EXPECT_EQ(gurl, [tabOpener url]); | 489 EXPECT_EQ(gurl, [tabOpener url]); |
487 EXPECT_EQ(ApplicationMode::INCOGNITO, [tabOpener applicationMode]); | 490 EXPECT_EQ(ApplicationMode::INCOGNITO, [tabOpener applicationMode]); |
488 } | 491 } |
489 | 492 |
490 // Tests that handleStartupParameters with a U2F url opens in the correct tab. | 493 // Tests that handleStartupParameters with a U2F url opens in the correct tab. |
491 TEST(UserActivityHandlerNoFixtureTest, handleStartupParamsU2F) { | 494 TEST(UserActivityHandlerNoFixtureTest, handleStartupParamsU2F) { |
492 // Setup. | 495 // Setup. |
493 GURL gurl("chromium://u2f-callback?isU2F=1&tabID=B05B1860"); | 496 GURL gurl("chromium://u2f-callback?isU2F=1&tabID=B05B1860"); |
494 NSString* tabID = [U2FController tabIDFromResponseURL:gurl]; | 497 NSString* tabID = [U2FController tabIDFromResponseURL:gurl]; |
495 | 498 |
496 base::scoped_nsobject<AppStartupParameters> startupParams( | 499 AppStartupParameters* startupParams = |
497 [[AppStartupParameters alloc] initWithExternalURL:gurl]); | 500 [[AppStartupParameters alloc] initWithExternalURL:gurl]; |
498 [startupParams setLaunchInIncognito:YES]; | 501 [startupParams setLaunchInIncognito:YES]; |
499 | 502 |
500 base::scoped_nsobject<UserActivityHandlerTabMock> tabMock( | 503 UserActivityHandlerTabMock* tabMock = |
501 [[UserActivityHandlerTabMock alloc] init]); | 504 [[UserActivityHandlerTabMock alloc] init]; |
502 id tabOCMock = [OCMockObject partialMockForObject:tabMock]; | 505 id tabOCMock = [OCMockObject partialMockForObject:tabMock]; |
503 [[[tabOCMock stub] andReturn:tabID] tabId]; | 506 [[[tabOCMock stub] andReturn:tabID] tabId]; |
504 | 507 |
505 base::scoped_nsobject<UserActivityHandlerTabModelMock> tabModel( | 508 UserActivityHandlerTabModelMock* tabModel = |
506 [[UserActivityHandlerTabModelMock alloc] init]); | 509 [[UserActivityHandlerTabModelMock alloc] init]; |
507 [tabModel addTab:(Tab*)tabMock.get()]; | 510 [tabModel addTab:(Tab*)tabMock]; |
508 | 511 |
509 id startupInformationMock = | 512 id startupInformationMock = |
510 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 513 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
511 [[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI]; | 514 [[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI]; |
512 [[[startupInformationMock stub] andReturn:startupParams] startupParameters]; | 515 [[[startupInformationMock stub] andReturn:startupParams] startupParameters]; |
513 [[startupInformationMock expect] setStartupParameters:nil]; | 516 [[startupInformationMock expect] setStartupParameters:nil]; |
514 | 517 |
515 id browserViewInformationMock = | 518 id browserViewInformationMock = |
516 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; | 519 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; |
517 [[[browserViewInformationMock stub] andReturn:(TabModel*)tabModel.get()] | 520 [[[browserViewInformationMock stub] andReturn:(TabModel*)tabModel] |
518 mainTabModel]; | 521 mainTabModel]; |
519 [[[browserViewInformationMock stub] andReturn:(TabModel*)tabModel.get()] | 522 [[[browserViewInformationMock stub] andReturn:(TabModel*)tabModel] |
520 otrTabModel]; | 523 otrTabModel]; |
521 | 524 |
522 base::scoped_nsobject<MockTabOpener> tabOpener([[MockTabOpener alloc] init]); | 525 MockTabOpener* tabOpener = [[MockTabOpener alloc] init]; |
523 | 526 |
524 // Action. | 527 // Action. |
525 [UserActivityHandler | 528 [UserActivityHandler |
526 handleStartupParametersWithTabOpener:tabOpener | 529 handleStartupParametersWithTabOpener:tabOpener |
527 startupInformation:startupInformationMock | 530 startupInformation:startupInformationMock |
528 browserViewInformation:browserViewInformationMock]; | 531 browserViewInformation:browserViewInformationMock]; |
529 | 532 |
530 // Tests. | 533 // Tests. |
531 EXPECT_OCMOCK_VERIFY(startupInformationMock); | 534 EXPECT_OCMOCK_VERIFY(startupInformationMock); |
532 EXPECT_EQ(gurl, [tabMock url]); | 535 EXPECT_EQ(gurl, [tabMock url]); |
533 } | 536 } |
534 | 537 |
535 // Tests that performActionForShortcutItem set startupParameters accordingly to | 538 // Tests that performActionForShortcutItem set startupParameters accordingly to |
536 // the shortcut used | 539 // the shortcut used |
537 TEST_F(UserActivityHandlerTest, performActionForShortcutItemWithRealShortcut) { | 540 TEST_F(UserActivityHandlerTest, performActionForShortcutItemWithRealShortcut) { |
538 // Setup. | 541 // Setup. |
539 GURL gurlNewTab("chrome://newtab/"); | 542 GURL gurlNewTab("chrome://newtab/"); |
540 | 543 |
541 base::scoped_nsobject<FakeStartupInformation> fakeStartupInformation( | 544 FakeStartupInformation* fakeStartupInformation = |
542 [[FakeStartupInformation alloc] init]); | 545 [[FakeStartupInformation alloc] init]; |
543 [fakeStartupInformation setIsPresentingFirstRunUI:NO]; | 546 [fakeStartupInformation setIsPresentingFirstRunUI:NO]; |
544 | 547 |
545 NSArray* parametersToTest = @[ | 548 NSArray* parametersToTest = @[ |
546 @[ @"OpenNewTab", @NO, @NO, @NO ], @[ @"OpenIncognitoTab", @YES, @NO, @NO ], | 549 @[ @"OpenNewTab", @NO, @NO, @NO ], @[ @"OpenIncognitoTab", @YES, @NO, @NO ], |
547 @[ @"OpenVoiceSearch", @NO, @YES, @NO ], | 550 @[ @"OpenVoiceSearch", @NO, @YES, @NO ], |
548 @[ @"OpenQRScanner", @NO, @NO, @YES ] | 551 @[ @"OpenQRScanner", @NO, @NO, @YES ] |
549 ]; | 552 ]; |
550 | 553 |
551 swizzleHandleStartupParameters(); | 554 swizzleHandleStartupParameters(); |
552 | 555 |
553 for (id parameters in parametersToTest) { | 556 for (id parameters in parametersToTest) { |
554 base::scoped_nsobject<UIApplicationShortcutItem> shortcut( | 557 UIApplicationShortcutItem* shortcut = |
555 [[UIApplicationShortcutItem alloc] initWithType:parameters[0] | 558 [[UIApplicationShortcutItem alloc] initWithType:parameters[0] |
556 localizedTitle:parameters[0]]); | 559 localizedTitle:parameters[0]]; |
557 | 560 |
558 resetHandleStartupParametersHasBeenCalled(); | 561 resetHandleStartupParametersHasBeenCalled(); |
559 | 562 |
560 // The test will fail is a method of those objects is called. | 563 // The test will fail is a method of those objects is called. |
561 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; | 564 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; |
562 id browserViewInformationMock = | 565 id browserViewInformationMock = |
563 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; | 566 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; |
564 | 567 |
565 // Action. | 568 // Action. |
566 [UserActivityHandler | 569 [UserActivityHandler |
(...skipping 19 matching lines...) Expand all Loading... | |
586 } | 589 } |
587 | 590 |
588 // Tests that performActionForShortcutItem just executes the completionHandler | 591 // Tests that performActionForShortcutItem just executes the completionHandler |
589 // with NO if the firstRunUI is present. | 592 // with NO if the firstRunUI is present. |
590 TEST_F(UserActivityHandlerTest, performActionForShortcutItemWithFirstRunUI) { | 593 TEST_F(UserActivityHandlerTest, performActionForShortcutItemWithFirstRunUI) { |
591 // Setup. | 594 // Setup. |
592 id startupInformationMock = | 595 id startupInformationMock = |
593 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; | 596 [OCMockObject mockForProtocol:@protocol(StartupInformation)]; |
594 [[[startupInformationMock stub] andReturnValue:@YES] isPresentingFirstRunUI]; | 597 [[[startupInformationMock stub] andReturnValue:@YES] isPresentingFirstRunUI]; |
595 | 598 |
596 base::scoped_nsobject<UIApplicationShortcutItem> shortcut( | 599 UIApplicationShortcutItem* shortcut = |
597 [[UIApplicationShortcutItem alloc] initWithType:@"OpenNewTab" | 600 [[UIApplicationShortcutItem alloc] initWithType:@"OpenNewTab" |
598 localizedTitle:@""]); | 601 localizedTitle:@""]; |
599 | 602 |
600 swizzleHandleStartupParameters(); | 603 swizzleHandleStartupParameters(); |
601 | 604 |
602 // The test will fail is a method of those objects is called. | 605 // The test will fail is a method of those objects is called. |
603 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; | 606 id tabOpenerMock = [OCMockObject mockForProtocol:@protocol(TabOpening)]; |
604 id browserViewInformationMock = | 607 id browserViewInformationMock = |
605 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; | 608 [OCMockObject mockForProtocol:@protocol(BrowserViewInformation)]; |
606 | 609 |
607 // Action. | 610 // Action. |
608 [UserActivityHandler performActionForShortcutItem:shortcut | 611 [UserActivityHandler performActionForShortcutItem:shortcut |
609 completionHandler:getCompletionHandler() | 612 completionHandler:getCompletionHandler() |
610 tabOpener:tabOpenerMock | 613 tabOpener:tabOpenerMock |
611 startupInformation:startupInformationMock | 614 startupInformation:startupInformationMock |
612 browserViewInformation:browserViewInformationMock]; | 615 browserViewInformation:browserViewInformationMock]; |
613 | 616 |
614 // Tests. | 617 // Tests. |
615 EXPECT_TRUE(completionHandlerExecuted()); | 618 EXPECT_TRUE(completionHandlerExecuted()); |
616 EXPECT_FALSE(completionHandlerArgument()); | 619 EXPECT_FALSE(completionHandlerArgument()); |
617 EXPECT_FALSE(getHandleStartupParametersHasBeenCalled()); | 620 EXPECT_FALSE(getHandleStartupParametersHasBeenCalled()); |
618 } | 621 } |
OLD | NEW |