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

Side by Side Diff: ios/chrome/browser/tabs/tab_model_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/BUILD.gn ('k') | ios/chrome/browser/tabs/tab_unittest.mm » ('j') | 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 <objc/runtime.h> 5 #import <objc/runtime.h>
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/mac/scoped_nsautorelease_pool.h"
9 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 9 #include "base/run_loop.h"
11 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h" 12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h"
14 #include "ios/chrome/browser/chrome_url_constants.h" 13 #include "ios/chrome/browser/chrome_url_constants.h"
15 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" 14 #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
16 #include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h" 15 #include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h"
17 #import "ios/chrome/browser/sessions/session_ios.h" 16 #import "ios/chrome/browser/sessions/session_ios.h"
18 #import "ios/chrome/browser/sessions/session_window_ios.h" 17 #import "ios/chrome/browser/sessions/session_window_ios.h"
(...skipping 17 matching lines...) Expand all
36 #include "ios/web/public/test/test_web_thread_bundle.h" 35 #include "ios/web/public/test/test_web_thread_bundle.h"
37 #include "ios/web/public/web_thread.h" 36 #include "ios/web/public/web_thread.h"
38 #import "ios/web/web_state/ui/crw_web_controller.h" 37 #import "ios/web/web_state/ui/crw_web_controller.h"
39 #import "ios/web/web_state/web_state_impl.h" 38 #import "ios/web/web_state/web_state_impl.h"
40 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
41 #include "testing/gtest_mac.h" 40 #include "testing/gtest_mac.h"
42 #include "testing/platform_test.h" 41 #include "testing/platform_test.h"
43 #import "third_party/ocmock/OCMock/OCMock.h" 42 #import "third_party/ocmock/OCMock/OCMock.h"
44 #include "third_party/ocmock/gtest_support.h" 43 #include "third_party/ocmock/gtest_support.h"
45 44
45 #if !defined(__has_feature) || !__has_feature(objc_arc)
46 #error "This file requires ARC support."
47 #endif
48
46 // Defines a TabModelObserver for use in unittests. This class can be used to 49 // Defines a TabModelObserver for use in unittests. This class can be used to
47 // test if an observer method was called or not. 50 // test if an observer method was called or not.
48 @interface TabModelObserverPong : NSObject<TabModelObserver> { 51 @interface TabModelObserverPong : NSObject<TabModelObserver> {
49 // TODO(crbug.com/661989): Add tests for the other observer methods. 52 // TODO(crbug.com/661989): Add tests for the other observer methods.
50 BOOL tabMovedWasCalled_; 53 BOOL tabMovedWasCalled_;
51 } 54 }
52 @property(nonatomic, assign) BOOL tabMovedWasCalled; 55 @property(nonatomic, assign) BOOL tabMovedWasCalled;
53 @end 56 @end
54 57
55 @implementation TabModelObserverPong 58 @implementation TabModelObserverPong
(...skipping 17 matching lines...) Expand all
73 public: 76 public:
74 TabModelTest() 77 TabModelTest()
75 : scoped_browser_state_manager_( 78 : scoped_browser_state_manager_(
76 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())), 79 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())),
77 web_client_(base::MakeUnique<ChromeWebClient>()) { 80 web_client_(base::MakeUnique<ChromeWebClient>()) {
78 DCHECK_CURRENTLY_ON(web::WebThread::UI); 81 DCHECK_CURRENTLY_ON(web::WebThread::UI);
79 82
80 TestChromeBrowserState::Builder test_cbs_builder; 83 TestChromeBrowserState::Builder test_cbs_builder;
81 chrome_browser_state_ = test_cbs_builder.Build(); 84 chrome_browser_state_ = test_cbs_builder.Build();
82 85
83 session_window_.reset([[SessionWindowIOS alloc] init]); 86 session_window_ = [[SessionWindowIOS alloc] init];
84 87
85 // Create tab model with just a dummy session service so the async state 88 // Create tab model with just a dummy session service so the async state
86 // saving doesn't trigger unless actually wanted. 89 // saving doesn't trigger unless actually wanted.
87 SetTabModel( 90 SetTabModel(CreateTabModel([[TestSessionService alloc] init], nil));
88 CreateTabModel([[[TestSessionService alloc] init] autorelease], nil));
89 } 91 }
90 92
91 ~TabModelTest() override { 93 ~TabModelTest() override = default;
92 [tab_model_ browserStateDestroyed]; 94
95 void TearDown() override {
96 SetTabModel(nil);
97 PlatformTest::TearDown();
93 } 98 }
94 99
95 void SetTabModel(base::scoped_nsobject<TabModel> tab_model) { 100 void SetTabModel(TabModel* tab_model) {
96 if (tab_model_) { 101 if (tab_model_) {
97 @autoreleasepool { 102 @autoreleasepool {
98 [tab_model_ browserStateDestroyed]; 103 [tab_model_ browserStateDestroyed];
99 tab_model_.reset(); 104 tab_model_ = nil;
100 } 105 }
101 } 106 }
102 107
103 tab_model_ = tab_model; 108 tab_model_ = tab_model;
104 } 109 }
105 110
106 base::scoped_nsobject<TabModel> CreateTabModel( 111 TabModel* CreateTabModel(SessionServiceIOS* session_service,
107 SessionServiceIOS* session_service, 112 SessionWindowIOS* session_window) {
108 SessionWindowIOS* session_window) { 113 TabModel* tab_model([[TabModel alloc]
109 base::scoped_nsobject<TabModel> tab_model([[TabModel alloc]
110 initWithSessionWindow:session_window 114 initWithSessionWindow:session_window
111 sessionService:session_service 115 sessionService:session_service
112 browserState:chrome_browser_state_.get()]); 116 browserState:chrome_browser_state_.get()]);
113 [tab_model setWebUsageEnabled:NO]; 117 [tab_model setWebUsageEnabled:NO];
114 [tab_model setPrimary:YES]; 118 [tab_model setPrimary:YES];
115 return tab_model; 119 return tab_model;
116 } 120 }
117 121
118 protected: 122 protected:
119 // Creates a session window with entries named "restored window 1", 123 // Creates a session window with entries named "restored window 1",
120 // "restored window 2" and "restored window 3" and the second entry 124 // "restored window 2" and "restored window 3" and the second entry
121 // marked as selected. 125 // marked as selected.
122 base::scoped_nsobject<SessionWindowIOS> CreateSessionWindow() { 126 SessionWindowIOS* CreateSessionWindow() {
123 NSMutableArray<CRWSessionStorage*>* sessions = [NSMutableArray array]; 127 NSMutableArray<CRWSessionStorage*>* sessions = [NSMutableArray array];
124 for (int i = 0; i < 3; i++) { 128 for (int i = 0; i < 3; i++) {
125 CRWSessionStorage* session_storage = 129 CRWSessionStorage* session_storage = [[CRWSessionStorage alloc] init];
126 [[[CRWSessionStorage alloc] init] autorelease];
127 [sessions addObject:session_storage]; 130 [sessions addObject:session_storage];
128 } 131 }
129 return base::scoped_nsobject<SessionWindowIOS>( 132 return base::scoped_nsobject<SessionWindowIOS>(
130 [[SessionWindowIOS alloc] initWithSessions:sessions selectedIndex:1]); 133 [[SessionWindowIOS alloc] initWithSessions:sessions selectedIndex:1]);
131 } 134 }
132 135
133 web::TestWebThreadBundle thread_bundle_; 136 web::TestWebThreadBundle thread_bundle_;
134 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; 137 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_;
135 web::ScopedTestingWebClient web_client_; 138 web::ScopedTestingWebClient web_client_;
136 base::scoped_nsobject<SessionWindowIOS> session_window_; 139 SessionWindowIOS* session_window_;
137 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 140 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
138 base::mac::ScopedNSAutoreleasePool pool_; 141 TabModel* tab_model_;
139 base::scoped_nsobject<TabModel> tab_model_;
140 }; 142 };
141 143
142 TEST_F(TabModelTest, IsEmpty) { 144 TEST_F(TabModelTest, IsEmpty) {
143 EXPECT_EQ([tab_model_ count], 0U); 145 EXPECT_EQ([tab_model_ count], 0U);
144 EXPECT_TRUE([tab_model_ isEmpty]); 146 EXPECT_TRUE([tab_model_ isEmpty]);
145 [tab_model_ insertTabWithURL:GURL(kURL1) 147 [tab_model_ insertTabWithURL:GURL(kURL1)
146 referrer:web::Referrer() 148 referrer:web::Referrer()
147 transition:ui::PAGE_TRANSITION_TYPED 149 transition:ui::PAGE_TRANSITION_TYPED
148 opener:nil 150 opener:nil
149 openedByDOM:NO 151 openedByDOM:NO
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 343
342 TEST_F(TabModelTest, RestoreSessionOnNTPTest) { 344 TEST_F(TabModelTest, RestoreSessionOnNTPTest) {
343 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) 345 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL)
344 referrer:web::Referrer() 346 referrer:web::Referrer()
345 transition:ui::PAGE_TRANSITION_TYPED 347 transition:ui::PAGE_TRANSITION_TYPED
346 opener:nil 348 opener:nil
347 openedByDOM:NO 349 openedByDOM:NO
348 atIndex:0 350 atIndex:0
349 inBackground:NO]; 351 inBackground:NO];
350 352
351 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow()); 353 SessionWindowIOS* window(CreateSessionWindow());
352 [tab_model_ restoreSessionWindow:window.get()]; 354 [tab_model_ restoreSessionWindow:window];
353 355
354 ASSERT_EQ(3U, [tab_model_ count]); 356 ASSERT_EQ(3U, [tab_model_ count]);
355 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]); 357 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]);
356 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]); 358 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]);
357 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); 359 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]);
358 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); 360 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]);
359 } 361 }
360 362
361 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) { 363 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) {
362 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) 364 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL)
363 referrer:web::Referrer() 365 referrer:web::Referrer()
364 transition:ui::PAGE_TRANSITION_TYPED 366 transition:ui::PAGE_TRANSITION_TYPED
365 opener:nil 367 opener:nil
366 openedByDOM:NO 368 openedByDOM:NO
367 atIndex:0 369 atIndex:0
368 inBackground:NO]; 370 inBackground:NO];
369 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) 371 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL)
370 referrer:web::Referrer() 372 referrer:web::Referrer()
371 transition:ui::PAGE_TRANSITION_TYPED 373 transition:ui::PAGE_TRANSITION_TYPED
372 opener:nil 374 opener:nil
373 openedByDOM:NO 375 openedByDOM:NO
374 atIndex:1 376 atIndex:1
375 inBackground:NO]; 377 inBackground:NO];
376 378
377 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow()); 379 SessionWindowIOS* window(CreateSessionWindow());
378 [tab_model_ restoreSessionWindow:window.get()]; 380 [tab_model_ restoreSessionWindow:window];
379 381
380 ASSERT_EQ(5U, [tab_model_ count]); 382 ASSERT_EQ(5U, [tab_model_ count]);
381 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]); 383 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]);
382 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 384 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
383 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); 385 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]);
384 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]); 386 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]);
385 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]); 387 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]);
386 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]); 388 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]);
387 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]); 389 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]);
388 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]); 390 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]);
389 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]); 391 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]);
390 } 392 }
391 393
392 TEST_F(TabModelTest, RestoreSessionOnAnyTest) { 394 TEST_F(TabModelTest, RestoreSessionOnAnyTest) {
393 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1) 395 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
394 referrer:web::Referrer() 396 referrer:web::Referrer()
395 transition:ui::PAGE_TRANSITION_TYPED 397 transition:ui::PAGE_TRANSITION_TYPED
396 opener:nil 398 opener:nil
397 openedByDOM:NO 399 openedByDOM:NO
398 atIndex:0 400 atIndex:0
399 inBackground:NO]; 401 inBackground:NO];
400 402
401 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow()); 403 SessionWindowIOS* window(CreateSessionWindow());
402 [tab_model_ restoreSessionWindow:window.get()]; 404 [tab_model_ restoreSessionWindow:window];
403 405
404 ASSERT_EQ(4U, [tab_model_ count]); 406 ASSERT_EQ(4U, [tab_model_ count]);
405 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]); 407 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]);
406 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); 408 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]);
407 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); 409 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]);
408 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); 410 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]);
409 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]); 411 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]);
410 } 412 }
411 413
412 TEST_F(TabModelTest, CloseAllTabs) { 414 TEST_F(TabModelTest, CloseAllTabs) {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 atIndex:[tab_model_ count] 1020 atIndex:[tab_model_ count]
1019 inBackground:NO]; 1021 inBackground:NO];
1020 1022
1021 // Basic sanity checks before moving on. 1023 // Basic sanity checks before moving on.
1022 ASSERT_EQ(3U, [tab_model_ count]); 1024 ASSERT_EQ(3U, [tab_model_ count]);
1023 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 1025 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
1024 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); 1026 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]);
1025 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); 1027 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]);
1026 1028
1027 // Check that observer methods are called. 1029 // Check that observer methods are called.
1028 base::scoped_nsobject<TabModelObserverPong> tab_model_observer; 1030 TabModelObserverPong* tab_model_observer;
1029 tab_model_observer.reset([[TabModelObserverPong alloc] init]); 1031 tab_model_observer = [[TabModelObserverPong alloc] init];
1030 [tab_model_ addObserver:tab_model_observer.get()]; 1032 [tab_model_ addObserver:tab_model_observer];
1031 1033
1032 // Move a tab from index 1 to index 0 (move tab left by one). 1034 // Move a tab from index 1 to index 0 (move tab left by one).
1033 [tab_model_observer setTabMovedWasCalled:NO]; 1035 [tab_model_observer setTabMovedWasCalled:NO];
1034 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0]; 1036 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0];
1035 ASSERT_EQ(3U, [tab_model_ count]); 1037 ASSERT_EQ(3U, [tab_model_ count]);
1036 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1038 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
1037 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]); 1039 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]);
1038 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); 1040 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]);
1039 EXPECT_TRUE([tab_model_observer tabMovedWasCalled]); 1041 EXPECT_TRUE([tab_model_observer tabMovedWasCalled]);
1040 1042
(...skipping 28 matching lines...) Expand all
1069 [tab_model_observer setTabMovedWasCalled:NO]; 1071 [tab_model_observer setTabMovedWasCalled:NO];
1070 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:2]; 1072 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:2];
1071 ASSERT_EQ(3U, [tab_model_ count]); 1073 ASSERT_EQ(3U, [tab_model_ count]);
1072 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1074 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
1073 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 1075 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
1074 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); 1076 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]);
1075 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]); 1077 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]);
1076 1078
1077 // TabModel asserts that there are no observer when it is deallocated, 1079 // TabModel asserts that there are no observer when it is deallocated,
1078 // so remove the observer before the end of the method. 1080 // so remove the observer before the end of the method.
1079 [tab_model_ removeObserver:tab_model_observer.get()]; 1081 [tab_model_ removeObserver:tab_model_observer];
1080 } 1082 }
1081 1083
1082 TEST_F(TabModelTest, ParentTabModel) { 1084 TEST_F(TabModelTest, ParentTabModel) {
1083 std::unique_ptr<web::WebState> web_state = web::WebState::Create( 1085 std::unique_ptr<web::WebState> web_state = web::WebState::Create(
1084 web::WebState::CreateParams(chrome_browser_state_.get())); 1086 web::WebState::CreateParams(chrome_browser_state_.get()));
1085 AttachTabHelpers(web_state.get()); 1087 AttachTabHelpers(web_state.get());
1086 1088
1087 Tab* tab = LegacyTabHelper::GetTabForWebState(web_state.get()); 1089 Tab* tab = LegacyTabHelper::GetTabForWebState(web_state.get());
1088 EXPECT_NSEQ(nil, [tab parentTabModel]); 1090 EXPECT_NSEQ(nil, [tab parentTabModel]);
1089 1091
1090 [tab_model_ webStateList]->InsertWebState(0, std::move(web_state)); 1092 [tab_model_ webStateList]->InsertWebState(0, std::move(web_state));
1091 EXPECT_NSEQ(tab_model_.get(), [tab parentTabModel]); 1093 EXPECT_NSEQ(tab_model_, [tab parentTabModel]);
1092 } 1094 }
1093 1095
1094 TEST_F(TabModelTest, TabCreatedOnInsertion) { 1096 TEST_F(TabModelTest, TabCreatedOnInsertion) {
1095 std::unique_ptr<web::WebState> web_state = web::WebState::Create( 1097 std::unique_ptr<web::WebState> web_state = web::WebState::Create(
1096 web::WebState::CreateParams(chrome_browser_state_.get())); 1098 web::WebState::CreateParams(chrome_browser_state_.get()));
1097 1099
1098 EXPECT_NSEQ(nil, LegacyTabHelper::GetTabForWebState(web_state.get())); 1100 EXPECT_NSEQ(nil, LegacyTabHelper::GetTabForWebState(web_state.get()));
1099 1101
1100 web::WebState* web_state_ptr = web_state.get(); 1102 web::WebState* web_state_ptr = web_state.get();
1101 [tab_model_ webStateList]->InsertWebState(0, std::move(web_state)); 1103 [tab_model_ webStateList]->InsertWebState(0, std::move(web_state));
1102 EXPECT_NSNE(nil, LegacyTabHelper::GetTabForWebState(web_state_ptr)); 1104 EXPECT_NSNE(nil, LegacyTabHelper::GetTabForWebState(web_state_ptr));
1103 } 1105 }
1104 1106
1105 TEST_F(TabModelTest, PersistSelectionChange) { 1107 TEST_F(TabModelTest, PersistSelectionChange) {
1106 NSString* stashPath = 1108 NSString* stashPath =
1107 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value()); 1109 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value());
1108 1110
1109 // Reset the TabModel with a custom SessionServiceIOS (to control whether 1111 // Reset the TabModel with a custom SessionServiceIOS (to control whether
1110 // data is saved to disk). 1112 // data is saved to disk).
1111 base::scoped_nsobject<TestSessionService> test_session_service( 1113 TestSessionService* test_session_service = [[TestSessionService alloc] init];
1112 [[TestSessionService alloc] init]); 1114 SetTabModel(CreateTabModel(test_session_service, nil));
1113 SetTabModel(CreateTabModel(test_session_service.get(), nil));
1114 1115
1115 [tab_model_ insertTabWithURL:GURL(kURL1) 1116 [tab_model_ insertTabWithURL:GURL(kURL1)
1116 referrer:web::Referrer() 1117 referrer:web::Referrer()
1117 transition:ui::PAGE_TRANSITION_TYPED 1118 transition:ui::PAGE_TRANSITION_TYPED
1118 opener:nil 1119 opener:nil
1119 openedByDOM:NO 1120 openedByDOM:NO
1120 atIndex:[tab_model_ count] 1121 atIndex:[tab_model_ count]
1121 inBackground:NO]; 1122 inBackground:NO];
1122 [tab_model_ insertTabWithURL:GURL(kURL1) 1123 [tab_model_ insertTabWithURL:GURL(kURL1)
1123 referrer:web::Referrer() 1124 referrer:web::Referrer()
(...skipping 26 matching lines...) Expand all
1150 [test_session_service setPerformIO:NO]; 1151 [test_session_service setPerformIO:NO];
1151 1152
1152 NSString* state_path = base::SysUTF8ToNSString( 1153 NSString* state_path = base::SysUTF8ToNSString(
1153 chrome_browser_state_->GetStatePath().AsUTF8Unsafe()); 1154 chrome_browser_state_->GetStatePath().AsUTF8Unsafe());
1154 SessionIOS* session = 1155 SessionIOS* session =
1155 [test_session_service loadSessionFromDirectory:state_path]; 1156 [test_session_service loadSessionFromDirectory:state_path];
1156 ASSERT_EQ(1u, session.sessionWindows.count); 1157 ASSERT_EQ(1u, session.sessionWindows.count);
1157 SessionWindowIOS* session_window = session.sessionWindows[0]; 1158 SessionWindowIOS* session_window = session.sessionWindows[0];
1158 1159
1159 // Create tab model from saved session. 1160 // Create tab model from saved session.
1160 SetTabModel(CreateTabModel(test_session_service.get(), session_window)); 1161 SetTabModel(CreateTabModel(test_session_service, session_window));
1161 1162
1162 ASSERT_EQ(3u, [tab_model_ count]); 1163 ASSERT_EQ(3u, [tab_model_ count]);
1163 1164
1164 EXPECT_EQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]); 1165 EXPECT_EQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]);
1165 EXPECT_EQ(nil, [tab_model_ openerOfTab:[tab_model_ tabAtIndex:1]]); 1166 EXPECT_EQ(nil, [tab_model_ openerOfTab:[tab_model_ tabAtIndex:1]]);
1166 EXPECT_EQ([tab_model_ tabAtIndex:1], 1167 EXPECT_EQ([tab_model_ tabAtIndex:1],
1167 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]); 1168 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]);
1168 EXPECT_EQ([tab_model_ tabAtIndex:2], 1169 EXPECT_EQ([tab_model_ tabAtIndex:2],
1169 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]); 1170 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]);
1170 1171
1171 // Clean up. 1172 // Clean up.
1172 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath 1173 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath
1173 error:nullptr]); 1174 error:nullptr]);
1174 } 1175 }
1175 1176
1176 } // anonymous namespace 1177 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/BUILD.gn ('k') | ios/chrome/browser/tabs/tab_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698