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

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

Issue 2936833002: [ObjC ARC] Converts ios/chrome/browser/ui:unit_tests to ARC. (Closed)
Patch Set: Fix bad ARC guard. 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
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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/mac/scoped_nsautorelease_pool.h"
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
16 #include "base/path_service.h" 14 #include "base/path_service.h"
17 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
18 #include "components/bookmarks/test/bookmark_test_helpers.h" 16 #include "components/bookmarks/test/bookmark_test_helpers.h"
19 #include "components/prefs/testing_pref_service.h" 17 #include "components/prefs/testing_pref_service.h"
20 #include "components/search_engines/template_url_service.h" 18 #include "components/search_engines/template_url_service.h"
21 #include "components/sessions/core/tab_restore_service.h" 19 #include "components/sessions/core/tab_restore_service.h"
22 #include "components/toolbar/test_toolbar_model.h" 20 #include "components/toolbar/test_toolbar_model.h"
23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 21 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
24 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 22 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "net/url_request/url_request_test_util.h" 58 #include "net/url_request/url_request_test_util.h"
61 #include "testing/gmock/include/gmock/gmock.h" 59 #include "testing/gmock/include/gmock/gmock.h"
62 #include "testing/gtest/include/gtest/gtest.h" 60 #include "testing/gtest/include/gtest/gtest.h"
63 #include "testing/gtest_mac.h" 61 #include "testing/gtest_mac.h"
64 #import "third_party/ocmock/OCMock/OCMock.h" 62 #import "third_party/ocmock/OCMock/OCMock.h"
65 #include "third_party/ocmock/gtest_support.h" 63 #include "third_party/ocmock/gtest_support.h"
66 #include "ui/base/l10n/l10n_util.h" 64 #include "ui/base/l10n/l10n_util.h"
67 #include "ui/base/l10n/l10n_util_mac.h" 65 #include "ui/base/l10n/l10n_util_mac.h"
68 #include "ui/base/test/ios/ui_image_test_utils.h" 66 #include "ui/base/test/ios/ui_image_test_utils.h"
69 67
68 #if !defined(__has_feature) || !__has_feature(objc_arc)
69 #error "This file requires ARC support."
70 #endif
71
70 using web::NavigationManagerImpl; 72 using web::NavigationManagerImpl;
71 using web::WebStateImpl; 73 using web::WebStateImpl;
72 74
73 // Private methods in BrowserViewController to test. 75 // Private methods in BrowserViewController to test.
74 @interface BrowserViewController ( 76 @interface BrowserViewController (
75 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate> 77 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate>
76 - (void)pageLoadStarted:(NSNotification*)notification; 78 - (void)pageLoadStarted:(NSNotification*)notification;
77 - (void)pageLoadComplete:(NSNotification*)notification; 79 - (void)pageLoadComplete:(NSNotification*)notification;
78 - (void)tabSelected:(Tab*)tab; 80 - (void)tabSelected:(Tab*)tab;
79 - (void)tabDeselected:(NSNotification*)notification; 81 - (void)tabDeselected:(NSNotification*)notification;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 ios::TemplateURLServiceFactory::GetInstance(), 174 ios::TemplateURLServiceFactory::GetInstance(),
173 ios::TemplateURLServiceFactory::GetDefaultFactory()); 175 ios::TemplateURLServiceFactory::GetDefaultFactory());
174 chrome_browser_state_ = test_cbs_builder.Build(); 176 chrome_browser_state_ = test_cbs_builder.Build();
175 chrome_browser_state_->CreateBookmarkModel(false); 177 chrome_browser_state_->CreateBookmarkModel(false);
176 bookmarks::BookmarkModel* bookmark_model = 178 bookmarks::BookmarkModel* bookmark_model =
177 ios::BookmarkModelFactory::GetForBrowserState( 179 ios::BookmarkModelFactory::GetForBrowserState(
178 chrome_browser_state_.get()); 180 chrome_browser_state_.get());
179 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); 181 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
180 182
181 // Set up mock TabModel, Tab, and CRWWebController. 183 // Set up mock TabModel, Tab, and CRWWebController.
182 base::scoped_nsobject<id> tabModel([[BVCTestTabModel alloc] init]); 184 id tabModel = [[BVCTestTabModel alloc] init];
183 base::scoped_nsobject<id> currentTab([[BVCTestTabMock alloc] 185 id currentTab = [[BVCTestTabMock alloc]
184 initWithRepresentedObject:[OCMockObject niceMockForClass:[Tab class]]]); 186 initWithRepresentedObject:[OCMockObject niceMockForClass:[Tab class]]];
185 id webControllerMock = 187 id webControllerMock =
186 [OCMockObject niceMockForClass:[CRWWebController class]]; 188 [OCMockObject niceMockForClass:[CRWWebController class]];
187 189
188 // Stub methods for TabModel. 190 // Stub methods for TabModel.
189 NSUInteger tabCount = 1; 191 NSUInteger tabCount = 1;
190 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(tabCount)] count]; 192 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(tabCount)] count];
191 BOOL enabled = YES; 193 BOOL enabled = YES;
192 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(enabled)] webUsageEnabled]; 194 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(enabled)] webUsageEnabled];
193 [[[tabModel stub] andReturn:currentTab] currentTab]; 195 [[[tabModel stub] andReturn:currentTab] currentTab];
194 [[[tabModel stub] andReturn:currentTab] tabAtIndex:0]; 196 [[[tabModel stub] andReturn:currentTab] tabAtIndex:0];
195 [[tabModel stub] addObserver:[OCMArg any]]; 197 [[tabModel stub] addObserver:[OCMArg any]];
196 [[tabModel stub] removeObserver:[OCMArg any]]; 198 [[tabModel stub] removeObserver:[OCMArg any]];
197 [[tabModel stub] saveSessionImmediately:NO]; 199 [[tabModel stub] saveSessionImmediately:NO];
198 [[tabModel stub] setCurrentTab:[OCMArg any]]; 200 [[tabModel stub] setCurrentTab:[OCMArg any]];
199 [[tabModel stub] closeAllTabs]; 201 [[tabModel stub] closeAllTabs];
200 202
201 // Stub methods for Tab. 203 // Stub methods for Tab.
202 UIView* dummyView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 204 UIView* dummyView = [[UIView alloc] initWithFrame:CGRectZero];
203 [[[currentTab stub] andReturn:dummyView] view]; 205 [[[currentTab stub] andReturn:dummyView] view];
204 [[[currentTab stub] andReturn:webControllerMock] webController]; 206 [[[currentTab stub] andReturn:webControllerMock] webController];
205 207
206 web::WebState::CreateParams params(chrome_browser_state_.get()); 208 web::WebState::CreateParams params(chrome_browser_state_.get());
207 std::unique_ptr<web::WebState> webState = web::WebState::Create(params); 209 std::unique_ptr<web::WebState> webState = web::WebState::Create(params);
208 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release())); 210 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release()));
209 [currentTab setWebState:webStateImpl_.get()]; 211 [currentTab setWebState:webStateImpl_.get()];
210 webStateImpl_->SetWebController(webControllerMock); 212 webStateImpl_->SetWebController(webControllerMock);
211 213
212 // Set up mock ShareController. 214 // Set up mock ShareController.
213 id shareController = 215 id shareController =
214 [OCMockObject niceMockForProtocol:@protocol(ShareProtocol)]; 216 [OCMockObject niceMockForProtocol:@protocol(ShareProtocol)];
215 shareController_.reset([shareController retain]); 217 shareController_ = shareController;
216 218
217 id passKitController = 219 id passKitController =
218 [OCMockObject niceMockForClass:[PKAddPassesViewController class]]; 220 [OCMockObject niceMockForClass:[PKAddPassesViewController class]];
219 passKitViewController_.reset([passKitController retain]); 221 passKitViewController_ = passKitController;
220 222
221 // Set up a fake toolbar model for the dependency factory to return. 223 // Set up a fake toolbar model for the dependency factory to return.
222 // It will be owned (and destroyed) by the BVC. 224 // It will be owned (and destroyed) by the BVC.
223 toolbarModelIOS_ = new TestToolbarModelIOS(); 225 toolbarModelIOS_ = new TestToolbarModelIOS();
224 226
225 // Set up a stub dependency factory. 227 // Set up a stub dependency factory.
226 id factory = [OCMockObject 228 id factory = [OCMockObject
227 mockForClass:[BrowserViewControllerDependencyFactory class]]; 229 mockForClass:[BrowserViewControllerDependencyFactory class]];
228 [[[factory stub] andReturn:nil] 230 [[[factory stub] andReturn:nil]
229 newTabStripControllerWithTabModel:[OCMArg any]]; 231 newTabStripControllerWithTabModel:[OCMArg any]];
230 [[[factory stub] andReturn:nil] newPreloadController]; 232 [[[factory stub] andReturn:nil] newPreloadController];
231 [[[factory stub] andReturnValue:OCMOCK_VALUE(toolbarModelIOS_)] 233 [[[factory stub] andReturnValue:OCMOCK_VALUE(toolbarModelIOS_)]
232 newToolbarModelIOSWithDelegate:static_cast<ToolbarModelDelegateIOS*>( 234 newToolbarModelIOSWithDelegate:static_cast<ToolbarModelDelegateIOS*>(
233 [OCMArg anyPointer])]; 235 [OCMArg anyPointer])];
234 [[[factory stub] andReturn:nil] 236 [[[factory stub] andReturn:nil]
235 newWebToolbarControllerWithDelegate:[OCMArg any] 237 newWebToolbarControllerWithDelegate:[OCMArg any]
236 urlLoader:[OCMArg any] 238 urlLoader:[OCMArg any]
237 preloadProvider:[OCMArg any]]; 239 preloadProvider:[OCMArg any]];
238 [[[factory stub] andReturn:shareController_.get()] shareControllerInstance]; 240 [[[factory stub] andReturn:shareController_] shareControllerInstance];
239 [[[factory stub] andReturn:passKitViewController_.get()] 241 [[[factory stub] andReturn:passKitViewController_]
240 newPassKitViewControllerForPass:nil]; 242 newPassKitViewControllerForPass:nil];
241 [[[factory stub] andReturn:nil] showPassKitErrorInfoBarForManager:nil]; 243 [[[factory stub] andReturn:nil] showPassKitErrorInfoBarForManager:nil];
242 244
243 webController_.reset([webControllerMock retain]); 245 webController_ = webControllerMock;
244 tabModel_.reset([tabModel retain]); 246 tabModel_ = tabModel;
245 tab_.reset([currentTab retain]); 247 tab_ = currentTab;
246 dependencyFactory_.reset([factory retain]); 248 dependencyFactory_ = factory;
247 bvc_.reset([[BrowserViewController alloc] 249 bvc_ = [[BrowserViewController alloc]
248 initWithTabModel:tabModel_ 250 initWithTabModel:tabModel_
249 browserState:chrome_browser_state_.get() 251 browserState:chrome_browser_state_.get()
250 dependencyFactory:factory]); 252 dependencyFactory:factory];
251 253
252 // Load TemplateURLService. 254 // Load TemplateURLService.
253 TemplateURLService* template_url_service = 255 TemplateURLService* template_url_service =
254 ios::TemplateURLServiceFactory::GetForBrowserState( 256 ios::TemplateURLServiceFactory::GetForBrowserState(
255 chrome_browser_state_.get()); 257 chrome_browser_state_.get());
256 template_url_service->Load(); 258 template_url_service->Load();
257 259
258 // Force the view to load. 260 // Force the view to load.
259 UIWindow* window = [[UIWindow alloc] initWithFrame:CGRectZero]; 261 UIWindow* window = [[UIWindow alloc] initWithFrame:CGRectZero];
260 [window addSubview:[bvc_ view]]; 262 [window addSubview:[bvc_ view]];
261 window_.reset(window); 263 window_ = window;
262 } 264 }
263 265
264 void TearDown() override { 266 void TearDown() override {
265 [[bvc_ view] removeFromSuperview]; 267 [[bvc_ view] removeFromSuperview];
266 BlockCleanupTest::TearDown(); 268 BlockCleanupTest::TearDown();
267 } 269 }
268 270
269 base::scoped_nsobject<GenericChromeCommand> GetCommandWithTag(NSInteger tag) { 271 GenericChromeCommand* GetCommandWithTag(NSInteger tag) {
270 base::scoped_nsobject<GenericChromeCommand> command( 272 return [[GenericChromeCommand alloc] initWithTag:tag];
271 [[GenericChromeCommand alloc] initWithTag:tag]);
272 return command;
273 } 273 }
274 274
275 MOCK_METHOD0(OnCompletionCalled, void()); 275 MOCK_METHOD0(OnCompletionCalled, void());
276 276
277 web::TestWebThreadBundle thread_bundle_; 277 web::TestWebThreadBundle thread_bundle_;
278 IOSChromeScopedTestingLocalState local_state_; 278 IOSChromeScopedTestingLocalState local_state_;
279 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 279 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
280 std::unique_ptr<WebStateImpl> webStateImpl_; 280 std::unique_ptr<WebStateImpl> webStateImpl_;
281 base::scoped_nsobject<CRWWebController> webController_; 281 CRWWebController* webController_;
282 base::scoped_nsobject<Tab> tab_; 282 Tab* tab_;
283 base::scoped_nsobject<TabModel> tabModel_; 283 TabModel* tabModel_;
284 ToolbarModelIOS* toolbarModelIOS_; 284 ToolbarModelIOS* toolbarModelIOS_;
285 base::scoped_nsprotocol<id<ShareProtocol>> shareController_; 285 id<ShareProtocol> shareController_;
286 base::scoped_nsobject<PKAddPassesViewController> passKitViewController_; 286 PKAddPassesViewController* passKitViewController_;
287 base::scoped_nsobject<OCMockObject> dependencyFactory_; 287 OCMockObject* dependencyFactory_;
288 base::scoped_nsobject<BrowserViewController> bvc_; 288 BrowserViewController* bvc_;
289 base::scoped_nsobject<UIWindow> window_; 289 UIWindow* window_;
290 }; 290 };
291 291
292 // TODO(crbug.com/228714): These tests pretty much only tested that BVC passed 292 // TODO(crbug.com/228714): These tests pretty much only tested that BVC passed
293 // notifications on to the toolbar, and that the toolbar worked correctly. The 293 // notifications on to the toolbar, and that the toolbar worked correctly. The
294 // former should be an integration test, and the latter should be a toolbar 294 // former should be an integration test, and the latter should be a toolbar
295 // test. Leaving DISABLED_ for now to remind us to move them to toolbar tests. 295 // test. Leaving DISABLED_ for now to remind us to move them to toolbar tests.
296 TEST_F(BrowserViewControllerTest, DISABLED_TestPageLoadStarted) { 296 TEST_F(BrowserViewControllerTest, DISABLED_TestPageLoadStarted) {
297 NSDictionary* userInfoWithThisTab = 297 NSDictionary* userInfoWithThisTab =
298 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey]; 298 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey];
299 NSNotification* notification = [NSNotification 299 NSNotification* notification = [NSNotification
300 notificationWithName:kTabModelTabWillStartLoadingNotification 300 notificationWithName:kTabModelTabWillStartLoadingNotification
301 object:nil 301 object:nil
302 userInfo:userInfoWithThisTab]; 302 userInfo:userInfoWithThisTab];
303 [bvc_ pageLoadStarted:notification]; 303 [bvc_ pageLoadStarted:notification];
304 EXPECT_TRUE([bvc_ testing_isLoading]); 304 EXPECT_TRUE([bvc_ testing_isLoading]);
305 } 305 }
306 306
307 TEST_F(BrowserViewControllerTest, DISABLED_TestPageLoadComplete) { 307 TEST_F(BrowserViewControllerTest, DISABLED_TestPageLoadComplete) {
308 NSDictionary* userInfoWithThisTab = 308 NSDictionary* userInfoWithThisTab =
309 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey]; 309 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey];
310 NSNotification* notification = [NSNotification 310 NSNotification* notification = [NSNotification
311 notificationWithName:kTabModelTabDidFinishLoadingNotification 311 notificationWithName:kTabModelTabDidFinishLoadingNotification
312 object:nil 312 object:nil
313 userInfo:userInfoWithThisTab]; 313 userInfo:userInfoWithThisTab];
314 [bvc_ pageLoadComplete:notification]; 314 [bvc_ pageLoadComplete:notification];
315 EXPECT_FALSE([bvc_ testing_isLoading]); 315 EXPECT_FALSE([bvc_ testing_isLoading]);
316 } 316 }
317 317
318 TEST_F(BrowserViewControllerTest, TestTabSelected) { 318 TEST_F(BrowserViewControllerTest, TestTabSelected) {
319 id tabMock = (id)tab_.get(); 319 id tabMock = (id)tab_;
320 [[tabMock expect] wasShown]; 320 [[tabMock expect] wasShown];
321 [bvc_ tabSelected:tab_]; 321 [bvc_ tabSelected:tab_];
322 EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea])); 322 EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea]));
323 EXPECT_OCMOCK_VERIFY(tabMock); 323 EXPECT_OCMOCK_VERIFY(tabMock);
324 } 324 }
325 325
326 TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) { 326 TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) {
327 base::scoped_nsobject<id> block([^{ 327 id block = [^{
328 return GURL(kChromeUINewTabURL); 328 return GURL(kChromeUINewTabURL);
329 } copy]); 329 } copy];
330 id tabMock = (id)tab_.get(); 330 id tabMock = (id)tab_;
331 [tabMock onSelector:@selector(url) callBlockExpectation:block]; 331 [tabMock onSelector:@selector(url) callBlockExpectation:block];
332 [[tabMock expect] wasShown]; 332 [[tabMock expect] wasShown];
333 [bvc_ tabSelected:tab_]; 333 [bvc_ tabSelected:tab_];
334 EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea])); 334 EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea]));
335 EXPECT_OCMOCK_VERIFY(tabMock); 335 EXPECT_OCMOCK_VERIFY(tabMock);
336 } 336 }
337 337
338 TEST_F(BrowserViewControllerTest, TestTabDeselected) { 338 TEST_F(BrowserViewControllerTest, TestTabDeselected) {
339 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 339 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_);
340 [[tabMock expect] wasHidden]; 340 [[tabMock expect] wasHidden];
341 NSDictionary* userInfoWithThisTab = 341 NSDictionary* userInfoWithThisTab =
342 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey]; 342 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey];
343 NSNotification* notification = 343 NSNotification* notification =
344 [NSNotification notificationWithName:kTabModelTabDeselectedNotification 344 [NSNotification notificationWithName:kTabModelTabDeselectedNotification
345 object:nil 345 object:nil
346 userInfo:userInfoWithThisTab]; 346 userInfo:userInfoWithThisTab];
347 [bvc_ tabDeselected:notification]; 347 [bvc_ tabDeselected:notification];
348 EXPECT_OCMOCK_VERIFY(tabMock); 348 EXPECT_OCMOCK_VERIFY(tabMock);
349 } 349 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 EXPECT_FALSE([[bvc_ typingShield] isHidden]); 389 EXPECT_FALSE([[bvc_ typingShield] isHidden]);
390 [bvc_ shieldWasTapped:nil]; 390 [bvc_ shieldWasTapped:nil];
391 EXPECT_TRUE([[bvc_ typingShield] superview] == nil); 391 EXPECT_TRUE([[bvc_ typingShield] superview] == nil);
392 EXPECT_TRUE([[bvc_ typingShield] isHidden]); 392 EXPECT_TRUE([[bvc_ typingShield] isHidden]);
393 } 393 }
394 394
395 // Verifies that editing the omnimbox while the page is loading will stop the 395 // Verifies that editing the omnimbox while the page is loading will stop the
396 // load on a handset, but not stop the load on a tablet. 396 // load on a handset, but not stop the load on a tablet.
397 TEST_F(BrowserViewControllerTest, 397 TEST_F(BrowserViewControllerTest,
398 TestLocationBarBeganEdit_whenPageLoadIsInProgress) { 398 TestLocationBarBeganEdit_whenPageLoadIsInProgress) {
399 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 399 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_);
400 400
401 // Have the TestToolbarModel indicate that a page load is in progress. 401 // Have the TestToolbarModel indicate that a page load is in progress.
402 static_cast<TestToolbarModelIOS*>(toolbarModelIOS_)->set_is_loading(true); 402 static_cast<TestToolbarModelIOS*>(toolbarModelIOS_)->set_is_loading(true);
403 403
404 // The tab should only stop loading on handsets. 404 // The tab should only stop loading on handsets.
405 if (!IsIPadIdiom()) 405 if (!IsIPadIdiom())
406 [[static_cast<OCMockObject*>(webController_.get()) expect] stopLoading]; 406 [[static_cast<OCMockObject*>(webController_) expect] stopLoading];
407 [bvc_ locationBarBeganEdit:nil]; 407 [bvc_ locationBarBeganEdit:nil];
408 408
409 EXPECT_OCMOCK_VERIFY(static_cast<OCMockObject*>(webController_.get())); 409 EXPECT_OCMOCK_VERIFY(static_cast<OCMockObject*>(webController_));
410 EXPECT_OCMOCK_VERIFY(tabMock); 410 EXPECT_OCMOCK_VERIFY(tabMock);
411 } 411 }
412 412
413 // Verifies that editing the omnibox when the page is not loading will not try 413 // Verifies that editing the omnibox when the page is not loading will not try
414 // to stop the load on a handset or a tablet. 414 // to stop the load on a handset or a tablet.
415 TEST_F(BrowserViewControllerTest, 415 TEST_F(BrowserViewControllerTest,
416 TestLocationBarBeganEdit_whenPageLoadIsComplete) { 416 TestLocationBarBeganEdit_whenPageLoadIsComplete) {
417 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 417 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_);
418 418
419 // Have the TestToolbarModel indicate that the page load is complete. 419 // Have the TestToolbarModel indicate that the page load is complete.
420 static_cast<TestToolbarModelIOS*>(toolbarModelIOS_)->set_is_loading(false); 420 static_cast<TestToolbarModelIOS*>(toolbarModelIOS_)->set_is_loading(false);
421 421
422 // Don't set any expectation for stopLoading to be called on the mock tab. 422 // Don't set any expectation for stopLoading to be called on the mock tab.
423 [bvc_ locationBarBeganEdit:nil]; 423 [bvc_ locationBarBeganEdit:nil];
424 424
425 EXPECT_OCMOCK_VERIFY(tabMock); 425 EXPECT_OCMOCK_VERIFY(tabMock);
426 } 426 }
427 427
428 // Verifies that BVC invokes -shareURL on ShareController with the correct 428 // Verifies that BVC invokes -shareURL on ShareController with the correct
429 // parameters in response to the IDC_SHARE_PAGE command. 429 // parameters in response to the IDC_SHARE_PAGE command.
430 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) { 430 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) {
431 GURL expectedUrl("http://www.testurl.net"); 431 GURL expectedUrl("http://www.testurl.net");
432 NSString* expectedTitle = @"title"; 432 NSString* expectedTitle = @"title";
433 static_cast<BVCTestTabMock*>(tab_.get()).lastCommittedURL = expectedUrl; 433 static_cast<BVCTestTabMock*>(tab_).lastCommittedURL = expectedUrl;
434 static_cast<BVCTestTabMock*>(tab_.get()).visibleURL = expectedUrl; 434 static_cast<BVCTestTabMock*>(tab_).visibleURL = expectedUrl;
435 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 435 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_);
436 ios::ChromeBrowserState* ptr = chrome_browser_state_.get(); 436 ios::ChromeBrowserState* ptr = chrome_browser_state_.get();
437 [[[tabMock stub] andReturnValue:OCMOCK_VALUE(ptr)] browserState]; 437 [[[tabMock stub] andReturnValue:OCMOCK_VALUE(ptr)] browserState];
438 [[[tabMock stub] andReturn:expectedTitle] title]; 438 [[[tabMock stub] andReturn:expectedTitle] title];
439 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; 439 [[[tabMock stub] andReturn:expectedTitle] originalTitle];
440 440
441 UIImage* tabSnapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor( 441 UIImage* tabSnapshot = ui::test::uiimage_utils::UIImageWithSizeAndSolidColor(
442 CGSizeMake(300, 400), [UIColor blueColor]); 442 CGSizeMake(300, 400), [UIColor blueColor]);
443 [[[tabMock stub] andReturn:tabSnapshot] generateSnapshotWithOverlay:NO 443 [[[tabMock stub] andReturn:tabSnapshot] generateSnapshotWithOverlay:NO
444 visibleFrameOnly:YES]; 444 visibleFrameOnly:YES];
445 OCMockObject* shareControllerMock = 445 OCMockObject* shareControllerMock =
446 static_cast<OCMockObject*>(shareController_.get()); 446 static_cast<OCMockObject*>(shareController_);
447 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol 447 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol
448 // requirements. 448 // requirements.
449 BOOL (^shareDataChecker) 449 BOOL (^shareDataChecker)
450 (id value) = ^BOOL(id value) { 450 (id value) = ^BOOL(id value) {
451 if (![value isMemberOfClass:ShareToData.class]) 451 if (![value isMemberOfClass:ShareToData.class])
452 return NO; 452 return NO;
453 ShareToData* shareToData = static_cast<ShareToData*>(value); 453 ShareToData* shareToData = static_cast<ShareToData*>(value);
454 CGSize size = CGSizeMake(40, 40); 454 CGSize size = CGSizeMake(40, 40);
455 BOOL thumbnailDataIsEqual = ui::test::uiimage_utils::UIImagesAreEqual( 455 BOOL thumbnailDataIsEqual = ui::test::uiimage_utils::UIImagesAreEqual(
456 shareToData.thumbnailGenerator(size), 456 shareToData.thumbnailGenerator(size),
(...skipping 15 matching lines...) Expand all
472 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; 472 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)];
473 EXPECT_OCMOCK_VERIFY(shareControllerMock); 473 EXPECT_OCMOCK_VERIFY(shareControllerMock);
474 } 474 }
475 475
476 // Verifies that BVC does not invoke -shareURL on ShareController in response 476 // Verifies that BVC does not invoke -shareURL on ShareController in response
477 // to the IDC_SHARE_PAGE command if tab is in the process of being closed. 477 // to the IDC_SHARE_PAGE command if tab is in the process of being closed.
478 TEST_F(BrowserViewControllerTest, TestSharePageWhenClosing) { 478 TEST_F(BrowserViewControllerTest, TestSharePageWhenClosing) {
479 GURL expectedUrl("http://www.testurl.net"); 479 GURL expectedUrl("http://www.testurl.net");
480 NSString* expectedTitle = @"title"; 480 NSString* expectedTitle = @"title";
481 // Sets WebState to nil because [tab close] clears the WebState. 481 // Sets WebState to nil because [tab close] clears the WebState.
482 static_cast<BVCTestTabMock*>(tab_.get()).webState = nil; 482 static_cast<BVCTestTabMock*>(tab_).webState = nil;
483 static_cast<BVCTestTabMock*>(tab_.get()).lastCommittedURL = expectedUrl; 483 static_cast<BVCTestTabMock*>(tab_).lastCommittedURL = expectedUrl;
484 static_cast<BVCTestTabMock*>(tab_.get()).visibleURL = expectedUrl; 484 static_cast<BVCTestTabMock*>(tab_).visibleURL = expectedUrl;
485 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_.get()); 485 OCMockObject* tabMock = static_cast<OCMockObject*>(tab_);
486 [[[tabMock stub] andReturn:expectedTitle] title]; 486 [[[tabMock stub] andReturn:expectedTitle] title];
487 [[[tabMock stub] andReturn:expectedTitle] originalTitle]; 487 [[[tabMock stub] andReturn:expectedTitle] originalTitle];
488 // Explicitly disallow the execution of the ShareController. 488 // Explicitly disallow the execution of the ShareController.
489 OCMockObject* shareControllerMock = 489 OCMockObject* shareControllerMock =
490 static_cast<OCMockObject*>(shareController_.get()); 490 static_cast<OCMockObject*>(shareController_);
491 [[shareControllerMock reject] 491 [[shareControllerMock reject]
492 shareWithData:[OCMArg any] 492 shareWithData:[OCMArg any]
493 controller:bvc_ 493 controller:bvc_
494 browserState:chrome_browser_state_.get() 494 browserState:chrome_browser_state_.get()
495 shareToDelegate:bvc_ 495 shareToDelegate:bvc_
496 fromRect:[bvc_ testing_shareButtonAnchorRect] 496 fromRect:[bvc_ testing_shareButtonAnchorRect]
497 inView:[OCMArg any]]; 497 inView:[OCMArg any]];
498 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)]; 498 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)];
499 EXPECT_OCMOCK_VERIFY(shareControllerMock); 499 EXPECT_OCMOCK_VERIFY(shareControllerMock);
500 } 500 }
501 501
502 // Verifies that BVC instantiates a bubble to show the given success message on 502 // Verifies that BVC instantiates a bubble to show the given success message on
503 // receiving a -shareDidComplete callback for a successful share. 503 // receiving a -shareDidComplete callback for a successful share.
504 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithSuccess) { 504 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithSuccess) {
505 NSString* completionMessage = @"Completion!"; 505 NSString* completionMessage = @"Completion!";
506 [[dependencyFactory_ expect] showSnackbarWithMessage:completionMessage]; 506 [[dependencyFactory_ expect] showSnackbarWithMessage:completionMessage];
507 507
508 [bvc_ shareDidComplete:ShareTo::SHARE_SUCCESS 508 [bvc_ shareDidComplete:ShareTo::SHARE_SUCCESS
509 completionMessage:completionMessage]; 509 completionMessage:completionMessage];
510 EXPECT_OCMOCK_VERIFY(dependencyFactory_); 510 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
511 } 511 }
512 512
513 // Verifies that BVC shows an alert with the proper error message on 513 // Verifies that BVC shows an alert with the proper error message on
514 // receiving a -shareDidComplete callback for a failed share. 514 // receiving a -shareDidComplete callback for a failed share.
515 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithError) { 515 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithError) {
516 [[dependencyFactory_ reject] showSnackbarWithMessage:OCMOCK_ANY]; 516 [[dependencyFactory_ reject] showSnackbarWithMessage:OCMOCK_ANY];
517 base::scoped_nsobject<OCMockObject> mockCoordinator( 517 OCMockObject* mockCoordinator =
518 [[OCMockObject niceMockForClass:[AlertCoordinator class]] retain]); 518 [OCMockObject niceMockForClass:[AlertCoordinator class]];
519 AlertCoordinator* alertCoordinator = 519 AlertCoordinator* alertCoordinator =
520 static_cast<AlertCoordinator*>(mockCoordinator.get()); 520 static_cast<AlertCoordinator*>(mockCoordinator);
521 NSString* errorTitle = 521 NSString* errorTitle =
522 l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT_TITLE); 522 l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT_TITLE);
523 NSString* errorMessage = l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT); 523 NSString* errorMessage = l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT);
524 [[[dependencyFactory_ expect] andReturn:alertCoordinator] 524 [[[dependencyFactory_ expect] andReturn:alertCoordinator]
525 alertCoordinatorWithTitle:errorTitle 525 alertCoordinatorWithTitle:errorTitle
526 message:errorMessage 526 message:errorMessage
527 viewController:OCMOCK_ANY]; 527 viewController:OCMOCK_ANY];
528 [static_cast<AlertCoordinator*>([mockCoordinator expect]) start]; 528 [static_cast<AlertCoordinator*>([mockCoordinator expect]) start];
529 529
530 [bvc_ shareDidComplete:ShareTo::SHARE_ERROR completionMessage:@"dummy"]; 530 [bvc_ shareDidComplete:ShareTo::SHARE_ERROR completionMessage:@"dummy"];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 NSData* badPassKitObject = [NSData 565 NSData* badPassKitObject = [NSData
566 dataWithContentsOfFile:base::SysUTF8ToNSString(bad_pass_path.value())]; 566 dataWithContentsOfFile:base::SysUTF8ToNSString(bad_pass_path.value())];
567 EXPECT_TRUE(badPassKitObject); 567 EXPECT_TRUE(badPassKitObject);
568 [[dependencyFactory_ reject] newPassKitViewControllerForPass:OCMOCK_ANY]; 568 [[dependencyFactory_ reject] newPassKitViewControllerForPass:OCMOCK_ANY];
569 [bvc_ presentPassKitDialog:badPassKitObject]; 569 [bvc_ presentPassKitDialog:badPassKitObject];
570 EXPECT_OCMOCK_VERIFY(dependencyFactory_); 570 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
571 } 571 }
572 572
573 TEST_F(BrowserViewControllerTest, TestClearPresentedState) { 573 TEST_F(BrowserViewControllerTest, TestClearPresentedState) {
574 OCMockObject* shareControllerMock = 574 OCMockObject* shareControllerMock =
575 static_cast<OCMockObject*>(shareController_.get()); 575 static_cast<OCMockObject*>(shareController_);
576 [[shareControllerMock expect] cancelShareAnimated:NO]; 576 [[shareControllerMock expect] cancelShareAnimated:NO];
577 EXPECT_CALL(*this, OnCompletionCalled()); 577 EXPECT_CALL(*this, OnCompletionCalled());
578 [bvc_ clearPresentedStateWithCompletion:^{ 578 [bvc_ clearPresentedStateWithCompletion:^{
579 this->OnCompletionCalled(); 579 this->OnCompletionCalled();
580 }]; 580 }];
581 EXPECT_OCMOCK_VERIFY(shareControllerMock); 581 EXPECT_OCMOCK_VERIFY(shareControllerMock);
582 } 582 }
583 583
584 } // namespace 584 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/browser_container_view_unittest.mm ('k') | ios/chrome/browser/ui/chrome_web_view_factory_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698