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

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

Issue 2588713002: Upstream Chrome on iOS source code [4/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <Foundation/Foundation.h>
6 #import <PassKit/PassKit.h>
7
8 #include <memory>
9
10 #include "base/command_line.h"
11 #include "base/files/file_path.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"
16 #include "base/path_service.h"
17 #include "base/strings/sys_string_conversions.h"
18 #include "components/bookmarks/test/bookmark_test_helpers.h"
19 #include "components/prefs/testing_pref_service.h"
20 #include "components/search_engines/template_url_service.h"
21 #include "components/sessions/core/tab_restore_service.h"
22 #include "components/toolbar/test_toolbar_model.h"
23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
24 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
25 #include "ios/chrome/browser/chrome_paths.h"
26 #include "ios/chrome/browser/chrome_switches.h"
27 #include "ios/chrome/browser/chrome_url_constants.h"
28 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h"
29 #import "ios/chrome/browser/find_in_page/find_in_page_model.h"
30 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
31 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h"
32 #import "ios/chrome/browser/tabs/tab.h"
33 #import "ios/chrome/browser/tabs/tab_model.h"
34 #import "ios/chrome/browser/ui/activity_services/share_protocol.h"
35 #import "ios/chrome/browser/ui/activity_services/share_to_data.h"
36 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
37 #import "ios/chrome/browser/ui/browser_view_controller.h"
38 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h"
39 #import "ios/chrome/browser/ui/browser_view_controller_testing.h"
40 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
41 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
42 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h"
43 #import "ios/chrome/browser/ui/page_not_available_controller.h"
44 #include "ios/chrome/browser/ui/toolbar/test_toolbar_model_ios.h"
45 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
46 #include "ios/chrome/browser/ui/ui_util.h"
47 #import "ios/chrome/browser/web/error_page_content.h"
48 #import "ios/chrome/browser/web/passkit_dialog_provider.h"
49 #include "ios/chrome/grit/ios_strings.h"
50 #include "ios/chrome/test/block_cleanup_test.h"
51 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h"
52 #include "ios/chrome/test/testing_application_context.h"
53 #import "ios/testing/ocmock_complex_type_helper.h"
54 #import "ios/web/navigation/crw_session_controller.h"
55 #include "ios/web/public/referrer.h"
56 #include "ios/web/public/test/test_web_thread_bundle.h"
57 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
58 #import "ios/web/web_state/ui/crw_web_controller.h"
59 #import "ios/web/web_state/web_state_impl.h"
60 #import "net/base/mac/url_conversions.h"
61 #include "net/url_request/url_request_test_util.h"
62 #include "testing/gmock/include/gmock/gmock.h"
63 #include "testing/gtest/include/gtest/gtest.h"
64 #include "testing/gtest_mac.h"
65 #import "third_party/ocmock/OCMock/OCMock.h"
66 #include "third_party/ocmock/gtest_support.h"
67 #include "ui/base/l10n/l10n_util.h"
68 #include "ui/base/l10n/l10n_util_mac.h"
69
70 using web::NavigationManagerImpl;
71 using web::WebStateImpl;
72
73 // Private methods in BrowserViewController to test.
74 @interface BrowserViewController (
75 Testing)<CRWNativeContentProvider, PassKitDialogProvider, ShareToDelegate>
76 - (void)pageLoadStarted:(NSNotification*)notification;
77 - (void)pageLoadComplete:(NSNotification*)notification;
78 - (void)tabSelected:(Tab*)tab;
79 - (void)tabDeselected:(NSNotification*)notification;
80 - (void)tabCountChanged:(NSNotification*)notification;
81 - (IBAction)chromeExecuteCommand:(id)sender;
82 @end
83
84 @interface BVCTestTabMock : OCMockComplexTypeHelper {
85 GURL url_;
86 WebStateImpl* webState_;
87 }
88
89 @property(nonatomic, assign) const GURL& url;
90 @property(nonatomic, assign) WebStateImpl* webState;
91
92 - (NavigationManagerImpl*)navigationManager;
93
94 @end
95
96 @implementation BVCTestTabMock
97 - (const GURL&)url {
98 return url_;
99 }
100 - (void)setUrl:(const GURL&)url {
101 url_ = url;
102 }
103 - (WebStateImpl*)webState {
104 return webState_;
105 }
106 - (void)setWebState:(WebStateImpl*)webState {
107 webState_ = webState;
108 }
109 - (NavigationManagerImpl*)navigationManager {
110 return &(webState_->GetNavigationManagerImpl());
111 }
112 @end
113
114 #pragma mark -
115
116 namespace {
117 class BrowserViewControllerTest : public BlockCleanupTest {
118 public:
119 BrowserViewControllerTest() {}
120
121 protected:
122 void SetUp() override {
123 BlockCleanupTest::SetUp();
124 // Disable Contextual Search on the command line.
125 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
126 switches::kDisableContextualSearch)) {
127 base::CommandLine::ForCurrentProcess()->AppendSwitch(
128 switches::kDisableContextualSearch);
129 }
130
131 // Set up a TestChromeBrowserState instance.
132 TestChromeBrowserState::Builder test_cbs_builder;
133 test_cbs_builder.AddTestingFactory(
134 IOSChromeTabRestoreServiceFactory::GetInstance(),
135 IOSChromeTabRestoreServiceFactory::GetDefaultFactory());
136 test_cbs_builder.AddTestingFactory(
137 ios::TemplateURLServiceFactory::GetInstance(),
138 ios::TemplateURLServiceFactory::GetDefaultFactory());
139 chrome_browser_state_ = test_cbs_builder.Build();
140 chrome_browser_state_->CreateBookmarkModel(false);
141 bookmarks::BookmarkModel* bookmark_model =
142 ios::BookmarkModelFactory::GetForBrowserState(
143 chrome_browser_state_.get());
144 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
145
146 // Set up mock TabModel, Tab, CRWWebController and FindInPageController.
147 id tabModel = [OCMockObject mockForClass:[TabModel class]];
148 base::scoped_nsobject<id> currentTab([[BVCTestTabMock alloc]
149 initWithRepresentedObject:[OCMockObject niceMockForClass:[Tab class]]]);
150 id webControllerMock =
151 [OCMockObject niceMockForClass:[CRWWebController class]];
152 id findInPageControllerMock =
153 [OCMockObject niceMockForClass:[FindInPageController class]];
154
155 // Stub methods for TabModel.
156 NSUInteger tabCount = 1;
157 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(tabCount)] count];
158 BOOL enabled = YES;
159 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(enabled)] webUsageEnabled];
160 [[[tabModel stub] andReturn:currentTab] currentTab];
161 [[[tabModel stub] andReturn:currentTab] tabAtIndex:0];
162 GURL URL("http://www.google.com");
163 [[[tabModel stub] andReturn:currentTab] addTabWithURL:URL
164 referrer:web::Referrer()
165 windowName:[OCMArg any]];
166 [[tabModel stub] addObserver:[OCMArg any]];
167 [[tabModel stub] removeObserver:[OCMArg any]];
168 [[tabModel stub] saveSessionImmediately:NO];
169 [[tabModel stub] setCurrentTab:[OCMArg any]];
170 [[tabModel stub] closeAllTabs];
171
172 // Stub methods for Tab.
173 UIView* dummyView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
174 [[[currentTab stub] andReturn:dummyView] view];
175 [[[currentTab stub] andReturn:webControllerMock] webController];
176 [[[currentTab stub] andReturn:findInPageControllerMock]
177 findInPageController];
178
179 id sessionControllerMock =
180 [OCMockObject niceMockForClass:[CRWSessionController class]];
181 webStateImpl_.reset(new WebStateImpl(chrome_browser_state_.get()));
182 [currentTab setWebState:webStateImpl_.get()];
183 webStateImpl_->SetWebController(webControllerMock);
184 webStateImpl_->GetNavigationManagerImpl().SetSessionController(
185 sessionControllerMock);
186
187 // Set up mock ShareController.
188 id shareController =
189 [OCMockObject niceMockForProtocol:@protocol(ShareProtocol)];
190 shareController_.reset([shareController retain]);
191
192 id passKitController =
193 [OCMockObject niceMockForClass:[PKAddPassesViewController class]];
194 passKitViewController_.reset([passKitController retain]);
195
196 // Set up a fake toolbar model for the dependency factory to return.
197 // It will be owned (and destroyed) by the BVC.
198 toolbarModelIOS_ = new TestToolbarModelIOS();
199
200 // Set up a stub dependency factory.
201 id factory = [OCMockObject
202 mockForClass:[BrowserViewControllerDependencyFactory class]];
203 [[[factory stub] andReturn:nil]
204 newTabStripControllerWithTabModel:[OCMArg any]];
205 [[[factory stub] andReturn:nil] newPreloadController];
206 [[[factory stub] andReturnValue:OCMOCK_VALUE(toolbarModelIOS_)]
207 newToolbarModelIOSWithDelegate:(ToolbarModelDelegateIOS*)
208 [OCMArg anyPointer]];
209 [[[factory stub] andReturn:nil]
210 newWebToolbarControllerWithDelegate:[OCMArg any]
211 urlLoader:[OCMArg any]
212 preloadProvider:[OCMArg any]];
213 [[[factory stub] andReturn:shareController_.get()] shareControllerInstance];
214 [[[factory stub] andReturn:passKitViewController_.get()]
215 newPassKitViewControllerForPass:nil];
216 [[[factory stub] andReturn:nil] showPassKitErrorInfoBarForManager:nil];
217
218 webController_.reset([webControllerMock retain]);
219 findInPageController_.reset([findInPageControllerMock retain]);
220 tabModel_.reset([tabModel retain]);
221 tab_.reset([currentTab retain]);
222 dependencyFactory_.reset([factory retain]);
223 bvc_.reset([[BrowserViewController alloc]
224 initWithTabModel:tabModel_
225 browserState:chrome_browser_state_.get()
226 dependencyFactory:factory]);
227
228 // Load TemplateURLService.
229 TemplateURLService* template_url_service =
230 ios::TemplateURLServiceFactory::GetForBrowserState(
231 chrome_browser_state_.get());
232 template_url_service->Load();
233
234 // Force the view to load.
235 UIWindow* window = [[UIWindow alloc] initWithFrame:CGRectZero];
236 [window addSubview:[bvc_ view]];
237 window_.reset(window);
238 }
239
240 void TearDown() override {
241 [[bvc_ view] removeFromSuperview];
242 BlockCleanupTest::TearDown();
243 }
244
245 base::scoped_nsobject<GenericChromeCommand> GetCommandWithTag(NSInteger tag) {
246 base::scoped_nsobject<GenericChromeCommand> command(
247 [[GenericChromeCommand alloc] initWithTag:tag]);
248 return command;
249 }
250
251 MOCK_METHOD0(OnCompletionCalled, void());
252
253 web::TestWebThreadBundle thread_bundle_;
254 IOSChromeScopedTestingLocalState local_state_;
255 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
256 std::unique_ptr<WebStateImpl> webStateImpl_;
257 base::scoped_nsobject<CRWWebController> webController_;
258 base::scoped_nsobject<Tab> tab_;
259 base::scoped_nsobject<TabModel> tabModel_;
260 ToolbarModelIOS* toolbarModelIOS_;
261 base::scoped_nsprotocol<id<ShareProtocol>> shareController_;
262 base::scoped_nsobject<FindInPageController> findInPageController_;
263 base::scoped_nsobject<PKAddPassesViewController> passKitViewController_;
264 base::scoped_nsobject<OCMockObject> dependencyFactory_;
265 base::scoped_nsobject<BrowserViewController> bvc_;
266 base::scoped_nsobject<UIWindow> window_;
267 };
268
269 // TODO(crbug.com/228714): These tests pretty much only tested that BVC passed
270 // notifications on to the toolbar, and that the toolbar worked correctly. The
271 // former should be an integration test, and the latter should be a toolbar
272 // test. Leaving DISABLED_ for now to remind us to move them to toolbar tests.
273 TEST_F(BrowserViewControllerTest, DISABLED_TestPageLoadStarted) {
274 NSDictionary* userInfoWithThisTab =
275 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey];
276 NSNotification* notification = [NSNotification
277 notificationWithName:kTabModelTabWillStartLoadingNotification
278 object:nil
279 userInfo:userInfoWithThisTab];
280 [bvc_ pageLoadStarted:notification];
281 EXPECT_TRUE([bvc_ testing_isLoading]);
282 }
283
284 TEST_F(BrowserViewControllerTest, DISABLED_TestPageLoadComplete) {
285 NSDictionary* userInfoWithThisTab =
286 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey];
287 NSNotification* notification = [NSNotification
288 notificationWithName:kTabModelTabDidFinishLoadingNotification
289 object:nil
290 userInfo:userInfoWithThisTab];
291 [bvc_ pageLoadComplete:notification];
292 EXPECT_FALSE([bvc_ testing_isLoading]);
293 }
294
295 TEST_F(BrowserViewControllerTest, TestTabSelected) {
296 id tabMock = (id)tab_.get();
297 [[tabMock expect] wasShown];
298 [bvc_ tabSelected:tab_];
299 EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea]));
300 EXPECT_OCMOCK_VERIFY(tabMock);
301 }
302
303 TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) {
304 base::scoped_nsobject<id> block([^{
305 return GURL(kChromeUINewTabURL);
306 } copy]);
307 id tabMock = (id)tab_.get();
308 [tabMock onSelector:@selector(url) callBlockExpectation:block];
309 [[tabMock expect] wasShown];
310 [bvc_ tabSelected:tab_];
311 EXPECT_EQ([[tab_ view] superview], static_cast<UIView*>([bvc_ contentArea]));
312 EXPECT_OCMOCK_VERIFY(tabMock);
313 }
314
315 TEST_F(BrowserViewControllerTest, TestTabDeselected) {
316 OCMockObject* tabMock = (OCMockObject*)tab_.get();
317 [[tabMock expect] wasHidden];
318 NSDictionary* userInfoWithThisTab =
319 [NSDictionary dictionaryWithObject:tab_ forKey:kTabModelTabKey];
320 NSNotification* notification =
321 [NSNotification notificationWithName:kTabModelTabDeselectedNotification
322 object:nil
323 userInfo:userInfoWithThisTab];
324 [bvc_ tabDeselected:notification];
325 EXPECT_OCMOCK_VERIFY(tabMock);
326 }
327
328 TEST_F(BrowserViewControllerTest, TestNativeContentController) {
329 id<CRWNativeContent> controller =
330 [bvc_ controllerForURL:GURL(kChromeUINewTabURL)];
331 EXPECT_TRUE(controller != nil);
332 EXPECT_TRUE([controller isMemberOfClass:[NewTabPageController class]]);
333
334 controller = [bvc_ controllerForURL:GURL(kChromeUISettingsURL)];
335 EXPECT_TRUE(controller != nil);
336 EXPECT_TRUE([controller isMemberOfClass:[PageNotAvailableController class]]);
337 }
338
339 TEST_F(BrowserViewControllerTest, TestErrorController) {
340 const GURL badUrl("http://floofywhizbangzzz.com");
341 NSString* badURLString = base::SysUTF8ToNSString(badUrl.spec());
342 NSDictionary* userInfoDic = [NSDictionary
343 dictionaryWithObjectsAndKeys:badURLString,
344 NSURLErrorFailingURLStringErrorKey,
345 [NSError
346 errorWithDomain:base::SysUTF8ToNSString(
347 net::kErrorDomain)
348 code:-104
349 userInfo:nil],
350 NSUnderlyingErrorKey, nil];
351 NSError* testError =
352 [NSError errorWithDomain:@"testdomain" code:-1 userInfo:userInfoDic];
353 id<CRWNativeContent> controller =
354 [bvc_ controllerForURL:badUrl withError:testError isPost:NO];
355 EXPECT_TRUE(controller != nil);
356 EXPECT_TRUE([controller isMemberOfClass:[ErrorPageContent class]]);
357 }
358
359 // TODO(altse): Needs a testing |Profile| that implements AutocompleteClassifier
360 // before enabling again.
361 TEST_F(BrowserViewControllerTest, DISABLED_TestShieldWasTapped) {
362 [bvc_ testing_focusOmnibox];
363 EXPECT_TRUE([[bvc_ typingShield] superview] != nil);
364 EXPECT_FALSE([[bvc_ typingShield] isHidden]);
365 [bvc_ shieldWasTapped:nil];
366 EXPECT_TRUE([[bvc_ typingShield] superview] == nil);
367 EXPECT_TRUE([[bvc_ typingShield] isHidden]);
368 }
369
370 // Verifies that editing the omnimbox while the page is loading will stop the
371 // load on a handset, but not stop the load on a tablet.
372 TEST_F(BrowserViewControllerTest,
373 TestLocationBarBeganEdit_whenPageLoadIsInProgress) {
374 OCMockObject* tabMock = (OCMockObject*)tab_.get();
375
376 // Have the TestToolbarModel indicate that a page load is in progress.
377 ((TestToolbarModelIOS*)toolbarModelIOS_)->set_is_loading(true);
378
379 // The tab should only stop loading on handsets.
380 if (!IsIPadIdiom())
381 [[tabMock expect] stopLoading];
382 [bvc_ locationBarBeganEdit:nil];
383
384 EXPECT_OCMOCK_VERIFY(tabMock);
385 }
386
387 // Verifies that editing the omnibox when the page is not loading will not try
388 // to stop the load on a handset or a tablet.
389 TEST_F(BrowserViewControllerTest,
390 TestLocationBarBeganEdit_whenPageLoadIsComplete) {
391 OCMockObject* tabMock = (OCMockObject*)tab_.get();
392
393 // Have the TestToolbarModel indicate that the page load is complete.
394 ((TestToolbarModelIOS*)toolbarModelIOS_)->set_is_loading(false);
395
396 // Don't set any expectation for stopLoading to be called on the mock tab.
397 [bvc_ locationBarBeganEdit:nil];
398
399 EXPECT_OCMOCK_VERIFY(tabMock);
400 }
401
402 // Verifies that BVC invokes -shareURL on ShareController with the correct
403 // parameters in response to the IDC_SHARE_PAGE command.
404 TEST_F(BrowserViewControllerTest, TestSharePageCommandHandling) {
405 GURL expectedUrl("http://www.testurl.net");
406 NSString* expectedTitle = @"title";
407 [(BVCTestTabMock*)tab_.get() setUrl:expectedUrl];
408 OCMockObject* tabMock = (OCMockObject*)tab_.get();
409 [[[tabMock stub] andReturn:expectedTitle] title];
410 [[[tabMock stub] andReturn:expectedTitle] originalTitle];
411 base::scoped_nsobject<ShareToData> expectedShareData([[ShareToData alloc]
412 initWithURL:expectedUrl
413 title:expectedTitle
414 isOriginalTitle:YES
415 isPagePrintable:YES]);
416 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get();
417 // Passing non zero/nil |fromRect| and |inView| parameters to satisfy protocol
418 // requirements.
419 [[shareControllerMock expect]
420 shareWithData:expectedShareData
421 controller:bvc_
422 browserState:chrome_browser_state_.get()
423 shareToDelegate:bvc_
424 fromRect:[bvc_ testing_shareButtonAnchorRect]
425 inView:[OCMArg any]];
426 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)];
427 EXPECT_OCMOCK_VERIFY(shareControllerMock);
428 }
429
430 // Verifies that BVC does not invoke -shareURL on ShareController in response
431 // to the IDC_SHARE_PAGE command if tab is in the process of being closed.
432 TEST_F(BrowserViewControllerTest, TestSharePageWhenClosing) {
433 GURL expectedUrl("http://www.testurl.net");
434 NSString* expectedTitle = @"title";
435 // Sets WebState to nil because [tab close] clears the WebState.
436 [(BVCTestTabMock*)tab_.get() setWebState:nil];
437 [(BVCTestTabMock*)tab_.get() setUrl:expectedUrl];
438 OCMockObject* tabMock = (OCMockObject*)tab_.get();
439 [[[tabMock stub] andReturn:expectedTitle] title];
440 [[[tabMock stub] andReturn:expectedTitle] originalTitle];
441 // Explicitly disallow the execution of the ShareController.
442 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get();
443 [[shareControllerMock reject]
444 shareWithData:[OCMArg any]
445 controller:bvc_
446 browserState:chrome_browser_state_.get()
447 shareToDelegate:bvc_
448 fromRect:[bvc_ testing_shareButtonAnchorRect]
449 inView:[OCMArg any]];
450 [bvc_ chromeExecuteCommand:GetCommandWithTag(IDC_SHARE_PAGE)];
451 EXPECT_OCMOCK_VERIFY(shareControllerMock);
452 }
453
454 // Verifies that BVC instantiates a bubble to show the given success message on
455 // receiving a -shareDidComplete callback for a successful share.
456 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithSuccess) {
457 NSString* successMessage = @"Success";
458 [[dependencyFactory_ expect] showSnackbarWithMessage:successMessage];
459
460 [bvc_ shareDidComplete:ShareTo::SHARE_SUCCESS successMessage:successMessage];
461 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
462 }
463
464 // Verifies that BVC shows an alert with the proper error message on
465 // receiving a -shareDidComplete callback for a failed share.
466 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithError) {
467 [[dependencyFactory_ reject] showSnackbarWithMessage:OCMOCK_ANY];
468 base::scoped_nsobject<OCMockObject> mockCoordinator(
469 [[OCMockObject niceMockForClass:[AlertCoordinator class]] retain]);
470 AlertCoordinator* alertCoordinator =
471 static_cast<AlertCoordinator*>(mockCoordinator.get());
472 NSString* errorTitle =
473 l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT_TITLE);
474 NSString* errorMessage = l10n_util::GetNSString(IDS_IOS_SHARE_TO_ERROR_ALERT);
475 [[[dependencyFactory_ expect] andReturn:alertCoordinator]
476 alertCoordinatorWithTitle:errorTitle
477 message:errorMessage
478 viewController:OCMOCK_ANY];
479 [((AlertCoordinator*)[mockCoordinator expect])start];
480
481 [bvc_ shareDidComplete:ShareTo::SHARE_ERROR successMessage:@"dummy"];
482 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
483 EXPECT_OCMOCK_VERIFY(mockCoordinator);
484 }
485
486 // Verifies that BVC does not show a success bubble or error alert on receiving
487 // a -shareDidComplete callback for a cancelled share.
488 TEST_F(BrowserViewControllerTest, TestShareDidCompleteWithCancellation) {
489 [[dependencyFactory_ reject] showSnackbarWithMessage:OCMOCK_ANY];
490 [[dependencyFactory_ reject] alertCoordinatorWithTitle:OCMOCK_ANY
491 message:OCMOCK_ANY
492 viewController:OCMOCK_ANY];
493
494 [bvc_ shareDidComplete:ShareTo::SHARE_CANCEL successMessage:@"dummy"];
495 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
496 }
497
498 TEST_F(BrowserViewControllerTest, TestPassKitDialogDisplayed) {
499 // Create a good Pass and make sure the controller is displayed.
500 base::FilePath pass_path;
501 ASSERT_TRUE(PathService::Get(ios::DIR_TEST_DATA, &pass_path));
502 pass_path = pass_path.Append(FILE_PATH_LITERAL("testpass.pkpass"));
503 NSData* passKitObject = [NSData
504 dataWithContentsOfFile:base::SysUTF8ToNSString(pass_path.value())];
505 EXPECT_TRUE(passKitObject);
506 [[dependencyFactory_ expect] newPassKitViewControllerForPass:OCMOCK_ANY];
507 [bvc_ presentPassKitDialog:passKitObject];
508 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
509 }
510
511 TEST_F(BrowserViewControllerTest, TestPassKitErrorInfoBarDisplayed) {
512 // Create a bad Pass and make sure the controller is not displayed.
513 base::FilePath bad_pass_path;
514 ASSERT_TRUE(PathService::Get(ios::DIR_TEST_DATA, &bad_pass_path));
515 bad_pass_path = bad_pass_path.Append(FILE_PATH_LITERAL("testbadpass.pkpass"));
516 NSData* badPassKitObject = [NSData
517 dataWithContentsOfFile:base::SysUTF8ToNSString(bad_pass_path.value())];
518 EXPECT_TRUE(badPassKitObject);
519 [[dependencyFactory_ reject] newPassKitViewControllerForPass:OCMOCK_ANY];
520 [bvc_ presentPassKitDialog:badPassKitObject];
521 EXPECT_OCMOCK_VERIFY(dependencyFactory_);
522 }
523
524 TEST_F(BrowserViewControllerTest, TestClearPresentedState) {
525 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get();
526 [[shareControllerMock expect] cancelShareAnimated:NO];
527 EXPECT_CALL(*this, OnCompletionCalled());
528 [bvc_ clearPresentedStateWithCompletion:^{
529 this->OnCompletionCalled();
530 }];
531 EXPECT_OCMOCK_VERIFY(shareControllerMock);
532 }
533
534 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/browser_view_controller_testing.mm ('k') | ios/chrome/browser/ui/chrome_web_view_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698