Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: ios/chrome/browser/ui/activity_services/activity_service_controller_unittest.mm

Issue 2752643004: Stop showing snackbar with success message when sharing with Chrome iOS. (Closed)
Patch Set: Addressed comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/ui/activity_services/activity_service_controller.h" 5 #import "ios/chrome/browser/ui/activity_services/activity_service_controller.h"
6 6
7 #import <MobileCoreServices/MobileCoreServices.h> 7 #import <MobileCoreServices/MobileCoreServices.h>
8 8
9 #import "base/test/ios/wait_util.h" 9 #import "base/test/ios/wait_util.h"
10 #include "components/reading_list/core/reading_list_switches.h" 10 #include "components/reading_list/core/reading_list_switches.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 blockCalled = true; 157 blockCalled = true;
158 }; 158 };
159 // OCMock does not allow "any" specification for non-object parameters. 159 // OCMock does not allow "any" specification for non-object parameters.
160 // To implement something that accept any non-SHARE_SUCCESS parameter 160 // To implement something that accept any non-SHARE_SUCCESS parameter
161 // to calling this method, all the non-success values have to be 161 // to calling this method, all the non-success values have to be
162 // enumerated. 162 // enumerated.
163 [[[shareToDelegateMock stub] andDo:validationBlock] 163 [[[shareToDelegateMock stub] andDo:validationBlock]
164 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_CANCEL 164 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_CANCEL
165 username:OCMOCK_ANY 165 username:OCMOCK_ANY
166 password:OCMOCK_ANY 166 password:OCMOCK_ANY
167 successMessage:OCMOCK_ANY]; 167 completionMessage:OCMOCK_ANY];
168 [[[shareToDelegateMock stub] andDo:validationBlock] 168 [[[shareToDelegateMock stub] andDo:validationBlock]
169 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_NETWORK_FAILURE 169 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_NETWORK_FAILURE
170 username:OCMOCK_ANY 170 username:OCMOCK_ANY
171 password:OCMOCK_ANY 171 password:OCMOCK_ANY
172 successMessage:OCMOCK_ANY]; 172 completionMessage:OCMOCK_ANY];
173 [[[shareToDelegateMock stub] andDo:validationBlock] 173 [[[shareToDelegateMock stub] andDo:validationBlock]
174 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_SIGN_IN_FAILURE 174 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_SIGN_IN_FAILURE
175 username:OCMOCK_ANY 175 username:OCMOCK_ANY
176 password:OCMOCK_ANY 176 password:OCMOCK_ANY
177 successMessage:OCMOCK_ANY]; 177 completionMessage:OCMOCK_ANY];
178 [[[shareToDelegateMock stub] andDo:validationBlock] 178 [[[shareToDelegateMock stub] andDo:validationBlock]
179 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_ERROR 179 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_ERROR
180 username:OCMOCK_ANY 180 username:OCMOCK_ANY
181 password:OCMOCK_ANY 181 password:OCMOCK_ANY
182 successMessage:OCMOCK_ANY]; 182 completionMessage:OCMOCK_ANY];
183 [[[shareToDelegateMock stub] andDo:validationBlock] 183 [[[shareToDelegateMock stub] andDo:validationBlock]
184 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_UNKNOWN_RESULT 184 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_UNKNOWN_RESULT
185 username:OCMOCK_ANY 185 username:OCMOCK_ANY
186 password:OCMOCK_ANY 186 password:OCMOCK_ANY
187 successMessage:OCMOCK_ANY]; 187 completionMessage:OCMOCK_ANY];
188 [activityController setShareToDelegateForTesting:(id)shareToDelegateMock]; 188 [activityController setShareToDelegateForTesting:(id)shareToDelegateMock];
189 189
190 // Sets up the returned item from a Password Management App Extension. 190 // Sets up the returned item from a Password Management App Extension.
191 NSString* activityType = activity_services::kAppExtensionLastPass; 191 NSString* activityType = activity_services::kAppExtensionLastPass;
192 ShareTo::ShareResult result = ShareTo::ShareResult::SHARE_SUCCESS; 192 ShareTo::ShareResult result = ShareTo::ShareResult::SHARE_SUCCESS;
193 BOOL resetUI = 193 BOOL resetUI =
194 [activityController processItemsReturnedFromActivity:activityType 194 [activityController processItemsReturnedFromActivity:activityType
195 status:result 195 status:result
196 items:extensionItems]; 196 items:extensionItems];
197 ASSERT_EQ(expectedResetUI, resetUI); 197 ASSERT_EQ(expectedResetUI, resetUI);
198 base::test::ios::WaitUntilCondition(^{ 198 base::test::ios::WaitUntilCondition(^{
199 return blockCalled; 199 return blockCalled;
200 }); 200 });
201 EXPECT_OCMOCK_VERIFY(shareToDelegateMock); 201 EXPECT_OCMOCK_VERIFY(shareToDelegateMock);
202 } 202 }
203 203
204 web::TestWebThreadBundle thread_bundle_; 204 web::TestWebThreadBundle thread_bundle_;
205 UIViewController* parentController_; 205 UIViewController* parentController_;
206 OCMockObject* shareToDelegate_; 206 OCMockObject* shareToDelegate_;
207 ShareToData* shareData_; 207 ShareToData* shareData_;
208 }; 208 };
209 209
210 TEST_F(ActivityServiceControllerTest, PresentAndDismissController) { 210 TEST_F(ActivityServiceControllerTest, PresentAndDismissController) {
211 [[shareToDelegate_ expect] shareDidComplete:ShareTo::ShareResult::SHARE_CANCEL 211 [[shareToDelegate_ expect] shareDidComplete:ShareTo::ShareResult::SHARE_CANCEL
212 successMessage:[OCMArg isNil]]; 212 completionMessage:[OCMArg isNil]];
213 213
214 UIViewController* parentController = 214 UIViewController* parentController =
215 static_cast<UIViewController*>(parentController_); 215 static_cast<UIViewController*>(parentController_);
216 ActivityServiceController* activityController = 216 ActivityServiceController* activityController =
217 [[ActivityServiceController alloc] init]; 217 [[ActivityServiceController alloc] init];
218 EXPECT_FALSE([activityController isActive]); 218 EXPECT_FALSE([activityController isActive]);
219 219
220 // Test sharing. 220 // Test sharing.
221 [activityController shareWithData:shareData_ 221 [activityController shareWithData:shareData_
222 controller:parentController 222 controller:parentController
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 EXPECT_NSEQ(@"https://chromium.org/login.html", [item absoluteString]); 344 EXPECT_NSEQ(@"https://chromium.org/login.html", [item absoluteString]);
345 } 345 }
346 346
347 // Verifies that -processItemsReturnedFromActivity:status:item: contains 347 // Verifies that -processItemsReturnedFromActivity:status:item: contains
348 // the username and password. 348 // the username and password.
349 TEST_F(ActivityServiceControllerTest, ProcessItemsReturnedSuccessfully) { 349 TEST_F(ActivityServiceControllerTest, ProcessItemsReturnedSuccessfully) {
350 ActivityServiceController* activityController = 350 ActivityServiceController* activityController =
351 [[ActivityServiceController alloc] init]; 351 [[ActivityServiceController alloc] init];
352 352
353 // Sets up a Mock ShareToDelegate object to check that the callback function 353 // Sets up a Mock ShareToDelegate object to check that the callback function
354 // -passwordAppExDidFinish:username:password:successMessage: 354 // -passwordAppExDidFinish:username:password:completionMessage:
355 // is correct with the correct username and password. 355 // is correct with the correct username and password.
356 OCMockObject* shareToDelegateMock = 356 OCMockObject* shareToDelegateMock =
357 [OCMockObject mockForProtocol:@protocol(ShareToDelegate)]; 357 [OCMockObject mockForProtocol:@protocol(ShareToDelegate)];
358 NSString* const kSecretUsername = @"john.doe"; 358 NSString* const kSecretUsername = @"john.doe";
359 NSString* const kSecretPassword = @"super!secret"; 359 NSString* const kSecretPassword = @"super!secret";
360 __block bool blockCalled = false; 360 __block bool blockCalled = false;
361 void (^validationBlock)(NSInvocation*) = ^(NSInvocation* invocation) { 361 void (^validationBlock)(NSInvocation*) = ^(NSInvocation* invocation) {
362 __unsafe_unretained NSString* username; 362 __unsafe_unretained NSString* username;
363 __unsafe_unretained NSString* password; 363 __unsafe_unretained NSString* password;
364 // Skips 0 and 1 index because they are |self| and |cmd|. 364 // Skips 0 and 1 index because they are |self| and |cmd|.
365 [invocation getArgument:&username atIndex:3]; 365 [invocation getArgument:&username atIndex:3];
366 [invocation getArgument:&password atIndex:4]; 366 [invocation getArgument:&password atIndex:4];
367 EXPECT_NSEQ(kSecretUsername, username); 367 EXPECT_NSEQ(kSecretUsername, username);
368 EXPECT_NSEQ(kSecretPassword, password); 368 EXPECT_NSEQ(kSecretPassword, password);
369 blockCalled = true; 369 blockCalled = true;
370 }; 370 };
371 [[[shareToDelegateMock stub] andDo:validationBlock] 371 [[[shareToDelegateMock stub] andDo:validationBlock]
372 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_SUCCESS 372 passwordAppExDidFinish:ShareTo::ShareResult::SHARE_SUCCESS
373 username:OCMOCK_ANY 373 username:OCMOCK_ANY
374 password:OCMOCK_ANY 374 password:OCMOCK_ANY
375 successMessage:OCMOCK_ANY]; 375 completionMessage:OCMOCK_ANY];
376 [activityController setShareToDelegateForTesting:(id)shareToDelegateMock]; 376 [activityController setShareToDelegateForTesting:(id)shareToDelegateMock];
377 377
378 // Sets up the returned item from a Password Management App Extension. 378 // Sets up the returned item from a Password Management App Extension.
379 NSString* activityType = @"com.software.find-login-action.extension"; 379 NSString* activityType = @"com.software.find-login-action.extension";
380 ShareTo::ShareResult result = ShareTo::ShareResult::SHARE_SUCCESS; 380 ShareTo::ShareResult result = ShareTo::ShareResult::SHARE_SUCCESS;
381 NSDictionary* dictionaryFromAppEx = 381 NSDictionary* dictionaryFromAppEx =
382 @{ @"username" : kSecretUsername, 382 @{ @"username" : kSecretUsername,
383 @"password" : kSecretPassword }; 383 @"password" : kSecretPassword };
384 NSItemProvider* itemProvider = 384 NSItemProvider* itemProvider =
385 [[NSItemProvider alloc] initWithItem:dictionaryFromAppEx 385 [[NSItemProvider alloc] initWithItem:dictionaryFromAppEx
386 typeIdentifier:(NSString*)kUTTypePropertyList]; 386 typeIdentifier:(NSString*)kUTTypePropertyList];
387 NSExtensionItem* extensionItem = [[NSExtensionItem alloc] init]; 387 NSExtensionItem* extensionItem = [[NSExtensionItem alloc] init];
388 [extensionItem setAttachments:@[ itemProvider ]]; 388 [extensionItem setAttachments:@[ itemProvider ]];
389 389
390 BOOL resetUI = 390 BOOL resetUI =
391 [activityController processItemsReturnedFromActivity:activityType 391 [activityController processItemsReturnedFromActivity:activityType
392 status:result 392 status:result
393 items:@[ extensionItem ]]; 393 items:@[ extensionItem ]];
394 ASSERT_FALSE(resetUI); 394 ASSERT_FALSE(resetUI);
395 // Wait for -passwordAppExDidFinish:username:password:successMessage: 395 // Wait for -passwordAppExDidFinish:username:password:completionMessage:
396 // to be called. 396 // to be called.
397 base::test::ios::WaitUntilCondition(^{ 397 base::test::ios::WaitUntilCondition(^{
398 return blockCalled; 398 return blockCalled;
399 }); 399 });
400 EXPECT_OCMOCK_VERIFY(shareToDelegateMock); 400 EXPECT_OCMOCK_VERIFY(shareToDelegateMock);
401 } 401 }
402 402
403 // Verifies that -processItemsReturnedFromActivity:status:item: fails when 403 // Verifies that -processItemsReturnedFromActivity:status:item: fails when
404 // called with invalid NSExtensionItem. 404 // called with invalid NSExtensionItem.
405 TEST_F(ActivityServiceControllerTest, ProcessItemsReturnedFailures) { 405 TEST_F(ActivityServiceControllerTest, ProcessItemsReturnedFailures) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 // public.url UTType in order to allow Share actions (e.g. Facebook, Twitter, 481 // public.url UTType in order to allow Share actions (e.g. Facebook, Twitter,
482 // etc) to appear on UIActivityViewController opened by Chrome). 482 // etc) to appear on UIActivityViewController opened by Chrome).
483 CFStringRef chromeFindLoginAction = reinterpret_cast<CFStringRef>( 483 CFStringRef chromeFindLoginAction = reinterpret_cast<CFStringRef>(
484 activity_services::kUTTypeAppExtensionFindLoginAction); 484 activity_services::kUTTypeAppExtensionFindLoginAction);
485 EXPECT_TRUE(UTTypeConformsTo(chromeFindLoginAction, kUTTypeURL)); 485 EXPECT_TRUE(UTTypeConformsTo(chromeFindLoginAction, kUTTypeURL));
486 EXPECT_TRUE( 486 EXPECT_TRUE(
487 UTTypeConformsTo(chromeFindLoginAction, onePasswordFindLoginAction)); 487 UTTypeConformsTo(chromeFindLoginAction, onePasswordFindLoginAction));
488 } 488 }
489 489
490 } // namespace 490 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698