| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 EXPECT_OCMOCK_VERIFY(tabMock); | 402 EXPECT_OCMOCK_VERIFY(tabMock); |
| 402 } | 403 } |
| 403 | 404 |
| 404 // Verifies that BVC invokes -shareURL on ShareController with the correct | 405 // Verifies that BVC invokes -shareURL on ShareController with the correct |
| 405 // parameters in response to the IDC_SHARE_PAGE command. | 406 // parameters in response to the IDC_SHARE_PAGE command. |
| 406 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) { | 407 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) { |
| 407 GURL expectedUrl("http://www.testurl.net"); | 408 GURL expectedUrl("http://www.testurl.net"); |
| 408 NSString* expectedTitle = @"title"; | 409 NSString* expectedTitle = @"title"; |
| 409 [(BVCTestTabMock*)tab_.get() setUrl:expectedUrl]; | 410 [(BVCTestTabMock*)tab_.get() setUrl:expectedUrl]; |
| 410 OCMockObject* tabMock = (OCMockObject*)tab_.get(); | 411 OCMockObject* tabMock = (OCMockObject*)tab_.get(); |
| 412 ios::ChromeBrowserState* ptr = chrome_browser_state_.get(); |
| 413 [[[tabMock stub] andReturnValue:OCMOCK_VALUE(ptr)] browserState]; |
| 411 [[[tabMock stub] andReturn:expectedTitle] title]; | 414 [[[tabMock stub] andReturn:expectedTitle] title]; |
| 412 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; | 415 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; |
| 413 base::scoped_nsobject<ShareToData> expectedShareData([[ShareToData alloc] | 416 |
| 414 initWithURL:expectedUrl | 417 UIImage* tabSnapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor( |
| 415 title:expectedTitle | 418 CGSizeMake(300, 400), [UIColor blueColor]); |
| 416 isOriginalTitle:YES | 419 [[[tabMock stub] andReturn:tabSnapshot] generateSnapshotWithOverlay:NO |
| 417 isPagePrintable:YES]); | 420 visibleFrameOnly:YES]; |
| 418 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); | 421 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); |
| 419 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol | 422 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol |
| 420 // requirements. | 423 // requirements. |
| 424 BOOL (^shareDataChecker) |
| 425 (id value) = ^BOOL(id value) { |
| 426 if (![value isMemberOfClass:ShareToData.class]) |
| 427 return NO; |
| 428 ShareToData* shareToData = (ShareToData*)value; |
| 429 CGSize size = CGSizeMake(40, 40); |
| 430 BOOL thumbnailDataIsEqual = ui::test::uiimage_utils::UIImagesAreEqual( |
| 431 shareToData.thumbnailGenerator(size), |
| 432 ui::test::uiimage_utils::UIImageWithSizeAndSolidColor( |
| 433 size, [UIColor blueColor])); |
| 434 return shareToData.url == expectedUrl && |
| 435 [shareToData.title isEqual:expectedTitle] && |
| 436 shareToData.isOriginalTitle == YES && |
| 437 shareToData.isPagePrintable == NO && thumbnailDataIsEqual; |
| 438 }; |
| 439 |
| 421 [[shareControllerMock expect] | 440 [[shareControllerMock expect] |
| 422 shareWithData:expectedShareData | 441 shareWithData:[OCMArg checkWithBlock:shareDataChecker] |
| 423 controller:bvc_ | 442 controller:bvc_ |
| 424 browserState:chrome_browser_state_.get() | 443 browserState:chrome_browser_state_.get() |
| 425 shareToDelegate:bvc_ | 444 shareToDelegate:bvc_ |
| 426 fromRect:[bvc_ testing_shareButtonAnchorRect] | 445 fromRect:[bvc_ testing_shareButtonAnchorRect] |
| 427 inView:[OCMArg any]]; | 446 inView:[OCMArg any]]; |
| 428 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; | 447 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; |
| 429 EXPECT_OCMOCK_VERIFY(shareControllerMock); | 448 EXPECT_OCMOCK_VERIFY(shareControllerMock); |
| 430 } | 449 } |
| 431 | 450 |
| 432 // Verifies that BVC does not invoke -shareURL on ShareController in response | 451 // Verifies that BVC does not invoke -shareURL on ShareController in response |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); | 546 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); |
| 528 [[shareControllerMock expect] cancelShareAnimated:NO]; | 547 [[shareControllerMock expect] cancelShareAnimated:NO]; |
| 529 EXPECT_CALL(*this, OnCompletionCalled()); | 548 EXPECT_CALL(*this, OnCompletionCalled()); |
| 530 [bvc_ clearPresentedStateWithCompletion:^{ | 549 [bvc_ clearPresentedStateWithCompletion:^{ |
| 531 this->OnCompletionCalled(); | 550 this->OnCompletionCalled(); |
| 532 }]; | 551 }]; |
| 533 EXPECT_OCMOCK_VERIFY(shareControllerMock); | 552 EXPECT_OCMOCK_VERIFY(shareControllerMock); |
| 534 } | 553 } |
| 535 | 554 |
| 536 } // namespace | 555 } // namespace |
| OLD | NEW |