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

Side by Side Diff: ios/chrome/browser/tabs/tab_unittest.mm

Issue 2886763003: [ios] Convert //ios/chrome/browser/tabs:unit_tests to ARC. (Closed)
Patch Set: Rebase Created 3 years, 7 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/tabs/tab_model_unittest.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 <UIKit/UIKit.h> 5 #import <UIKit/UIKit.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/ios/block_types.h" 11 #include "base/ios/block_types.h"
12 #import "base/ios/weak_nsobject.h"
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
15 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
16 #include "base/run_loop.h" 14 #include "base/run_loop.h"
17 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
18 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
19 #include "components/bookmarks/test/bookmark_test_helpers.h" 17 #include "components/bookmarks/test/bookmark_test_helpers.h"
20 #include "components/history/core/browser/history_service.h" 18 #include "components/history/core/browser/history_service.h"
21 #include "components/keyed_service/core/service_access_type.h" 19 #include "components/keyed_service/core/service_access_type.h"
22 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 20 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
23 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 21 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
(...skipping 25 matching lines...) Expand all
49 #include "ios/web/public/test/test_web_thread_bundle.h" 47 #include "ios/web/public/test/test_web_thread_bundle.h"
50 #import "ios/web/web_state/navigation_context_impl.h" 48 #import "ios/web/web_state/navigation_context_impl.h"
51 #import "ios/web/web_state/ui/crw_web_controller.h" 49 #import "ios/web/web_state/ui/crw_web_controller.h"
52 #import "ios/web/web_state/web_state_impl.h" 50 #import "ios/web/web_state/web_state_impl.h"
53 #import "net/base/mac/url_conversions.h" 51 #import "net/base/mac/url_conversions.h"
54 #include "net/http/http_response_headers.h" 52 #include "net/http/http_response_headers.h"
55 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
56 #include "testing/gtest_mac.h" 54 #include "testing/gtest_mac.h"
57 #import "third_party/ocmock/OCMock/OCMock.h" 55 #import "third_party/ocmock/OCMock/OCMock.h"
58 56
59 using web::WebStateImpl; 57 #if !defined(__has_feature) || !__has_feature(objc_arc)
58 #error "This file requires ARC support."
59 #endif
60 60
61 static const char kAppSettingsUrl[] = "app-settings://"; 61 namespace {
62 static const char kNewTabUrl[] = "chrome://newtab/"; 62 const char kAppSettingsUrl[] = "app-settings://";
63 static const char kGoogleUserUrl[] = "http://google.com"; 63 const char kNewTabUrl[] = "chrome://newtab/";
64 static const char kGoogleRedirectUrl[] = "http://www.google.fr/"; 64 const char kGoogleUserUrl[] = "http://google.com";
65 const char kGoogleRedirectUrl[] = "http://www.google.fr/";
65 static NSString* const kGoogleTitle = @"Google"; 66 static NSString* const kGoogleTitle = @"Google";
66 static const char kOtherUserUrl[] = "http://other.com"; 67 const char kOtherUserUrl[] = "http://other.com";
67 static const char kOtherRedirectUrl[] = "http://other.fr/"; 68 const char kOtherRedirectUrl[] = "http://other.fr/";
68 static NSString* const kOtherTitle = @"Other"; 69 NSString* const kOtherTitle = @"Other";
69 const char kContentDispositionWithFilename[] = 70 const char kContentDispositionWithFilename[] =
70 "attachment; filename=\"suggested_filename.pdf\""; 71 "attachment; filename=\"suggested_filename.pdf\"";
71 const char kContentDispositionWithoutFilename[] = 72 const char kContentDispositionWithoutFilename[] =
72 "attachment; parameter=parameter_value"; 73 "attachment; parameter=parameter_value";
73 const char kInvalidFilenameUrl[] = "http://www.hostname.com/"; 74 const char kInvalidFilenameUrl[] = "http://www.hostname.com/";
74 const char kValidFilenameUrl[] = "http://www.hostname.com/filename.pdf"; 75 const char kValidFilenameUrl[] = "http://www.hostname.com/filename.pdf";
76 } // namespace
75 77
76 @interface ArrayTabModel : TabModel { 78 @interface ArrayTabModel : TabModel {
77 @private 79 @private
78 base::scoped_nsobject<NSMutableArray> tabsForTesting_; 80 NSMutableArray* _tabsForTesting;
79 } 81 }
80 @end 82 @end
81 83
82 @implementation ArrayTabModel 84 @implementation ArrayTabModel
83 - (id)init { 85 - (instancetype)init {
84 if ((self = [super init])) 86 if ((self = [super init]))
85 tabsForTesting_.reset([[NSMutableArray alloc] initWithCapacity:1]); 87 _tabsForTesting = [[NSMutableArray alloc] initWithCapacity:1];
86 return self; 88 return self;
87 } 89 }
88 90
89 - (void)addTabForTesting:(Tab*)tab { 91 - (void)addTabForTesting:(Tab*)tab {
90 [tabsForTesting_ addObject:tab]; 92 [_tabsForTesting addObject:tab];
91 } 93 }
92 94
93 - (NSUInteger)indexOfTab:(Tab*)tab { 95 - (NSUInteger)indexOfTab:(Tab*)tab {
94 return [tabsForTesting_ indexOfObject:tab]; 96 return [_tabsForTesting indexOfObject:tab];
95 } 97 }
96 98
97 - (NSUInteger)count { 99 - (NSUInteger)count {
98 return [tabsForTesting_ count]; 100 return [_tabsForTesting count];
99 } 101 }
100 102
101 - (void)closeTabAtIndex:(NSUInteger)index { 103 - (void)closeTabAtIndex:(NSUInteger)index {
102 [tabsForTesting_ removeObjectAtIndex:index]; 104 [_tabsForTesting removeObjectAtIndex:index];
103 } 105 }
104 @end 106 @end
105 107
106 @interface ExternalAppLauncherMock : OCMockComplexTypeHelper 108 @interface ExternalAppLauncherMock : OCMockComplexTypeHelper
107 @end 109 @end
108 110
109 @implementation ExternalAppLauncherMock 111 @implementation ExternalAppLauncherMock
110 typedef BOOL (^openURLBlockType)(const GURL&, BOOL); 112 typedef BOOL (^openURLBlockType)(const GURL&, BOOL);
111 113
112 - (BOOL)openURL:(const GURL&)url linkClicked:(BOOL)linkClicked { 114 - (BOOL)openURL:(const GURL&)url linkClicked:(BOOL)linkClicked {
(...skipping 28 matching lines...) Expand all
141 history::QueryResults results_; 143 history::QueryResults results_;
142 base::RunLoop* run_loop_; 144 base::RunLoop* run_loop_;
143 }; 145 };
144 146
145 HistoryQueryResultsObserver::~HistoryQueryResultsObserver() {} 147 HistoryQueryResultsObserver::~HistoryQueryResultsObserver() {}
146 148
147 class FakeChromeBrowserProvider : public ios::TestChromeBrowserProvider { 149 class FakeChromeBrowserProvider : public ios::TestChromeBrowserProvider {
148 public: 150 public:
149 FakeChromeBrowserProvider(id<NativeAppMetadata> metadata) { 151 FakeChromeBrowserProvider(id<NativeAppMetadata> metadata) {
150 FakeNativeAppWhitelistManager* fakeManager = 152 FakeNativeAppWhitelistManager* fakeManager =
151 [[[FakeNativeAppWhitelistManager alloc] init] autorelease]; 153 [[FakeNativeAppWhitelistManager alloc] init];
152 fakeManager.metadata = metadata; 154 fakeManager.metadata = metadata;
153 manager_.reset([fakeManager retain]); 155 manager_.reset(fakeManager);
154 } 156 }
155 ~FakeChromeBrowserProvider() override {} 157 ~FakeChromeBrowserProvider() override {}
156 158
157 id<NativeAppWhitelistManager> GetNativeAppWhitelistManager() const override { 159 id<NativeAppWhitelistManager> GetNativeAppWhitelistManager() const override {
158 return manager_; 160 return manager_;
159 } 161 }
160 162
161 private: 163 private:
162 base::scoped_nsprotocol<id<NativeAppWhitelistManager>> manager_; 164 base::scoped_nsprotocol<id<NativeAppWhitelistManager>> manager_;
163 }; 165 };
(...skipping 16 matching lines...) Expand all
180 setCallbackSchemeForTesting:@"chromium"]; 182 setCallbackSchemeForTesting:@"chromium"];
181 183
182 // Set up the testing profiles. 184 // Set up the testing profiles.
183 TestChromeBrowserState::Builder test_cbs_builder; 185 TestChromeBrowserState::Builder test_cbs_builder;
184 chrome_browser_state_ = test_cbs_builder.Build(); 186 chrome_browser_state_ = test_cbs_builder.Build();
185 chrome_browser_state_->CreateBookmarkModel(false); 187 chrome_browser_state_->CreateBookmarkModel(false);
186 bookmarks::test::WaitForBookmarkModelToLoad( 188 bookmarks::test::WaitForBookmarkModelToLoad(
187 ios::BookmarkModelFactory::GetForBrowserState( 189 ios::BookmarkModelFactory::GetForBrowserState(
188 chrome_browser_state_.get())); 190 chrome_browser_state_.get()));
189 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); 191 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true));
190 history_service_ = ios::HistoryServiceFactory::GetForBrowserState(
191 chrome_browser_state_.get(), ServiceAccessType::EXPLICIT_ACCESS);
192 192
193 ios::ChromeBrowserState* browser_state = chrome_browser_state_.get(); 193 ios::ChromeBrowserState* browser_state = chrome_browser_state_.get();
194 if (UseOffTheRecordBrowserState()) 194 if (UseOffTheRecordBrowserState())
195 browser_state = browser_state->GetOffTheRecordChromeBrowserState(); 195 browser_state = browser_state->GetOffTheRecordChromeBrowserState();
196 196
197 mock_web_controller_ = 197 mock_web_controller_ =
198 [OCMockObject niceMockForClass:[CRWWebController class]]; 198 [OCMockObject niceMockForClass:[CRWWebController class]];
199 web::WebState::CreateParams create_params(browser_state); 199 web::WebState::CreateParams create_params(browser_state);
200 web_state_impl_ = base::MakeUnique<WebStateImpl>(create_params); 200 web_state_impl_ = base::MakeUnique<web::WebStateImpl>(create_params);
201 web_state_impl_->SetWebController(mock_web_controller_); 201 web_state_impl_->SetWebController(mock_web_controller_);
202 web_state_impl_->GetNavigationManagerImpl().InitializeSession(); 202 web_state_impl_->GetNavigationManagerImpl().InitializeSession();
203 web::WebStateImpl* web_state_impl = web_state_impl_.get(); 203 web::WebStateImpl* web_state_impl = web_state_impl_.get();
204 [[[static_cast<OCMockObject*>(mock_web_controller_) stub] 204 [[[static_cast<OCMockObject*>(mock_web_controller_) stub]
205 andReturnValue:OCMOCK_VALUE(web_state_impl)] webStateImpl]; 205 andReturnValue:OCMOCK_VALUE(web_state_impl)] webStateImpl];
206 web_controller_view_.reset([[UIView alloc] init]); 206 web_controller_view_ = [[UIView alloc] init];
207 [[[static_cast<OCMockObject*>(mock_web_controller_) stub] 207 [[[static_cast<OCMockObject*>(mock_web_controller_) stub]
208 andReturn:web_controller_view_.get()] view]; 208 andReturn:web_controller_view_] view];
209 LegacyTabHelper::CreateForWebState(web_state_impl_.get()); 209 LegacyTabHelper::CreateForWebState(web_state_impl_.get());
210 tab_.reset(LegacyTabHelper::GetTabForWebState(web_state_impl_.get())); 210 tab_ = LegacyTabHelper::GetTabForWebState(web_state_impl_.get());
211 web::NavigationManager::WebLoadParams load_params( 211 web::NavigationManager::WebLoadParams load_params(
212 GURL("chrome://version/")); 212 GURL("chrome://version/"));
213 [tab_ navigationManager]->LoadURLWithParams(load_params); 213 [tab_ navigationManager]->LoadURLWithParams(load_params);
214 214
215 // There should be no entries in the history at this point. 215 // There should be no entries in the history at this point.
216 history::QueryResults results; 216 history::QueryResults results;
217 QueryAllHistory(&results); 217 QueryAllHistory(&results);
218 EXPECT_EQ(0UL, results.size()); 218 EXPECT_EQ(0UL, results.size());
219 mock_external_app_launcher_.reset([[ExternalAppLauncherMock alloc] 219 mock_external_app_launcher_ = [[ExternalAppLauncherMock alloc]
220 initWithRepresentedObject: 220 initWithRepresentedObject:
221 [OCMockObject mockForClass:[ExternalAppLauncher class]]]); 221 [OCMockObject mockForClass:[ExternalAppLauncher class]]];
222 [tab_ replaceExternalAppLauncher:mock_external_app_launcher_]; 222 [tab_ replaceExternalAppLauncher:mock_external_app_launcher_];
223 } 223 }
224 224
225 void TearDown() override { 225 void TearDown() override {
226 // Ensure that the Tab is destroyed before the autorelease pool is cleared. 226 // Ensure that the Tab is destroyed before the autorelease pool is cleared.
227 web_state_impl_.reset(); 227 web_state_impl_.reset();
228 BlockCleanupTest::TearDown(); 228 BlockCleanupTest::TearDown();
229 } 229 }
230 230
231 void BrowseTo(const GURL& userUrl, const GURL& redirectUrl, NSString* title) { 231 void BrowseTo(const GURL& userUrl, const GURL& redirectUrl, NSString* title) {
232 DCHECK_EQ(tab_.get().webState, web_state_impl_.get()); 232 DCHECK_EQ(tab_.webState, web_state_impl_.get());
233 233
234 [tab_ webWillAddPendingURL:userUrl transition:ui::PAGE_TRANSITION_TYPED]; 234 [tab_ webWillAddPendingURL:userUrl transition:ui::PAGE_TRANSITION_TYPED];
235 std::unique_ptr<web::NavigationContext> context1 = 235 std::unique_ptr<web::NavigationContext> context1 =
236 web::NavigationContextImpl::CreateNavigationContext( 236 web::NavigationContextImpl::CreateNavigationContext(
237 web_state_impl_.get(), userUrl); 237 web_state_impl_.get(), userUrl);
238 web_state_impl_->OnNavigationStarted(context1.get()); 238 web_state_impl_->OnNavigationStarted(context1.get());
239 [tab_ webWillAddPendingURL:redirectUrl 239 [tab_ webWillAddPendingURL:redirectUrl
240 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT]; 240 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT];
241 241
242 web::Referrer empty_referrer; 242 web::Referrer empty_referrer;
(...skipping 13 matching lines...) Expand all
256 base::string16 new_title = base::SysNSStringToUTF16(title); 256 base::string16 new_title = base::SysNSStringToUTF16(title);
257 [tab_ navigationManager]->GetLastCommittedItem()->SetTitle(new_title); 257 [tab_ navigationManager]->GetLastCommittedItem()->SetTitle(new_title);
258 258
259 web_state_impl_->OnTitleChanged(); 259 web_state_impl_->OnTitleChanged();
260 [[[(id)mock_web_controller_ expect] 260 [[[(id)mock_web_controller_ expect]
261 andReturnValue:OCMOCK_VALUE(kPageLoaded)] loadPhase]; 261 andReturnValue:OCMOCK_VALUE(kPageLoaded)] loadPhase];
262 web_state_impl_->OnPageLoaded(redirectUrl, true); 262 web_state_impl_->OnPageLoaded(redirectUrl, true);
263 } 263 }
264 264
265 void BrowseToNewTab() { 265 void BrowseToNewTab() {
266 DCHECK_EQ(tab_.get().webState, web_state_impl_.get()); 266 DCHECK_EQ(tab_.webState, web_state_impl_.get());
267 const GURL url(kNewTabUrl); 267 const GURL url(kNewTabUrl);
268 // TODO(crbug.com/661992): This will not work with a mock CRWWebController. 268 // TODO(crbug.com/661992): This will not work with a mock CRWWebController.
269 // The only test that uses it is currently disabled. 269 // The only test that uses it is currently disabled.
270 web::NavigationManager::WebLoadParams params(url); 270 web::NavigationManager::WebLoadParams params(url);
271 params.transition_type = ui::PAGE_TRANSITION_TYPED; 271 params.transition_type = ui::PAGE_TRANSITION_TYPED;
272 [tab_ navigationManager]->LoadURLWithParams(params); 272 [tab_ navigationManager]->LoadURLWithParams(params);
273 [[[(id)mock_web_controller_ expect] 273 [[[(id)mock_web_controller_ expect]
274 andReturnValue:OCMOCK_VALUE(kPageLoading)] loadPhase]; 274 andReturnValue:OCMOCK_VALUE(kPageLoading)] loadPhase];
275 [[[(id)mock_web_controller_ expect] 275 [[[(id)mock_web_controller_ expect]
276 andReturnValue:OCMOCK_VALUE(kPageLoaded)] loadPhase]; 276 andReturnValue:OCMOCK_VALUE(kPageLoaded)] loadPhase];
277 web_state_impl_->OnPageLoaded(url, true); 277 web_state_impl_->OnPageLoaded(url, true);
278 web_state_impl_->OnTitleChanged(); 278 web_state_impl_->OnTitleChanged();
279 } 279 }
280 280
281 void QueryAllHistory(history::QueryResults* results) { 281 void QueryAllHistory(history::QueryResults* results) {
282 base::CancelableTaskTracker tracker; 282 base::CancelableTaskTracker tracker;
283 base::RunLoop run_loop; 283 base::RunLoop run_loop;
284 scoped_refptr<HistoryQueryResultsObserver> observer( 284 scoped_refptr<HistoryQueryResultsObserver> observer(
285 new HistoryQueryResultsObserver(&run_loop)); 285 new HistoryQueryResultsObserver(&run_loop));
286 history_service_->QueryHistory( 286 history::HistoryService* history_service =
287 ios::HistoryServiceFactory::GetForBrowserState(
288 chrome_browser_state_.get(), ServiceAccessType::EXPLICIT_ACCESS);
289 history_service->QueryHistory(
287 base::string16(), history::QueryOptions(), 290 base::string16(), history::QueryOptions(),
288 base::Bind(&HistoryQueryResultsObserver::ProcessResults, observer), 291 base::Bind(&HistoryQueryResultsObserver::ProcessResults, observer),
289 &tracker); 292 &tracker);
290 run_loop.Run(); 293 run_loop.Run();
291 results->Swap(observer->results()); 294 results->Swap(observer->results());
292 } 295 }
293 296
294 void CheckHistoryResult(const history::URLResult& historyResult, 297 void CheckHistoryResult(const history::URLResult& historyResult,
295 const GURL& expectedUrl, 298 const GURL& expectedUrl,
296 NSString* expectedTitle) { 299 NSString* expectedTitle) {
(...skipping 25 matching lines...) Expand all
322 } 325 }
323 #endif 326 #endif
324 327
325 virtual bool UseOffTheRecordBrowserState() const { return false; } 328 virtual bool UseOffTheRecordBrowserState() const { return false; }
326 329
327 protected: 330 protected:
328 web::TestWebThreadBundle thread_bundle_; 331 web::TestWebThreadBundle thread_bundle_;
329 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; 332 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_;
330 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 333 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
331 std::unique_ptr<web::WebStateImpl> web_state_impl_; 334 std::unique_ptr<web::WebStateImpl> web_state_impl_;
332 history::HistoryService* history_service_; // weak 335 __weak CRWWebController* mock_web_controller_;
333 CRWWebController* mock_web_controller_; // weak 336 UIView* web_controller_view_;
334 base::scoped_nsobject<UIView> web_controller_view_; 337 ArrayTabModel* tabModel_;
335 base::scoped_nsobject<ArrayTabModel> tabModel_; 338 id mock_external_app_launcher_;
336 base::scoped_nsobject<id> mock_external_app_launcher_; 339 __weak Tab* tab_;
337 base::WeakNSObject<Tab> tab_;
338 }; 340 };
339 341
340 TEST_F(TabTest, AddToHistoryWithRedirect) { 342 TEST_F(TabTest, AddToHistoryWithRedirect) {
341 BrowseTo(GURL(kGoogleUserUrl), GURL(kGoogleRedirectUrl), kGoogleTitle); 343 BrowseTo(GURL(kGoogleUserUrl), GURL(kGoogleRedirectUrl), kGoogleTitle);
342 history::QueryResults results; 344 history::QueryResults results;
343 QueryAllHistory(&results); 345 QueryAllHistory(&results);
344 EXPECT_EQ(1U, results.size()); 346 EXPECT_EQ(1U, results.size());
345 CheckHistoryResult(results[0], GURL(kGoogleRedirectUrl), kGoogleTitle); 347 CheckHistoryResult(results[0], GURL(kGoogleRedirectUrl), kGoogleTitle);
346 CheckCurrentItem(results[0]); 348 CheckCurrentItem(results[0]);
347 } 349 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 TEST_F(TabOpenAppTest, testURL) { 494 TEST_F(TabOpenAppTest, testURL) {
493 // TODO(crbug/711511): Remove this test when Native App Launcher has been 495 // TODO(crbug/711511): Remove this test when Native App Launcher has been
494 // fully deprecated. 496 // fully deprecated.
495 if (!experimental_flags::IsNativeAppLauncherEnabled()) 497 if (!experimental_flags::IsNativeAppLauncherEnabled())
496 return; 498 return;
497 499
498 EXPECT_FALSE([tab_ browserState]->IsOffTheRecord()); 500 EXPECT_FALSE([tab_ browserState]->IsOffTheRecord());
499 501
500 GURL testURL("http://www.youtube.com/"); 502 GURL testURL("http://www.youtube.com/");
501 // Fake metadata object to enable and disable autoopenlinks for testURL. 503 // Fake metadata object to enable and disable autoopenlinks for testURL.
502 base::scoped_nsobject<FakeNativeAppMetadata> metadata( 504 FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
503 [[FakeNativeAppMetadata alloc] init]);
504 IOSChromeScopedTestingChromeBrowserProvider provider( 505 IOSChromeScopedTestingChromeBrowserProvider provider(
505 base::MakeUnique<FakeChromeBrowserProvider>(metadata)); 506 base::MakeUnique<FakeChromeBrowserProvider>(metadata));
506 // Turn auto open on. 507 // Turn auto open on.
507 int expectedCallCount = 1; 508 int expectedCallCount = 1;
508 [metadata setShouldAutoOpenLinks:YES]; 509 [metadata setShouldAutoOpenLinks:YES];
509 TestOpenNativeAppURL(testURL, YES, expectedCallCount, YES); 510 TestOpenNativeAppURL(testURL, YES, expectedCallCount, YES);
510 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO); 511 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO);
511 512
512 // Turn auto open off. 513 // Turn auto open off.
513 expectedCallCount = 0; 514 expectedCallCount = 0;
514 [metadata setShouldAutoOpenLinks:NO]; 515 [metadata setShouldAutoOpenLinks:NO];
515 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO); 516 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO);
516 } 517 }
517 518
518 // TODO(crbug.com/330189): This test fails if Google Maps is installed (usually 519 // TODO(crbug.com/330189): This test fails if Google Maps is installed (usually
519 // on device). 520 // on device).
520 TEST_F(TabOpenAppTest, DISABLED_testResetShouldAutoOpenOnFailure) { 521 TEST_F(TabOpenAppTest, DISABLED_testResetShouldAutoOpenOnFailure) {
521 // TODO(crbug/711511): Remove this test when Native App Launcher has been 522 // TODO(crbug/711511): Remove this test when Native App Launcher has been
522 // fully deprecated. 523 // fully deprecated.
523 if (!experimental_flags::IsNativeAppLauncherEnabled()) 524 if (!experimental_flags::IsNativeAppLauncherEnabled())
524 return; 525 return;
525 526
526 EXPECT_FALSE([tab_ browserState]->IsOffTheRecord()); 527 EXPECT_FALSE([tab_ browserState]->IsOffTheRecord());
527 528
528 // With a regular profile. 529 // With a regular profile.
529 GURL testURL("http://maps.google.com/"); 530 GURL testURL("http://maps.google.com/");
530 // Fake metadata object 531 // Fake metadata object
531 base::scoped_nsobject<FakeNativeAppMetadata> metadata( 532 FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
532 [[FakeNativeAppMetadata alloc] init]);
533 533
534 // Turn auto open on. 534 // Turn auto open on.
535 [metadata setShouldAutoOpenLinks:YES]; 535 [metadata setShouldAutoOpenLinks:YES];
536 int expectedCallCount = 2; 536 int expectedCallCount = 2;
537 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO); 537 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO);
538 EXPECT_FALSE([metadata shouldAutoOpenLinks]); 538 EXPECT_FALSE([metadata shouldAutoOpenLinks]);
539 } 539 }
540 540
541 // Tests the opening of matching native apps with off-the-record browser state. 541 // Tests the opening of matching native apps with off-the-record browser state.
542 TEST_F(TabOpenAppOffTheRecordTest, testDummyURL) { 542 TEST_F(TabOpenAppOffTheRecordTest, testDummyURL) {
(...skipping 12 matching lines...) Expand all
555 // TODO(crbug/711511): Remove this test when Native App Launcher has been 555 // TODO(crbug/711511): Remove this test when Native App Launcher has been
556 // fully deprecated. 556 // fully deprecated.
557 if (!experimental_flags::IsNativeAppLauncherEnabled()) 557 if (!experimental_flags::IsNativeAppLauncherEnabled())
558 return; 558 return;
559 559
560 EXPECT_TRUE([tab_ browserState]->IsOffTheRecord()); 560 EXPECT_TRUE([tab_ browserState]->IsOffTheRecord());
561 561
562 // With a regular chrome browser state. 562 // With a regular chrome browser state.
563 GURL testURL("http://www.youtube.com/"); 563 GURL testURL("http://www.youtube.com/");
564 // Mock metadata object to enable and disable autoopenlinks for testURL. 564 // Mock metadata object to enable and disable autoopenlinks for testURL.
565 base::scoped_nsobject<FakeNativeAppMetadata> metadata( 565 FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
566 [[FakeNativeAppMetadata alloc] init]);
567 IOSChromeScopedTestingChromeBrowserProvider provider( 566 IOSChromeScopedTestingChromeBrowserProvider provider(
568 base::MakeUnique<FakeChromeBrowserProvider>(metadata)); 567 base::MakeUnique<FakeChromeBrowserProvider>(metadata));
569 568
570 // Turn auto open on. 569 // Turn auto open on.
571 [metadata setShouldAutoOpenLinks:YES]; 570 [metadata setShouldAutoOpenLinks:YES];
572 TestOpenNativeAppURL(testURL, NO, 0, NO); 571 TestOpenNativeAppURL(testURL, NO, 0, NO);
573 572
574 // Turn auto open off. 573 // Turn auto open off.
575 [metadata setShouldAutoOpenLinks:NO]; 574 [metadata setShouldAutoOpenLinks:NO];
576 TestOpenNativeAppURL(testURL, NO, 0, NO); 575 TestOpenNativeAppURL(testURL, NO, 0, NO);
577 } 576 }
578 577
579 // TODO(crbug.com/330189): This test fails if Google Maps is installed (usually 578 // TODO(crbug.com/330189): This test fails if Google Maps is installed (usually
580 // on device). 579 // on device).
581 TEST_F(TabOpenAppOffTheRecordTest, DISABLED_testResetShouldAutoOpenOnFailure) { 580 TEST_F(TabOpenAppOffTheRecordTest, DISABLED_testResetShouldAutoOpenOnFailure) {
582 // TODO(crbug/711511): Remove this test when Native App Launcher has been 581 // TODO(crbug/711511): Remove this test when Native App Launcher has been
583 // fully deprecated. 582 // fully deprecated.
584 if (!experimental_flags::IsNativeAppLauncherEnabled()) 583 if (!experimental_flags::IsNativeAppLauncherEnabled())
585 return; 584 return;
586 585
587 EXPECT_TRUE([tab_ browserState]->IsOffTheRecord()); 586 EXPECT_TRUE([tab_ browserState]->IsOffTheRecord());
588 587
589 // With a regular profile. 588 // With a regular profile.
590 GURL testURL("http://maps.google.com/"); 589 GURL testURL("http://maps.google.com/");
591 // Fake metadata object. 590 // Fake metadata object.
592 base::scoped_nsobject<FakeNativeAppMetadata> metadata( 591 FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
593 [[FakeNativeAppMetadata alloc] init]);
594 592
595 // Turn auto open on. 593 // Turn auto open on.
596 [metadata setShouldAutoOpenLinks:YES]; 594 [metadata setShouldAutoOpenLinks:YES];
597 int expectedCallCount = 2; 595 int expectedCallCount = 2;
598 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO); 596 TestOpenNativeAppURL(testURL, NO, expectedCallCount, NO);
599 EXPECT_FALSE([metadata shouldAutoOpenLinks]); 597 EXPECT_FALSE([metadata shouldAutoOpenLinks]);
600 } 598 }
601 599
602 } // namespace 600 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_model_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698