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

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

Issue 2654433007: [ios] Moves find-in-page code out of Tab and into FindTabHelper. (Closed)
Patch Set: Null checks Created 3 years, 10 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" 13 #include "base/mac/scoped_nsautorelease_pool.h"
14 #include "base/mac/scoped_nsobject.h" 14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
18 #include "components/bookmarks/test/bookmark_test_helpers.h" 18 #include "components/bookmarks/test/bookmark_test_helpers.h"
19 #include "components/prefs/testing_pref_service.h" 19 #include "components/prefs/testing_pref_service.h"
20 #include "components/search_engines/template_url_service.h" 20 #include "components/search_engines/template_url_service.h"
21 #include "components/sessions/core/tab_restore_service.h" 21 #include "components/sessions/core/tab_restore_service.h"
22 #include "components/toolbar/test_toolbar_model.h" 22 #include "components/toolbar/test_toolbar_model.h"
23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
24 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 24 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
25 #include "ios/chrome/browser/chrome_paths.h" 25 #include "ios/chrome/browser/chrome_paths.h"
26 #include "ios/chrome/browser/chrome_switches.h" 26 #include "ios/chrome/browser/chrome_switches.h"
27 #include "ios/chrome/browser/chrome_url_constants.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" 28 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
31 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h" 29 #include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h"
32 #import "ios/chrome/browser/tabs/tab.h" 30 #import "ios/chrome/browser/tabs/tab.h"
33 #import "ios/chrome/browser/tabs/tab_model.h" 31 #import "ios/chrome/browser/tabs/tab_model.h"
34 #import "ios/chrome/browser/ui/activity_services/share_protocol.h" 32 #import "ios/chrome/browser/ui/activity_services/share_protocol.h"
35 #import "ios/chrome/browser/ui/activity_services/share_to_data.h" 33 #import "ios/chrome/browser/ui/activity_services/share_to_data.h"
36 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" 34 #import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
37 #import "ios/chrome/browser/ui/browser_view_controller.h" 35 #import "ios/chrome/browser/ui/browser_view_controller.h"
38 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h" 36 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h"
39 #import "ios/chrome/browser/ui/browser_view_controller_testing.h" 37 #import "ios/chrome/browser/ui/browser_view_controller_testing.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 test_cbs_builder.AddTestingFactory( 134 test_cbs_builder.AddTestingFactory(
137 ios::TemplateURLServiceFactory::GetInstance(), 135 ios::TemplateURLServiceFactory::GetInstance(),
138 ios::TemplateURLServiceFactory::GetDefaultFactory()); 136 ios::TemplateURLServiceFactory::GetDefaultFactory());
139 chrome_browser_state_ = test_cbs_builder.Build(); 137 chrome_browser_state_ = test_cbs_builder.Build();
140 chrome_browser_state_->CreateBookmarkModel(false); 138 chrome_browser_state_->CreateBookmarkModel(false);
141 bookmarks::BookmarkModel* bookmark_model = 139 bookmarks::BookmarkModel* bookmark_model =
142 ios::BookmarkModelFactory::GetForBrowserState( 140 ios::BookmarkModelFactory::GetForBrowserState(
143 chrome_browser_state_.get()); 141 chrome_browser_state_.get());
144 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); 142 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
145 143
146 // Set up mock TabModel, Tab, CRWWebController and FindInPageController. 144 // Set up mock TabModel, Tab, and CRWWebController.
147 id tabModel = [OCMockObject mockForClass:[TabModel class]]; 145 id tabModel = [OCMockObject mockForClass:[TabModel class]];
148 base::scoped_nsobject<id> currentTab([[BVCTestTabMock alloc] 146 base::scoped_nsobject<id> currentTab([[BVCTestTabMock alloc]
149 initWithRepresentedObject:[OCMockObject niceMockForClass:[Tab class]]]); 147 initWithRepresentedObject:[OCMockObject niceMockForClass:[Tab class]]]);
150 id webControllerMock = 148 id webControllerMock =
151 [OCMockObject niceMockForClass:[CRWWebController class]]; 149 [OCMockObject niceMockForClass:[CRWWebController class]];
152 id findInPageControllerMock =
153 [OCMockObject niceMockForClass:[FindInPageController class]];
154 150
155 // Stub methods for TabModel. 151 // Stub methods for TabModel.
156 NSUInteger tabCount = 1; 152 NSUInteger tabCount = 1;
157 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(tabCount)] count]; 153 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(tabCount)] count];
158 BOOL enabled = YES; 154 BOOL enabled = YES;
159 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(enabled)] webUsageEnabled]; 155 [[[tabModel stub] andReturnValue:OCMOCK_VALUE(enabled)] webUsageEnabled];
160 [[[tabModel stub] andReturn:currentTab] currentTab]; 156 [[[tabModel stub] andReturn:currentTab] currentTab];
161 [[[tabModel stub] andReturn:currentTab] tabAtIndex:0]; 157 [[[tabModel stub] andReturn:currentTab] tabAtIndex:0];
162 GURL URL("http://www.google.com"); 158 GURL URL("http://www.google.com");
163 [[[tabModel stub] andReturn:currentTab] addTabWithURL:URL 159 [[[tabModel stub] andReturn:currentTab] addTabWithURL:URL
164 referrer:web::Referrer() 160 referrer:web::Referrer()
165 windowName:[OCMArg any]]; 161 windowName:[OCMArg any]];
166 [[tabModel stub] addObserver:[OCMArg any]]; 162 [[tabModel stub] addObserver:[OCMArg any]];
167 [[tabModel stub] removeObserver:[OCMArg any]]; 163 [[tabModel stub] removeObserver:[OCMArg any]];
168 [[tabModel stub] saveSessionImmediately:NO]; 164 [[tabModel stub] saveSessionImmediately:NO];
169 [[tabModel stub] setCurrentTab:[OCMArg any]]; 165 [[tabModel stub] setCurrentTab:[OCMArg any]];
170 [[tabModel stub] closeAllTabs]; 166 [[tabModel stub] closeAllTabs];
171 167
172 // Stub methods for Tab. 168 // Stub methods for Tab.
173 UIView* dummyView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 169 UIView* dummyView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
174 [[[currentTab stub] andReturn:dummyView] view]; 170 [[[currentTab stub] andReturn:dummyView] view];
175 [[[currentTab stub] andReturn:webControllerMock] webController]; 171 [[[currentTab stub] andReturn:webControllerMock] webController];
176 [[[currentTab stub] andReturn:findInPageControllerMock]
177 findInPageController];
178 172
179 id sessionControllerMock = 173 id sessionControllerMock =
180 [OCMockObject niceMockForClass:[CRWSessionController class]]; 174 [OCMockObject niceMockForClass:[CRWSessionController class]];
181 webStateImpl_.reset(new WebStateImpl(chrome_browser_state_.get())); 175 webStateImpl_.reset(new WebStateImpl(chrome_browser_state_.get()));
182 [currentTab setWebState:webStateImpl_.get()]; 176 [currentTab setWebState:webStateImpl_.get()];
183 webStateImpl_->SetWebController(webControllerMock); 177 webStateImpl_->SetWebController(webControllerMock);
184 webStateImpl_->GetNavigationManagerImpl().SetSessionController( 178 webStateImpl_->GetNavigationManagerImpl().SetSessionController(
185 sessionControllerMock); 179 sessionControllerMock);
186 180
187 // Set up mock ShareController. 181 // Set up mock ShareController.
(...skipping 21 matching lines...) Expand all
209 [[[factory stub] andReturn:nil] 203 [[[factory stub] andReturn:nil]
210 newWebToolbarControllerWithDelegate:[OCMArg any] 204 newWebToolbarControllerWithDelegate:[OCMArg any]
211 urlLoader:[OCMArg any] 205 urlLoader:[OCMArg any]
212 preloadProvider:[OCMArg any]]; 206 preloadProvider:[OCMArg any]];
213 [[[factory stub] andReturn:shareController_.get()] shareControllerInstance]; 207 [[[factory stub] andReturn:shareController_.get()] shareControllerInstance];
214 [[[factory stub] andReturn:passKitViewController_.get()] 208 [[[factory stub] andReturn:passKitViewController_.get()]
215 newPassKitViewControllerForPass:nil]; 209 newPassKitViewControllerForPass:nil];
216 [[[factory stub] andReturn:nil] showPassKitErrorInfoBarForManager:nil]; 210 [[[factory stub] andReturn:nil] showPassKitErrorInfoBarForManager:nil];
217 211
218 webController_.reset([webControllerMock retain]); 212 webController_.reset([webControllerMock retain]);
219 findInPageController_.reset([findInPageControllerMock retain]);
220 tabModel_.reset([tabModel retain]); 213 tabModel_.reset([tabModel retain]);
221 tab_.reset([currentTab retain]); 214 tab_.reset([currentTab retain]);
222 dependencyFactory_.reset([factory retain]); 215 dependencyFactory_.reset([factory retain]);
223 bvc_.reset([[BrowserViewController alloc] 216 bvc_.reset([[BrowserViewController alloc]
224 initWithTabModel:tabModel_ 217 initWithTabModel:tabModel_
225 browserState:chrome_browser_state_.get() 218 browserState:chrome_browser_state_.get()
226 dependencyFactory:factory]); 219 dependencyFactory:factory]);
227 220
228 // Load TemplateURLService. 221 // Load TemplateURLService.
229 TemplateURLService* template_url_service = 222 TemplateURLService* template_url_service =
(...skipping 22 matching lines...) Expand all
252 245
253 web::TestWebThreadBundle thread_bundle_; 246 web::TestWebThreadBundle thread_bundle_;
254 IOSChromeScopedTestingLocalState local_state_; 247 IOSChromeScopedTestingLocalState local_state_;
255 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 248 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
256 std::unique_ptr<WebStateImpl> webStateImpl_; 249 std::unique_ptr<WebStateImpl> webStateImpl_;
257 base::scoped_nsobject<CRWWebController> webController_; 250 base::scoped_nsobject<CRWWebController> webController_;
258 base::scoped_nsobject<Tab> tab_; 251 base::scoped_nsobject<Tab> tab_;
259 base::scoped_nsobject<TabModel> tabModel_; 252 base::scoped_nsobject<TabModel> tabModel_;
260 ToolbarModelIOS* toolbarModelIOS_; 253 ToolbarModelIOS* toolbarModelIOS_;
261 base::scoped_nsprotocol<id<ShareProtocol>> shareController_; 254 base::scoped_nsprotocol<id<ShareProtocol>> shareController_;
262 base::scoped_nsobject<FindInPageController> findInPageController_;
263 base::scoped_nsobject<PKAddPassesViewController> passKitViewController_; 255 base::scoped_nsobject<PKAddPassesViewController> passKitViewController_;
264 base::scoped_nsobject<OCMockObject> dependencyFactory_; 256 base::scoped_nsobject<OCMockObject> dependencyFactory_;
265 base::scoped_nsobject<BrowserViewController> bvc_; 257 base::scoped_nsobject<BrowserViewController> bvc_;
266 base::scoped_nsobject<UIWindow> window_; 258 base::scoped_nsobject<UIWindow> window_;
267 }; 259 };
268 260
269 // TODO(crbug.com/228714): These tests pretty much only tested that BVC passed 261 // 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 262 // 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 263 // 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. 264 // test. Leaving DISABLED_ for now to remind us to move them to toolbar tests.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get(); 519 OCMockObject* shareControllerMock = (OCMockObject*)shareController_.get();
528 [[shareControllerMock expect] cancelShareAnimated:NO]; 520 [[shareControllerMock expect] cancelShareAnimated:NO];
529 EXPECT_CALL(*this, OnCompletionCalled()); 521 EXPECT_CALL(*this, OnCompletionCalled());
530 [bvc_ clearPresentedStateWithCompletion:^{ 522 [bvc_ clearPresentedStateWithCompletion:^{
531 this->OnCompletionCalled(); 523 this->OnCompletionCalled();
532 }]; 524 }];
533 EXPECT_OCMOCK_VERIFY(shareControllerMock); 525 EXPECT_OCMOCK_VERIFY(shareControllerMock);
534 } 526 }
535 527
536 } // namespace 528 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698