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

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller_unittest.mm

Issue 2824523002: Remove usage of Tab's |url| property from BrowserViewController. (Closed)
Patch Set: fixed test mock Created 3 years, 6 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
« no previous file with comments | « ios/chrome/browser/ui/browser_view_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate> 75 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate>
76 - (void)pageLoadStarted:(NSNotification*)notification; 76 - (void)pageLoadStarted:(NSNotification*)notification;
77 - (void)pageLoadComplete:(NSNotification*)notification; 77 - (void)pageLoadComplete:(NSNotification*)notification;
78 - (void)tabSelected:(Tab*)tab; 78 - (void)tabSelected:(Tab*)tab;
79 - (void)tabDeselected:(NSNotification*)notification; 79 - (void)tabDeselected:(NSNotification*)notification;
80 - (void)tabCountChanged:(NSNotification*)notification; 80 - (void)tabCountChanged:(NSNotification*)notification;
81 - (IBAction)chromeExecuteCommand:(id)sender; 81 - (IBAction)chromeExecuteCommand:(id)sender;
82 @end 82 @end
83 83
84 @interface BVCTestTabMock : OCMockComplexTypeHelper { 84 @interface BVCTestTabMock : OCMockComplexTypeHelper {
85 GURL url_; 85 GURL _url;
86 WebStateImpl* webState_; 86 GURL _lastCommittedURL;
87 GURL _visibleURL;
88 WebStateImpl* _webState;
87 } 89 }
88 90
89 @property(nonatomic, assign) const GURL& url; 91 @property(nonatomic, assign) const GURL& url;
92 @property(nonatomic, assign) const GURL& lastCommittedURL;
93 @property(nonatomic, assign) const GURL& visibleURL;
90 @property(nonatomic, assign) WebStateImpl* webState; 94 @property(nonatomic, assign) WebStateImpl* webState;
91 95
92 - (web::NavigationManager*)navigationManager; 96 - (web::NavigationManager*)navigationManager;
93 - (web::NavigationManagerImpl*)navigationManagerImpl; 97 - (web::NavigationManagerImpl*)navigationManagerImpl;
94 98
95 @end 99 @end
96 100
97 @implementation BVCTestTabMock 101 @implementation BVCTestTabMock
98 - (const GURL&)url { 102 - (const GURL&)url {
99 return url_; 103 return _url;
100 } 104 }
101 - (void)setUrl:(const GURL&)url { 105 - (void)setUrl:(const GURL&)url {
102 url_ = url; 106 _url = url;
107 }
108 - (const GURL&)lastCommittedURL {
109 return _lastCommittedURL;
110 }
111 - (void)setLastCommittedURL:(const GURL&)lastCommittedURL {
112 _lastCommittedURL = lastCommittedURL;
113 }
114 - (const GURL&)visibleURL {
115 return _visibleURL;
116 }
117 - (void)setVisibleURL:(const GURL&)visibleURL {
118 _visibleURL = visibleURL;
103 } 119 }
104 - (WebStateImpl*)webState { 120 - (WebStateImpl*)webState {
105 return webState_; 121 return _webState;
106 } 122 }
107 - (void)setWebState:(WebStateImpl*)webState { 123 - (void)setWebState:(WebStateImpl*)webState {
108 webState_ = webState; 124 _webState = webState;
109 } 125 }
110 - (web::NavigationManager*)navigationManager { 126 - (web::NavigationManager*)navigationManager {
111 return &(webState_->GetNavigationManagerImpl()); 127 return &(_webState->GetNavigationManagerImpl());
112 } 128 }
113 - (web::NavigationManagerImpl*)navigationManagerImpl { 129 - (web::NavigationManagerImpl*)navigationManagerImpl {
114 return &(webState_->GetNavigationManagerImpl()); 130 return &(_webState->GetNavigationManagerImpl());
115 } 131 }
116 @end 132 @end
117 133
118 @interface BVCTestTabModel : OCMockComplexTypeHelper 134 @interface BVCTestTabModel : OCMockComplexTypeHelper
119 - (instancetype)init NS_DESIGNATED_INITIALIZER; 135 - (instancetype)init NS_DESIGNATED_INITIALIZER;
120 @end 136 @end
121 137
122 @implementation BVCTestTabModel { 138 @implementation BVCTestTabModel {
123 FakeWebStateListDelegate _webStateListDelegate; 139 FakeWebStateListDelegate _webStateListDelegate;
124 std::unique_ptr<WebStateList> _webStateList; 140 std::unique_ptr<WebStateList> _webStateList;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 [bvc_ locationBarBeganEdit:nil]; 431 [bvc_ locationBarBeganEdit:nil];
416 432
417 EXPECT_OCMOCK_VERIFY(tabMock); 433 EXPECT_OCMOCK_VERIFY(tabMock);
418 } 434 }
419 435
420 // Verifies that BVC invokes -shareURL on ShareController with the correct 436 // Verifies that BVC invokes -shareURL on ShareController with the correct
421 // parameters in response to the IDC_SHARE_PAGE command. 437 // parameters in response to the IDC_SHARE_PAGE command.
422 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) { 438 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) {
423 GURL expectedUrl("http://www.testurl.net"); 439 GURL expectedUrl("http://www.testurl.net");
424 NSString* expectedTitle = @"title"; 440 NSString* expectedTitle = @"title";
425 [static_cast<BVCTestTabMock*>(tab_.get()) setUrl:expectedUrl]; 441 static_cast<BVCTestTabMock*>(tab_.get()).url = expectedUrl;
442 static_cast<BVCTestTabMock*>(tab_.get()).lastCommittedURL = expectedUrl;
443 static_cast<BVCTestTabMock*>(tab_.get()).visibleURL = expectedUrl;
426 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 444 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get());
427 ios::ChromeBrowserState* ptr = chrome_browser_state_.get(); 445 ios::ChromeBrowserState* ptr = chrome_browser_state_.get();
428 [[[tabMock stub] andReturnValue:OCMOCK_VALUE(ptr)] browserState]; 446 [[[tabMock stub] andReturnValue:OCMOCK_VALUE(ptr)] browserState];
429 [[[tabMock stub] andReturn:expectedTitle] title]; 447 [[[tabMock stub] andReturn:expectedTitle] title];
430 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; 448 [[[tabMock stub] andReturn:expectedTitle] originalTitle];
431 449
432 UIImage* tabSnapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor( 450 UIImage* tabSnapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor(
433 CGSizeMake(300, 400), [UIColor blueColor]); 451 CGSizeMake(300, 400), [UIColor blueColor]);
434 [[[tabMock stub] andReturn:tabSnapshot] generateSnapshotWithOverlay:NO 452 [[[tabMock stub] andReturn:tabSnapshot] generateSnapshotWithOverlay:NO
435 visibleFrameOnly:YES]; 453 visibleFrameOnly:YES];
(...skipping 27 matching lines...) Expand all
463 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; 481 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)];
464 EXPECT_OCMOCK_VERIFY(shareControllerMock); 482 EXPECT_OCMOCK_VERIFY(shareControllerMock);
465 } 483 }
466 484
467 // Verifies that BVC does not invoke -shareURL on ShareController in response 485 // Verifies that BVC does not invoke -shareURL on ShareController in response
468 // to the IDC_SHARE_PAGE command if tab is in the process of being closed. 486 // to the IDC_SHARE_PAGE command if tab is in the process of being closed.
469 TEST_F(BrowserViewControllerTest, TestSharePageWhenClosing) { 487 TEST_F(BrowserViewControllerTest, TestSharePageWhenClosing) {
470 GURL expectedUrl("http://www.testurl.net"); 488 GURL expectedUrl("http://www.testurl.net");
471 NSString* expectedTitle = @"title"; 489 NSString* expectedTitle = @"title";
472 // Sets WebState to nil because [tab close] clears the WebState. 490 // Sets WebState to nil because [tab close] clears the WebState.
473 [static_cast<BVCTestTabMock*>(tab_.get()) setWebState:nil]; 491 static_cast<BVCTestTabMock*>(tab_.get()).webState = nil;
474 [static_cast<BVCTestTabMock*>(tab_.get()) setUrl:expectedUrl]; 492 static_cast<BVCTestTabMock*>(tab_.get()).url = expectedUrl;
493 static_cast<BVCTestTabMock*>(tab_.get()).lastCommittedURL = expectedUrl;
494 static_cast<BVCTestTabMock*>(tab_.get()).visibleURL = expectedUrl;
475 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 495 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get());
476 [[[tabMock stub] andReturn:expectedTitle] title]; 496 [[[tabMock stub] andReturn:expectedTitle] title];
477 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; 497 [[[tabMock stub] andReturn:expectedTitle] originalTitle];
478 // Explicitly disallow the execution of the ShareController. 498 // Explicitly disallow the execution of the ShareController.
479 OCMockObject* shareControllerMock = 499 OCMockObject* shareControllerMock =
480 static_cast<OCMockObject*>(shareController_.get()); 500 static_cast<OCMockObject*>(shareController_.get());
481 [[shareControllerMock reject] 501 [[shareControllerMock reject]
482 shareWithData:[OCMArg any] 502 shareWithData:[OCMArg any]
483 controller:bvc_ 503 controller:bvc_
484 browserState:chrome_browser_state_.get() 504 browserState:chrome_browser_state_.get()
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 static_cast<OCMockObject*>(shareController_.get()); 585 static_cast<OCMockObject*>(shareController_.get());
566 [[shareControllerMock expect] cancelShareAnimated:NO]; 586 [[shareControllerMock expect] cancelShareAnimated:NO];
567 EXPECT_CALL(*this, OnCompletionCalled()); 587 EXPECT_CALL(*this, OnCompletionCalled());
568 [bvc_ clearPresentedStateWithCompletion:^{ 588 [bvc_ clearPresentedStateWithCompletion:^{
569 this->OnCompletionCalled(); 589 this->OnCompletionCalled();
570 }]; 590 }];
571 EXPECT_OCMOCK_VERIFY(shareControllerMock); 591 EXPECT_OCMOCK_VERIFY(shareControllerMock);
572 } 592 }
573 593
574 } // namespace 594 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/browser_view_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698