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 #import <PassKit/PassKit.h> | 6 #import <PassKit/PassKit.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #import "ios/web/web_state/web_state_impl.h" | 59 #import "ios/web/web_state/web_state_impl.h" |
60 #import "net/base/mac/url_conversions.h" | 60 #import "net/base/mac/url_conversions.h" |
61 #include "net/url_request/url_request_test_util.h" | 61 #include "net/url_request/url_request_test_util.h" |
62 #include "testing/gmock/include/gmock/gmock.h" | 62 #include "testing/gmock/include/gmock/gmock.h" |
63 #include "testing/gtest/include/gtest/gtest.h" | 63 #include "testing/gtest/include/gtest/gtest.h" |
64 #include "testing/gtest_mac.h" | 64 #include "testing/gtest_mac.h" |
65 #import "third_party/ocmock/OCMock/OCMock.h" | 65 #import "third_party/ocmock/OCMock/OCMock.h" |
66 #include "third_party/ocmock/gtest_support.h" | 66 #include "third_party/ocmock/gtest_support.h" |
67 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
68 #include "ui/base/l10n/l10n_util_mac.h" | 68 #include "ui/base/l10n/l10n_util_mac.h" |
| 69 #include "ui/base/test/ios/ui_image_test_utils.h" |
69 | 70 |
70 using web::NavigationManagerImpl; | 71 using web::NavigationManagerImpl; |
71 using web::WebStateImpl; | 72 using web::WebStateImpl; |
72 | 73 |
73 // Private methods in BrowserViewController to test. | 74 // Private methods in BrowserViewController to test. |
74 @interface BrowserViewController ( | 75 @interface BrowserViewController ( |
75 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate> | 76 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate> |
76 - (void)pageLoadStarted:(NSNotification*)notification; | 77 - (void)pageLoadStarted:(NSNotification*)notification; |
77 - (void)pageLoadComplete:(NSNotification*)notification; | 78 - (void)pageLoadComplete:(NSNotification*)notification; |
78 - (void)tabSelected:(Tab*)tab; | 79 - (void)tabSelected:(Tab*)tab; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 EXPECT_OCMOCK_VERIFY(tabMock); | 400 EXPECT_OCMOCK_VERIFY(tabMock); |
400 } | 401 } |
401 | 402 |
402 // Verifies that BVC invokes -shareURL on ShareController with the correct | 403 // Verifies that BVC invokes -shareURL on ShareController with the correct |
403 // parameters in response to the IDC_SHARE_PAGE command. | 404 // parameters in response to the IDC_SHARE_PAGE command. |
404 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) { | 405 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) { |
405 GURL expectedUrl("http://www.testurl.net"); | 406 GURL expectedUrl("http://www.testurl.net"); |
406 NSString* expectedTitle = @"title"; | 407 NSString* expectedTitle = @"title"; |
407 [(BVCTestTabMock*)tab_.get() setUrl:expectedUrl]; | 408 [(BVCTestTabMock*)tab_.get() setUrl:expectedUrl]; |
408 OCMockObject* tabMock = (OCMockObject*)tab_.get(); | 409 OCMockObject* tabMock = (OCMockObject*)tab_.get(); |
| 410 ios::ChromeBrowserState* ptr = chrome_browser_state_.get(); |
| 411 [[[tabMock stub] andReturnValue:OCMOCK_VALUE(ptr)] browserState]; |
409 [[[tabMock stub] andReturn:expectedTitle] title]; | 412 [[[tabMock stub] andReturn:expectedTitle] title]; |
410 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; | 413 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; |
411 base::scoped_nsobject<ShareToData> expectedShareData([[ShareToData alloc] | 414 |
412 initWithURL:expectedUrl | 415 UIImage* tabSnapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor( |
413 title:expectedTitle | 416 CGSizeMake(300, 400), [UIColor blueColor]); |
414 isOriginalTitle:YES | 417 [[[tabMock stub] andReturn:tabSnapshot] generateSnapshotWithOverlay:NO |
415 isPagePrintable:YES]); | 418 visibleFrameOnly:YES]; |
416 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); | 419 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); |
417 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol | 420 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol |
418 // requirements. | 421 // requirements. |
| 422 BOOL (^shareDataChecker) |
| 423 (id value) = ^BOOL(id value) { |
| 424 if (![value isMemberOfClass:ShareToData.class]) |
| 425 return NO; |
| 426 ShareToData* shareToData = (ShareToData*)value; |
| 427 CGSize size = CGSizeMake(40, 40); |
| 428 BOOL thumbnailDataIsEqual = ui::test::uiimage_utils::UIImagesAreEqual( |
| 429 shareToData.thumbnailGenerator(size), |
| 430 ui::test::uiimage_utils::UIImageWithSizeAndSolidColor( |
| 431 size, [UIColor blueColor])); |
| 432 return shareToData.url == expectedUrl && |
| 433 [shareToData.title isEqual:expectedTitle] && |
| 434 shareToData.isOriginalTitle == YES && |
| 435 shareToData.isPagePrintable == NO && thumbnailDataIsEqual; |
| 436 }; |
| 437 |
419 [[shareControllerMock expect] | 438 [[shareControllerMock expect] |
420 shareWithData:expectedShareData | 439 shareWithData:[OCMArg checkWithBlock:shareDataChecker] |
421 controller:bvc_ | 440 controller:bvc_ |
422 browserState:chrome_browser_state_.get() | 441 browserState:chrome_browser_state_.get() |
423 shareToDelegate:bvc_ | 442 shareToDelegate:bvc_ |
424 fromRect:[bvc_ testing_shareButtonAnchorRect] | 443 fromRect:[bvc_ testing_shareButtonAnchorRect] |
425 inView:[OCMArg any]]; | 444 inView:[OCMArg any]]; |
426 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; | 445 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; |
427 EXPECT_OCMOCK_VERIFY(shareControllerMock); | 446 EXPECT_OCMOCK_VERIFY(shareControllerMock); |
428 } | 447 } |
429 | 448 |
430 // Verifies that BVC does not invoke -shareURL on ShareController in response | 449 // Verifies that BVC does not invoke -shareURL on ShareController in response |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); | 544 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); |
526 [[shareControllerMock expect] cancelShareAnimated:NO]; | 545 [[shareControllerMock expect] cancelShareAnimated:NO]; |
527 EXPECT_CALL(*this, OnCompletionCalled()); | 546 EXPECT_CALL(*this, OnCompletionCalled()); |
528 [bvc_ clearPresentedStateWithCompletion:^{ | 547 [bvc_ clearPresentedStateWithCompletion:^{ |
529 this->OnCompletionCalled(); | 548 this->OnCompletionCalled(); |
530 }]; | 549 }]; |
531 EXPECT_OCMOCK_VERIFY(shareControllerMock); | 550 EXPECT_OCMOCK_VERIFY(shareControllerMock); |
532 } | 551 } |
533 | 552 |
534 } // namespace | 553 } // namespace |
OLD | NEW |