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

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

Issue 2712743008: Remove -insertTabWithWebState:atIndex: from TabModel. (Closed)
Patch Set: Rebase. Created 3 years, 9 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 <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" 8 #include "base/mac/scoped_nsautorelease_pool.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 didMoveTab:(Tab*)tab 73 didMoveTab:(Tab*)tab
74 fromIndex:(NSUInteger)fromIndex 74 fromIndex:(NSUInteger)fromIndex
75 toIndex:(NSUInteger)toIndex { 75 toIndex:(NSUInteger)toIndex {
76 tabMovedWasCalled_ = YES; 76 tabMovedWasCalled_ = YES;
77 } 77 }
78 78
79 @end 79 @end
80 80
81 namespace { 81 namespace {
82 82
83 const GURL kURL("https://www.some.url.com"); 83 const char kURL1[] = "https://www.some.url.com";
84 const web::Referrer kEmptyReferrer; 84 const char kURL2[] = "https://www.some.url2.com";
85 const web::Referrer kReferrer(GURL("https//www.some.referer.com"),
86 web::ReferrerPolicyDefault);
87 const web::Referrer kReferrer2(GURL("https//www.some.referer2.com"),
88 web::ReferrerPolicyDefault);
89 85
90 class TabModelTest : public PlatformTest { 86 class TabModelTest : public PlatformTest {
91 public: 87 public:
92 TabModelTest() 88 TabModelTest()
93 : scoped_browser_state_manager_( 89 : scoped_browser_state_manager_(
94 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())), 90 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())),
95 web_client_(base::MakeUnique<ChromeWebClient>()) { 91 web_client_(base::MakeUnique<ChromeWebClient>()) {
96 DCHECK_CURRENTLY_ON(web::WebThread::UI); 92 DCHECK_CURRENTLY_ON(web::WebThread::UI);
97 93
98 TestChromeBrowserState::Builder test_cbs_builder; 94 TestChromeBrowserState::Builder test_cbs_builder;
99 chrome_browser_state_ = test_cbs_builder.Build(); 95 chrome_browser_state_ = test_cbs_builder.Build();
100 96
101 session_window_.reset([[SessionWindowIOS alloc] init]); 97 session_window_.reset([[SessionWindowIOS alloc] init]);
102 // Create tab model with just a dummy session service so the async state 98 // Create tab model with just a dummy session service so the async state
103 // saving doesn't trigger unless actually wanted. 99 // saving doesn't trigger unless actually wanted.
104 base::scoped_nsobject<TestSessionService> test_service( 100 base::scoped_nsobject<TestSessionService> test_service(
105 [[TestSessionService alloc] init]); 101 [[TestSessionService alloc] init]);
106 tab_model_.reset([[TabModel alloc] 102 tab_model_.reset([[TabModel alloc]
107 initWithSessionWindow:session_window_.get() 103 initWithSessionWindow:session_window_.get()
108 sessionService:test_service 104 sessionService:test_service
109 browserState:chrome_browser_state_.get()]); 105 browserState:chrome_browser_state_.get()]);
110 [tab_model_ setWebUsageEnabled:NO]; 106 [tab_model_ setWebUsageEnabled:NO];
111 [tab_model_ setPrimary:YES]; 107 [tab_model_ setPrimary:YES];
112 tab_model_observer_.reset([[TabModelObserverPong alloc] init]);
113 [tab_model_ addObserver:tab_model_observer_];
114 } 108 }
115 109
116 ~TabModelTest() override { 110 ~TabModelTest() override {
117 [tab_model_ removeObserver:tab_model_observer_];
118 [tab_model_ browserStateDestroyed]; 111 [tab_model_ browserStateDestroyed];
119 } 112 }
120 113
121 protected: 114 protected:
122 std::unique_ptr<WebStateImpl> CreateWebState(NSString* opener, 115 // Creates a session window with entries named "restored window 1",
123 NSInteger index) { 116 // "restored window 2" and "restored window 3" and the second entry
124 auto webState = base::MakeUnique<WebStateImpl>(chrome_browser_state_.get()); 117 // marked as selected.
125 webState->GetNavigationManagerImpl().InitializeSession(NO); 118 base::scoped_nsobject<SessionWindowIOS> CreateSessionWindow() {
126 if ([opener length] != 0) { 119 base::scoped_nsobject<SessionWindowIOS> window(
127 // Duplicate code from Tab initializer. Will be removed once the code 120 [[SessionWindowIOS alloc] init]);
128 // is rewritten to remove the use of internal ios/web/ API (see issue 121 for (int i = 0; i < 3; i++) {
129 // http://crbug.com/620465 for progress).
130 web::SerializableUserDataManager* userDataManager =
131 web::SerializableUserDataManager::FromWebState(webState.get());
132 userDataManager->AddSerializableData(opener, @"OpenerID");
133 userDataManager->AddSerializableData(@(index), @"OpenerNavigationIndex");
134 }
135 return webState;
136 }
137
138 std::unique_ptr<WebStateImpl> CreateWebState() {
139 return CreateWebState(@"", -1);
140 }
141
142 std::unique_ptr<WebStateImpl> CreateChildWebState(Tab* parent) {
143 return CreateWebState(parent.tabId, -1);
144 }
145
146 void RestoreSession(SessionWindowIOS* window) {
147 [tab_model_ restoreSessionWindow:window];
148 }
149
150 // Creates a session window with |entries| entries and a |selectedIndex| of 1.
151 SessionWindowIOS* CreateSessionWindow(int entries) {
152 SessionWindowIOS* window = [[SessionWindowIOS alloc] init];
153 for (int i = 0; i < entries; i++) {
154 CRWSessionStorage* session_storage = 122 CRWSessionStorage* session_storage =
155 [[[CRWSessionStorage alloc] init] autorelease]; 123 [[[CRWSessionStorage alloc] init] autorelease];
156 [window addSerializedSessionStorage:session_storage]; 124 [window addSerializedSessionStorage:session_storage];
157 } 125 }
158 if (entries) 126 [window setSelectedIndex:1];
159 [window setSelectedIndex:1];
160 return window; 127 return window;
161 } 128 }
162 129
163 web::TestWebThreadBundle thread_bundle_; 130 web::TestWebThreadBundle thread_bundle_;
164 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; 131 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_;
165 web::ScopedTestingWebClient web_client_; 132 web::ScopedTestingWebClient web_client_;
166 base::scoped_nsobject<SessionWindowIOS> session_window_; 133 base::scoped_nsobject<SessionWindowIOS> session_window_;
167 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 134 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
168 base::mac::ScopedNSAutoreleasePool pool_; 135 base::mac::ScopedNSAutoreleasePool pool_;
169 base::scoped_nsobject<TabModel> tab_model_; 136 base::scoped_nsobject<TabModel> tab_model_;
170 base::scoped_nsobject<TabModelObserverPong> tab_model_observer_;
171 }; 137 };
172 138
173 TEST_F(TabModelTest, IsEmpty) { 139 TEST_F(TabModelTest, IsEmpty) {
174 EXPECT_EQ([tab_model_ count], 0U); 140 EXPECT_EQ([tab_model_ count], 0U);
175 EXPECT_TRUE([tab_model_ isEmpty]); 141 EXPECT_TRUE([tab_model_ isEmpty]);
176 [tab_model_ insertTabWithURL:kURL 142 [tab_model_ insertTabWithURL:GURL(kURL1)
177 referrer:kReferrer 143 referrer:web::Referrer()
178 transition:ui::PAGE_TRANSITION_TYPED 144 transition:ui::PAGE_TRANSITION_TYPED
179 opener:nil 145 opener:nil
180 openedByDOM:NO 146 openedByDOM:NO
181 atIndex:0 147 atIndex:0
182 inBackground:YES]; 148 inBackground:NO];
183 ASSERT_EQ(1U, [tab_model_ count]); 149 ASSERT_EQ(1U, [tab_model_ count]);
184 EXPECT_FALSE([tab_model_ isEmpty]); 150 EXPECT_FALSE([tab_model_ isEmpty]);
185 } 151 }
186 152
187 TEST_F(TabModelTest, InsertUrlSingle) { 153 TEST_F(TabModelTest, InsertUrlSingle) {
188 Tab* tab = [tab_model_ insertTabWithURL:kURL 154 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
189 referrer:kReferrer 155 referrer:web::Referrer()
190 transition:ui::PAGE_TRANSITION_TYPED 156 transition:ui::PAGE_TRANSITION_TYPED
191 opener:nil 157 opener:nil
192 openedByDOM:NO 158 openedByDOM:NO
193 atIndex:0 159 atIndex:0
194 inBackground:YES]; 160 inBackground:NO];
195 ASSERT_EQ(1U, [tab_model_ count]); 161 ASSERT_EQ(1U, [tab_model_ count]);
196 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); 162 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]);
197 } 163 }
198 164
199 TEST_F(TabModelTest, InsertUrlMultiple) { 165 TEST_F(TabModelTest, InsertUrlMultiple) {
200 Tab* tab0 = [tab_model_ insertTabWithURL:kURL 166 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1)
201 referrer:kReferrer 167 referrer:web::Referrer()
202 transition:ui::PAGE_TRANSITION_TYPED 168 transition:ui::PAGE_TRANSITION_TYPED
203 opener:nil 169 opener:nil
204 openedByDOM:NO 170 openedByDOM:NO
205 atIndex:0 171 atIndex:0
206 inBackground:YES]; 172 inBackground:NO];
207 Tab* tab1 = [tab_model_ insertTabWithURL:kURL 173 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kURL1)
208 referrer:kReferrer 174 referrer:web::Referrer()
209 transition:ui::PAGE_TRANSITION_TYPED 175 transition:ui::PAGE_TRANSITION_TYPED
210 opener:nil 176 opener:nil
211 openedByDOM:NO 177 openedByDOM:NO
212 atIndex:0 178 atIndex:0
213 inBackground:YES]; 179 inBackground:NO];
214 Tab* tab2 = [tab_model_ insertTabWithURL:kURL 180 Tab* tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
215 referrer:kReferrer 181 referrer:web::Referrer()
216 transition:ui::PAGE_TRANSITION_TYPED 182 transition:ui::PAGE_TRANSITION_TYPED
217 opener:nil 183 opener:nil
218 openedByDOM:NO 184 openedByDOM:NO
219 atIndex:1 185 atIndex:1
220 inBackground:YES]; 186 inBackground:NO];
221 187
222 ASSERT_EQ(3U, [tab_model_ count]); 188 ASSERT_EQ(3U, [tab_model_ count]);
223 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 189 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
224 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 190 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
225 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); 191 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]);
226 } 192 }
227 193
228 TEST_F(TabModelTest, AppendUrlSingle) { 194 TEST_F(TabModelTest, AppendUrlSingle) {
229 Tab* tab = [tab_model_ insertTabWithURL:kURL 195 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
230 referrer:kReferrer 196 referrer:web::Referrer()
231 transition:ui::PAGE_TRANSITION_TYPED 197 transition:ui::PAGE_TRANSITION_TYPED
232 opener:nil 198 opener:nil
233 openedByDOM:NO 199 openedByDOM:NO
234 atIndex:[tab_model_ count] 200 atIndex:[tab_model_ count]
235 inBackground:YES]; 201 inBackground:NO];
236 ASSERT_EQ(1U, [tab_model_ count]); 202 ASSERT_EQ(1U, [tab_model_ count]);
237 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); 203 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]);
238 } 204 }
239 205
240 TEST_F(TabModelTest, AppendUrlMultiple) { 206 TEST_F(TabModelTest, AppendUrlMultiple) {
241 Tab* tab0 = [tab_model_ insertTabWithURL:kURL 207 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1)
242 referrer:kReferrer 208 referrer:web::Referrer()
243 transition:ui::PAGE_TRANSITION_TYPED 209 transition:ui::PAGE_TRANSITION_TYPED
244 opener:nil 210 opener:nil
245 openedByDOM:NO 211 openedByDOM:NO
246 atIndex:[tab_model_ count] 212 atIndex:[tab_model_ count]
247 inBackground:YES]; 213 inBackground:NO];
248 Tab* tab1 = [tab_model_ insertTabWithURL:kURL 214 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kURL1)
249 referrer:kReferrer 215 referrer:web::Referrer()
250 transition:ui::PAGE_TRANSITION_TYPED 216 transition:ui::PAGE_TRANSITION_TYPED
251 opener:nil 217 opener:nil
252 openedByDOM:NO 218 openedByDOM:NO
253 atIndex:[tab_model_ count] 219 atIndex:[tab_model_ count]
254 inBackground:YES]; 220 inBackground:NO];
255 Tab* tab2 = [tab_model_ insertTabWithURL:kURL 221 Tab* tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
256 referrer:kReferrer 222 referrer:web::Referrer()
257 transition:ui::PAGE_TRANSITION_TYPED 223 transition:ui::PAGE_TRANSITION_TYPED
258 opener:nil 224 opener:nil
259 openedByDOM:NO 225 openedByDOM:NO
260 atIndex:[tab_model_ count] 226 atIndex:[tab_model_ count]
261 inBackground:YES]; 227 inBackground:NO];
262 228
263 ASSERT_EQ(3U, [tab_model_ count]); 229 ASSERT_EQ(3U, [tab_model_ count]);
264 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 230 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
265 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); 231 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]);
266 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); 232 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]);
267 } 233 }
268 234
269 TEST_F(TabModelTest, CloseTabAtIndexBeginning) { 235 TEST_F(TabModelTest, CloseTabAtIndexBeginning) {
270 [tab_model_ insertTabWithURL:kURL 236 [tab_model_ insertTabWithURL:GURL(kURL1)
271 referrer:kReferrer 237 referrer:web::Referrer()
272 transition:ui::PAGE_TRANSITION_TYPED 238 transition:ui::PAGE_TRANSITION_TYPED
273 opener:nil 239 opener:nil
274 openedByDOM:NO 240 openedByDOM:NO
275 atIndex:[tab_model_ count] 241 atIndex:[tab_model_ count]
276 inBackground:YES]; 242 inBackground:NO];
277 Tab* tab1 = [tab_model_ insertTabWithURL:kURL 243 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kURL1)
278 referrer:kReferrer 244 referrer:web::Referrer()
279 transition:ui::PAGE_TRANSITION_TYPED 245 transition:ui::PAGE_TRANSITION_TYPED
280 opener:nil 246 opener:nil
281 openedByDOM:NO 247 openedByDOM:NO
282 atIndex:[tab_model_ count] 248 atIndex:[tab_model_ count]
283 inBackground:YES]; 249 inBackground:NO];
284 Tab* tab2 = [tab_model_ insertTabWithURL:kURL 250 Tab* tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
285 referrer:kReferrer 251 referrer:web::Referrer()
286 transition:ui::PAGE_TRANSITION_TYPED 252 transition:ui::PAGE_TRANSITION_TYPED
287 opener:nil 253 opener:nil
288 openedByDOM:NO 254 openedByDOM:NO
289 atIndex:[tab_model_ count] 255 atIndex:[tab_model_ count]
290 inBackground:YES]; 256 inBackground:NO];
291 257
292 [tab_model_ closeTabAtIndex:0]; 258 [tab_model_ closeTabAtIndex:0];
293 259
294 ASSERT_EQ(2U, [tab_model_ count]); 260 ASSERT_EQ(2U, [tab_model_ count]);
295 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 261 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
296 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 262 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
297 } 263 }
298 264
299 TEST_F(TabModelTest, CloseTabAtIndexMiddle) { 265 TEST_F(TabModelTest, CloseTabAtIndexMiddle) {
300 Tab* tab0 = [tab_model_ insertTabWithURL:kURL 266 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1)
301 referrer:kReferrer 267 referrer:web::Referrer()
302 transition:ui::PAGE_TRANSITION_TYPED 268 transition:ui::PAGE_TRANSITION_TYPED
303 opener:nil 269 opener:nil
304 openedByDOM:NO 270 openedByDOM:NO
305 atIndex:[tab_model_ count] 271 atIndex:[tab_model_ count]
306 inBackground:YES]; 272 inBackground:NO];
307 [tab_model_ insertTabWithURL:kURL 273 [tab_model_ insertTabWithURL:GURL(kURL1)
308 referrer:kReferrer 274 referrer:web::Referrer()
309 transition:ui::PAGE_TRANSITION_TYPED 275 transition:ui::PAGE_TRANSITION_TYPED
310 opener:nil 276 opener:nil
311 openedByDOM:NO 277 openedByDOM:NO
312 atIndex:[tab_model_ count] 278 atIndex:[tab_model_ count]
313 inBackground:YES]; 279 inBackground:NO];
314 Tab* tab2 = [tab_model_ insertTabWithURL:kURL 280 Tab* tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
315 referrer:kReferrer 281 referrer:web::Referrer()
316 transition:ui::PAGE_TRANSITION_TYPED 282 transition:ui::PAGE_TRANSITION_TYPED
317 opener:nil 283 opener:nil
318 openedByDOM:NO 284 openedByDOM:NO
319 atIndex:[tab_model_ count] 285 atIndex:[tab_model_ count]
320 inBackground:YES]; 286 inBackground:NO];
321 287
322 [tab_model_ closeTabAtIndex:1]; 288 [tab_model_ closeTabAtIndex:1];
323 289
324 ASSERT_EQ(2U, [tab_model_ count]); 290 ASSERT_EQ(2U, [tab_model_ count]);
325 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 291 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
326 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 292 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
327 } 293 }
328 294
329 TEST_F(TabModelTest, CloseTabAtIndexLast) { 295 TEST_F(TabModelTest, CloseTabAtIndexLast) {
330 Tab* tab0 = [tab_model_ insertTabWithURL:kURL 296 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1)
331 referrer:kReferrer 297 referrer:web::Referrer()
332 transition:ui::PAGE_TRANSITION_TYPED 298 transition:ui::PAGE_TRANSITION_TYPED
333 opener:nil 299 opener:nil
334 openedByDOM:NO 300 openedByDOM:NO
335 atIndex:[tab_model_ count] 301 atIndex:[tab_model_ count]
336 inBackground:YES]; 302 inBackground:NO];
337 Tab* tab1 = [tab_model_ insertTabWithURL:kURL 303 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kURL1)
338 referrer:kReferrer 304 referrer:web::Referrer()
339 transition:ui::PAGE_TRANSITION_TYPED 305 transition:ui::PAGE_TRANSITION_TYPED
340 opener:nil 306 opener:nil
341 openedByDOM:NO 307 openedByDOM:NO
342 atIndex:[tab_model_ count] 308 atIndex:[tab_model_ count]
343 inBackground:YES]; 309 inBackground:NO];
344 [tab_model_ insertTabWithURL:kURL 310 [tab_model_ insertTabWithURL:GURL(kURL1)
345 referrer:kReferrer 311 referrer:web::Referrer()
346 transition:ui::PAGE_TRANSITION_TYPED 312 transition:ui::PAGE_TRANSITION_TYPED
347 opener:nil 313 opener:nil
348 openedByDOM:NO 314 openedByDOM:NO
349 atIndex:[tab_model_ count] 315 atIndex:[tab_model_ count]
350 inBackground:YES]; 316 inBackground:NO];
351 317
352 [tab_model_ closeTabAtIndex:2]; 318 [tab_model_ closeTabAtIndex:2];
353 319
354 ASSERT_EQ(2U, [tab_model_ count]); 320 ASSERT_EQ(2U, [tab_model_ count]);
355 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 321 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
356 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); 322 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]);
357 } 323 }
358 324
359 TEST_F(TabModelTest, CloseTabAtIndexOnlyOne) { 325 TEST_F(TabModelTest, CloseTabAtIndexOnlyOne) {
360 [tab_model_ insertTabWithURL:kURL 326 [tab_model_ insertTabWithURL:GURL(kURL1)
361 referrer:kReferrer 327 referrer:web::Referrer()
362 transition:ui::PAGE_TRANSITION_TYPED 328 transition:ui::PAGE_TRANSITION_TYPED
363 opener:nil 329 opener:nil
364 openedByDOM:NO 330 openedByDOM:NO
365 atIndex:[tab_model_ count] 331 atIndex:[tab_model_ count]
366 inBackground:YES]; 332 inBackground:NO];
367 333
368 [tab_model_ closeTabAtIndex:0]; 334 [tab_model_ closeTabAtIndex:0];
369 335
370 EXPECT_EQ(0U, [tab_model_ count]); 336 EXPECT_EQ(0U, [tab_model_ count]);
371 } 337 }
372 338
373 TEST_F(TabModelTest, RestoreSessionOnNTPTest) { 339 TEST_F(TabModelTest, RestoreSessionOnNTPTest) {
374 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) 340 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL)
375 referrer:kEmptyReferrer 341 referrer:web::Referrer()
376 transition:ui::PAGE_TRANSITION_TYPED 342 transition:ui::PAGE_TRANSITION_TYPED
377 opener:nil 343 opener:nil
378 openedByDOM:NO 344 openedByDOM:NO
379 atIndex:0 345 atIndex:0
380 inBackground:YES]; 346 inBackground:NO];
381 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3));
382 347
383 RestoreSession(window.get()); 348 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow());
349 [tab_model_ restoreSessionWindow:window.get()];
350
384 ASSERT_EQ(3U, [tab_model_ count]); 351 ASSERT_EQ(3U, [tab_model_ count]);
385 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]); 352 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]);
386 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]); 353 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]);
387 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); 354 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]);
388 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); 355 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]);
389 } 356 }
390 357
391 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) { 358 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) {
392 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) 359 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL)
393 referrer:kEmptyReferrer 360 referrer:web::Referrer()
394 transition:ui::PAGE_TRANSITION_TYPED 361 transition:ui::PAGE_TRANSITION_TYPED
395 opener:nil 362 opener:nil
396 openedByDOM:NO 363 openedByDOM:NO
397 atIndex:0 364 atIndex:0
398 inBackground:YES]; 365 inBackground:NO];
399 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) 366 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL)
400 referrer:kEmptyReferrer 367 referrer:web::Referrer()
401 transition:ui::PAGE_TRANSITION_TYPED 368 transition:ui::PAGE_TRANSITION_TYPED
402 opener:nil 369 opener:nil
403 openedByDOM:NO 370 openedByDOM:NO
404 atIndex:1 371 atIndex:1
405 inBackground:YES]; 372 inBackground:NO];
406 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3));
407 373
408 RestoreSession(window.get()); 374 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow());
375 [tab_model_ restoreSessionWindow:window.get()];
376
409 ASSERT_EQ(5U, [tab_model_ count]); 377 ASSERT_EQ(5U, [tab_model_ count]);
410 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]); 378 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]);
411 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 379 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
412 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); 380 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]);
413 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]); 381 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]);
414 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]); 382 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]);
415 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]); 383 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]);
416 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]); 384 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]);
417 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]); 385 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]);
418 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]); 386 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]);
419 } 387 }
420 388
421 TEST_F(TabModelTest, RestoreSessionOnAnyTest) { 389 TEST_F(TabModelTest, RestoreSessionOnAnyTest) {
422 Tab* tab = [tab_model_ insertTabWithURL:kURL 390 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
423 referrer:kEmptyReferrer 391 referrer:web::Referrer()
424 transition:ui::PAGE_TRANSITION_TYPED 392 transition:ui::PAGE_TRANSITION_TYPED
425 opener:nil 393 opener:nil
426 openedByDOM:NO 394 openedByDOM:NO
427 atIndex:0 395 atIndex:0
428 inBackground:YES]; 396 inBackground:NO];
429 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3));
430 397
431 RestoreSession(window.get()); 398 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow());
399 [tab_model_ restoreSessionWindow:window.get()];
400
432 ASSERT_EQ(4U, [tab_model_ count]); 401 ASSERT_EQ(4U, [tab_model_ count]);
433 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]); 402 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]);
434 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); 403 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]);
435 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); 404 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]);
436 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); 405 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]);
437 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]); 406 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]);
438 } 407 }
439 408
440 TEST_F(TabModelTest, CloseAllTabs) { 409 TEST_F(TabModelTest, CloseAllTabs) {
441 [tab_model_ insertTabWithURL:kURL 410 [tab_model_ insertTabWithURL:GURL(kURL1)
442 referrer:kReferrer 411 referrer:web::Referrer()
443 transition:ui::PAGE_TRANSITION_TYPED 412 transition:ui::PAGE_TRANSITION_TYPED
444 opener:nil 413 opener:nil
445 openedByDOM:NO 414 openedByDOM:NO
446 atIndex:[tab_model_ count] 415 atIndex:[tab_model_ count]
447 inBackground:YES]; 416 inBackground:NO];
448 [tab_model_ insertTabWithURL:GURL("https://www.some.url2.com") 417 [tab_model_ insertTabWithURL:GURL(kURL2)
449 referrer:kReferrer2 418 referrer:web::Referrer()
450 transition:ui::PAGE_TRANSITION_TYPED 419 transition:ui::PAGE_TRANSITION_TYPED
451 opener:nil 420 opener:nil
452 openedByDOM:NO 421 openedByDOM:NO
453 atIndex:[tab_model_ count] 422 atIndex:[tab_model_ count]
454 inBackground:YES]; 423 inBackground:NO];
455 [tab_model_ insertTabWithURL:kURL 424 [tab_model_ insertTabWithURL:GURL(kURL1)
456 referrer:kReferrer 425 referrer:web::Referrer()
457 transition:ui::PAGE_TRANSITION_TYPED 426 transition:ui::PAGE_TRANSITION_TYPED
458 opener:nil 427 opener:nil
459 openedByDOM:NO 428 openedByDOM:NO
460 atIndex:[tab_model_ count] 429 atIndex:[tab_model_ count]
461 inBackground:YES]; 430 inBackground:NO];
462 431
463 [tab_model_ closeAllTabs]; 432 [tab_model_ closeAllTabs];
464 433
465 EXPECT_EQ(0U, [tab_model_ count]); 434 EXPECT_EQ(0U, [tab_model_ count]);
466 } 435 }
467 436
468 TEST_F(TabModelTest, CloseAllTabsWithNoTabs) { 437 TEST_F(TabModelTest, CloseAllTabsWithNoTabs) {
469 [tab_model_ closeAllTabs]; 438 [tab_model_ closeAllTabs];
470 439
471 EXPECT_EQ(0U, [tab_model_ count]); 440 EXPECT_EQ(0U, [tab_model_ count]);
472 } 441 }
473 442
474 TEST_F(TabModelTest, InsertWithSessionController) { 443 TEST_F(TabModelTest, InsertWithSessionController) {
475 EXPECT_EQ([tab_model_ count], 0U); 444 EXPECT_EQ([tab_model_ count], 0U);
476 EXPECT_TRUE([tab_model_ isEmpty]); 445 EXPECT_TRUE([tab_model_ isEmpty]);
477 446
478 Tab* new_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"opener", -1) 447 Tab* new_tab = [tab_model_ insertTabWithURL:GURL(kURL1)
479 atIndex:0]; 448 referrer:web::Referrer()
449 transition:ui::PAGE_TRANSITION_TYPED
450 opener:nil
451 openedByDOM:NO
452 atIndex:[tab_model_ count]
453 inBackground:NO];
454
480 EXPECT_EQ([tab_model_ count], 1U); 455 EXPECT_EQ([tab_model_ count], 1U);
481 [tab_model_ setCurrentTab:new_tab]; 456 [tab_model_ setCurrentTab:new_tab];
482 Tab* current_tab = [tab_model_ currentTab]; 457 Tab* current_tab = [tab_model_ currentTab];
483 EXPECT_TRUE(current_tab); 458 EXPECT_TRUE(current_tab);
484 } 459 }
485 460
486 TEST_F(TabModelTest, OpenerOfTab) { 461 TEST_F(TabModelTest, OpenerOfTab) {
487 // Start off with a couple tabs. 462 // Start off with a couple tabs.
488 [tab_model_ insertTabWithURL:kURL 463 [tab_model_ insertTabWithURL:GURL(kURL1)
489 referrer:kEmptyReferrer 464 referrer:web::Referrer()
490 transition:ui::PAGE_TRANSITION_TYPED 465 transition:ui::PAGE_TRANSITION_TYPED
491 opener:nil 466 opener:nil
492 openedByDOM:NO 467 openedByDOM:NO
493 atIndex:[tab_model_ count] 468 atIndex:[tab_model_ count]
494 inBackground:YES]; 469 inBackground:NO];
495 [tab_model_ insertTabWithURL:kURL 470 [tab_model_ insertTabWithURL:GURL(kURL1)
496 referrer:kEmptyReferrer 471 referrer:web::Referrer()
497 transition:ui::PAGE_TRANSITION_TYPED 472 transition:ui::PAGE_TRANSITION_TYPED
498 opener:nil 473 opener:nil
499 openedByDOM:NO 474 openedByDOM:NO
500 atIndex:[tab_model_ count] 475 atIndex:[tab_model_ count]
501 inBackground:YES]; 476 inBackground:NO];
502 [tab_model_ insertTabWithURL:kURL 477 [tab_model_ insertTabWithURL:GURL(kURL1)
503 referrer:kEmptyReferrer 478 referrer:web::Referrer()
504 transition:ui::PAGE_TRANSITION_TYPED 479 transition:ui::PAGE_TRANSITION_TYPED
505 opener:nil 480 opener:nil
506 openedByDOM:NO 481 openedByDOM:NO
507 atIndex:[tab_model_ count] 482 atIndex:[tab_model_ count]
508 inBackground:YES]; 483 inBackground:NO];
509 484
510 // Create parent tab. 485 // Create parent tab.
511 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() 486 Tab* parent_tab = [tab_model_ insertTabWithURL:GURL(kURL1)
512 atIndex:[tab_model_ count]]; 487 referrer:web::Referrer()
488 transition:ui::PAGE_TRANSITION_TYPED
489 opener:nil
490 openedByDOM:NO
491 atIndex:[tab_model_ count]
492 inBackground:NO];
493
513 // Create child tab. 494 // Create child tab.
514 Tab* child_tab = 495 Tab* child_tab = [tab_model_ insertTabWithURL:GURL(kURL1)
515 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) 496 referrer:web::Referrer()
516 atIndex:[tab_model_ count]]; 497 transition:ui::PAGE_TRANSITION_TYPED
498 opener:parent_tab
499 openedByDOM:NO
500 atIndex:[tab_model_ count]
501 inBackground:NO];
502
517 // Create another unrelated tab. 503 // Create another unrelated tab.
518 Tab* another_tab = [tab_model_ insertTabWithWebState:CreateWebState() 504 Tab* another_tab = [tab_model_ insertTabWithURL:GURL(kURL1)
519 atIndex:[tab_model_ count]]; 505 referrer:web::Referrer()
506 transition:ui::PAGE_TRANSITION_TYPED
507 opener:nil
508 openedByDOM:NO
509 atIndex:[tab_model_ count]
510 inBackground:NO];
520 511
521 // Create another child of the first tab. 512 // Create another child of the first tab.
522 Tab* child_tab2 = 513 Tab* child_tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
523 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) 514 referrer:web::Referrer()
524 atIndex:[tab_model_ count]]; 515 transition:ui::PAGE_TRANSITION_TYPED
516 opener:parent_tab
517 openedByDOM:NO
518 atIndex:[tab_model_ count]
519 inBackground:NO];
525 520
526 EXPECT_FALSE([tab_model_ openerOfTab:parent_tab]); 521 EXPECT_FALSE([tab_model_ openerOfTab:parent_tab]);
527 EXPECT_FALSE([tab_model_ openerOfTab:another_tab]); 522 EXPECT_FALSE([tab_model_ openerOfTab:another_tab]);
528 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab]); 523 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab]);
529 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab2]); 524 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab2]);
530 } 525 }
531 526
532 TEST_F(TabModelTest, OpenerOfTabEmptyModel) { 527 TEST_F(TabModelTest, OpenerOfTabEmptyModel) {
533 EXPECT_FALSE([tab_model_ openerOfTab:nil]); 528 EXPECT_FALSE([tab_model_ openerOfTab:nil]);
534 } 529 }
535 530
536 TEST_F(TabModelTest, OpenersEmptyModel) { 531 TEST_F(TabModelTest, OpenersEmptyModel) {
537 // Empty model. 532 // Empty model.
538 EXPECT_TRUE([tab_model_ isEmpty]); 533 EXPECT_TRUE([tab_model_ isEmpty]);
539 EXPECT_FALSE([tab_model_ nextTabWithOpener:nil afterTab:nil]); 534 EXPECT_FALSE([tab_model_ nextTabWithOpener:nil afterTab:nil]);
540 EXPECT_FALSE([tab_model_ lastTabWithOpener:nil]); 535 EXPECT_FALSE([tab_model_ lastTabWithOpener:nil]);
541 } 536 }
542 537
543 TEST_F(TabModelTest, OpenersNothingOpenedGeneral) { 538 TEST_F(TabModelTest, OpenersNothingOpenedGeneral) {
544 // Start with a few tabs. 539 // Start with a few tabs.
545 [tab_model_ insertTabWithURL:kURL 540 [tab_model_ insertTabWithURL:GURL(kURL1)
546 referrer:kEmptyReferrer 541 referrer:web::Referrer()
547 transition:ui::PAGE_TRANSITION_TYPED 542 transition:ui::PAGE_TRANSITION_TYPED
548 opener:nil 543 opener:nil
549 openedByDOM:NO 544 openedByDOM:NO
550 atIndex:[tab_model_ count] 545 atIndex:[tab_model_ count]
551 inBackground:YES]; 546 inBackground:NO];
552 [tab_model_ insertTabWithURL:kURL 547 [tab_model_ insertTabWithURL:GURL(kURL1)
553 referrer:kEmptyReferrer 548 referrer:web::Referrer()
554 transition:ui::PAGE_TRANSITION_TYPED 549 transition:ui::PAGE_TRANSITION_TYPED
555 opener:nil 550 opener:nil
556 openedByDOM:NO 551 openedByDOM:NO
557 atIndex:[tab_model_ count] 552 atIndex:[tab_model_ count]
558 inBackground:YES]; 553 inBackground:NO];
559 554
560 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() 555 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
561 atIndex:[tab_model_ count]]; 556 referrer:web::Referrer()
557 transition:ui::PAGE_TRANSITION_TYPED
558 opener:nil
559 openedByDOM:NO
560 atIndex:[tab_model_ count]
561 inBackground:NO];
562 562
563 [tab_model_ insertTabWithURL:kURL 563 [tab_model_ insertTabWithURL:GURL(kURL1)
564 referrer:kEmptyReferrer 564 referrer:web::Referrer()
565 transition:ui::PAGE_TRANSITION_TYPED 565 transition:ui::PAGE_TRANSITION_TYPED
566 opener:nil 566 opener:nil
567 openedByDOM:NO 567 openedByDOM:NO
568 atIndex:[tab_model_ count] 568 atIndex:[tab_model_ count]
569 inBackground:YES]; 569 inBackground:NO];
570 [tab_model_ insertTabWithURL:kURL 570 [tab_model_ insertTabWithURL:GURL(kURL1)
571 referrer:kEmptyReferrer 571 referrer:web::Referrer()
572 transition:ui::PAGE_TRANSITION_TYPED 572 transition:ui::PAGE_TRANSITION_TYPED
573 opener:nil 573 opener:nil
574 openedByDOM:NO 574 openedByDOM:NO
575 atIndex:[tab_model_ count] 575 atIndex:[tab_model_ count]
576 inBackground:YES]; 576 inBackground:NO];
577 577
578 // All should fail since this hasn't opened anything else. 578 // All should fail since this hasn't opened anything else.
579 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); 579 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]);
580 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); 580 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]);
581 581
582 // Add more items to the tab, expect the same results. 582 // Add more items to the tab, expect the same results.
583 [tab_model_ insertTabWithURL:kURL 583 [tab_model_ insertTabWithURL:GURL(kURL1)
584 referrer:kEmptyReferrer 584 referrer:web::Referrer()
585 transition:ui::PAGE_TRANSITION_TYPED 585 transition:ui::PAGE_TRANSITION_TYPED
586 opener:nil 586 opener:nil
587 openedByDOM:NO 587 openedByDOM:NO
588 atIndex:[tab_model_ count] 588 atIndex:[tab_model_ count]
589 inBackground:YES]; 589 inBackground:NO];
590 [tab_model_ insertTabWithURL:kURL 590 [tab_model_ insertTabWithURL:GURL(kURL1)
591 referrer:kEmptyReferrer 591 referrer:web::Referrer()
592 transition:ui::PAGE_TRANSITION_TYPED 592 transition:ui::PAGE_TRANSITION_TYPED
593 opener:nil 593 opener:nil
594 openedByDOM:NO 594 openedByDOM:NO
595 atIndex:[tab_model_ count] 595 atIndex:[tab_model_ count]
596 inBackground:YES]; 596 inBackground:NO];
597
598 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); 597 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]);
599 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); 598 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]);
600 } 599 }
601 600
602 TEST_F(TabModelTest, OpenersNothingOpenedFirst) { 601 TEST_F(TabModelTest, OpenersNothingOpenedFirst) {
603 // Our tab is first. 602 // Our tab is first.
604 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() 603 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
605 atIndex:[tab_model_ count]]; 604 referrer:web::Referrer()
605 transition:ui::PAGE_TRANSITION_TYPED
606 opener:nil
607 openedByDOM:NO
608 atIndex:[tab_model_ count]
609 inBackground:NO];
606 610
607 [tab_model_ insertTabWithURL:kURL 611 [tab_model_ insertTabWithURL:GURL(kURL1)
608 referrer:kEmptyReferrer 612 referrer:web::Referrer()
609 transition:ui::PAGE_TRANSITION_TYPED 613 transition:ui::PAGE_TRANSITION_TYPED
610 opener:nil 614 opener:nil
611 openedByDOM:NO 615 openedByDOM:NO
612 atIndex:[tab_model_ count] 616 atIndex:[tab_model_ count]
613 inBackground:YES]; 617 inBackground:NO];
614 [tab_model_ insertTabWithURL:kURL 618 [tab_model_ insertTabWithURL:GURL(kURL1)
615 referrer:kEmptyReferrer 619 referrer:web::Referrer()
616 transition:ui::PAGE_TRANSITION_TYPED 620 transition:ui::PAGE_TRANSITION_TYPED
617 opener:nil 621 opener:nil
618 openedByDOM:NO 622 openedByDOM:NO
619 atIndex:[tab_model_ count] 623 atIndex:[tab_model_ count]
620 inBackground:YES]; 624 inBackground:NO];
621 625
622 // All should fail since this hasn't opened anything else. 626 // All should fail since this hasn't opened anything else.
623 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); 627 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]);
624 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); 628 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]);
625 } 629 }
626 630
627 TEST_F(TabModelTest, OpenersNothingOpenedLast) { 631 TEST_F(TabModelTest, OpenersNothingOpenedLast) {
628 // Our tab is last. 632 // Our tab is last.
629 [tab_model_ insertTabWithURL:kURL 633 [tab_model_ insertTabWithURL:GURL(kURL1)
630 referrer:kEmptyReferrer 634 referrer:web::Referrer()
631 transition:ui::PAGE_TRANSITION_TYPED 635 transition:ui::PAGE_TRANSITION_TYPED
632 opener:nil 636 opener:nil
633 openedByDOM:NO 637 openedByDOM:NO
634 atIndex:[tab_model_ count] 638 atIndex:[tab_model_ count]
635 inBackground:YES]; 639 inBackground:NO];
636 [tab_model_ insertTabWithURL:kURL 640 [tab_model_ insertTabWithURL:GURL(kURL1)
637 referrer:kEmptyReferrer 641 referrer:web::Referrer()
638 transition:ui::PAGE_TRANSITION_TYPED 642 transition:ui::PAGE_TRANSITION_TYPED
639 opener:nil 643 opener:nil
640 openedByDOM:NO 644 openedByDOM:NO
641 atIndex:[tab_model_ count] 645 atIndex:[tab_model_ count]
642 inBackground:YES]; 646 inBackground:NO];
643 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() 647
644 atIndex:[tab_model_ count]]; 648 Tab* tab = [tab_model_ insertTabWithURL:GURL(kURL1)
649 referrer:web::Referrer()
650 transition:ui::PAGE_TRANSITION_TYPED
651 opener:nil
652 openedByDOM:NO
653 atIndex:[tab_model_ count]
654 inBackground:NO];
645 655
646 // All should fail since this hasn't opened anything else. 656 // All should fail since this hasn't opened anything else.
647 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); 657 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]);
648 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); 658 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]);
649 } 659 }
650 660
651 TEST_F(TabModelTest, OpenersChildTabBeforeOpener) { 661 TEST_F(TabModelTest, OpenersChildTabBeforeOpener) {
652 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() 662 Tab* parent_tab = [tab_model_ insertTabWithURL:GURL(kURL1)
653 atIndex:[tab_model_ count]]; 663 referrer:web::Referrer()
664 transition:ui::PAGE_TRANSITION_TYPED
665 opener:nil
666 openedByDOM:NO
667 atIndex:[tab_model_ count]
668 inBackground:NO];
669
654 // Insert child at start 670 // Insert child at start
655 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) atIndex:0]; 671 [tab_model_ insertTabWithURL:GURL(kURL1)
672 referrer:web::Referrer()
673 transition:ui::PAGE_TRANSITION_TYPED
674 opener:parent_tab
675 openedByDOM:NO
676 atIndex:0
677 inBackground:NO];
656 678
657 // Insert a few more between them. 679 // Insert a few more between them.
658 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; 680 [tab_model_ insertTabWithURL:GURL(kURL1)
659 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; 681 referrer:web::Referrer()
682 transition:ui::PAGE_TRANSITION_TYPED
683 opener:nil
684 openedByDOM:NO
685 atIndex:1
686 inBackground:NO];
687 [tab_model_ insertTabWithURL:GURL(kURL1)
688 referrer:web::Referrer()
689 transition:ui::PAGE_TRANSITION_TYPED
690 opener:nil
691 openedByDOM:NO
692 atIndex:1
693 inBackground:NO];
660 694
661 EXPECT_FALSE([tab_model_ nextTabWithOpener:parent_tab afterTab:nil]); 695 EXPECT_FALSE([tab_model_ nextTabWithOpener:parent_tab afterTab:nil]);
662 EXPECT_FALSE([tab_model_ lastTabWithOpener:parent_tab]); 696 EXPECT_FALSE([tab_model_ lastTabWithOpener:parent_tab]);
663 } 697 }
664 698
665 TEST_F(TabModelTest, OpenersChildTabAfterOpener) { 699 TEST_F(TabModelTest, OpenersChildTabAfterOpener) {
666 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() 700 Tab* parent_tab = [tab_model_ insertTabWithURL:GURL(kURL1)
667 atIndex:[tab_model_ count]]; 701 referrer:web::Referrer()
702 transition:ui::PAGE_TRANSITION_TYPED
703 opener:nil
704 openedByDOM:NO
705 atIndex:[tab_model_ count]
706 inBackground:NO];
668 707
669 [tab_model_ insertTabWithURL:kURL 708 [tab_model_ insertTabWithURL:GURL(kURL1)
670 referrer:kEmptyReferrer 709 referrer:web::Referrer()
671 transition:ui::PAGE_TRANSITION_TYPED 710 transition:ui::PAGE_TRANSITION_TYPED
672 opener:nil 711 opener:nil
673 openedByDOM:NO 712 openedByDOM:NO
674 atIndex:[tab_model_ count] 713 atIndex:[tab_model_ count]
675 inBackground:YES]; 714 inBackground:NO];
676 [tab_model_ insertTabWithURL:kURL 715 [tab_model_ insertTabWithURL:GURL(kURL1)
677 referrer:kEmptyReferrer 716 referrer:web::Referrer()
678 transition:ui::PAGE_TRANSITION_TYPED 717 transition:ui::PAGE_TRANSITION_TYPED
679 opener:nil 718 opener:nil
680 openedByDOM:NO 719 openedByDOM:NO
681 atIndex:[tab_model_ count] 720 atIndex:[tab_model_ count]
682 inBackground:YES]; 721 inBackground:NO];
722
683 // Insert two children at end. 723 // Insert two children at end.
684 Tab* child_tab1 = 724 Tab* child_tab1 = [tab_model_ insertTabWithURL:GURL(kURL1)
685 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) 725 referrer:web::Referrer()
686 atIndex:[tab_model_ count]]; 726 transition:ui::PAGE_TRANSITION_TYPED
687 Tab* child_tab2 = 727 opener:parent_tab
688 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) 728 openedByDOM:NO
689 atIndex:[tab_model_ count]]; 729 atIndex:[tab_model_ count]
730 inBackground:NO];
731 Tab* child_tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
732 referrer:web::Referrer()
733 transition:ui::PAGE_TRANSITION_TYPED
734 opener:parent_tab
735 openedByDOM:NO
736 atIndex:[tab_model_ count]
737 inBackground:NO];
690 738
691 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:nil], child_tab1); 739 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:nil], child_tab1);
692 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:child_tab1], 740 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:child_tab1],
693 child_tab2); 741 child_tab2);
694 EXPECT_EQ([tab_model_ lastTabWithOpener:parent_tab], child_tab2); 742 EXPECT_EQ([tab_model_ lastTabWithOpener:parent_tab], child_tab2);
695 } 743 }
696 744
697 TEST_F(TabModelTest, AddWithOrderController) { 745 TEST_F(TabModelTest, AddWithOrderController) {
698 // Create a few tabs with the controller at the front. 746 // Create a few tabs with the controller at the front.
699 Tab* parent = [tab_model_ insertTabWithURL:kURL 747 Tab* parent = [tab_model_ insertTabWithURL:GURL(kURL1)
700 referrer:kEmptyReferrer 748 referrer:web::Referrer()
701 transition:ui::PAGE_TRANSITION_TYPED 749 transition:ui::PAGE_TRANSITION_TYPED
702 opener:nil 750 opener:nil
703 openedByDOM:NO 751 openedByDOM:NO
704 atIndex:[tab_model_ count] 752 atIndex:[tab_model_ count]
705 inBackground:YES]; 753 inBackground:NO];
706 [tab_model_ insertTabWithURL:kURL 754 [tab_model_ insertTabWithURL:GURL(kURL1)
707 referrer:kEmptyReferrer 755 referrer:web::Referrer()
708 transition:ui::PAGE_TRANSITION_TYPED 756 transition:ui::PAGE_TRANSITION_TYPED
709 opener:nil 757 opener:nil
710 openedByDOM:NO 758 openedByDOM:NO
711 atIndex:[tab_model_ count] 759 atIndex:[tab_model_ count]
712 inBackground:YES]; 760 inBackground:NO];
713 [tab_model_ insertTabWithURL:kURL 761 [tab_model_ insertTabWithURL:GURL(kURL1)
714 referrer:kEmptyReferrer 762 referrer:web::Referrer()
715 transition:ui::PAGE_TRANSITION_TYPED 763 transition:ui::PAGE_TRANSITION_TYPED
716 opener:nil 764 opener:nil
717 openedByDOM:NO 765 openedByDOM:NO
718 atIndex:[tab_model_ count] 766 atIndex:[tab_model_ count]
719 inBackground:YES]; 767 inBackground:NO];
720 768
721 // Add a new tab, it should be added behind the parent. 769 // Add a new tab, it should be added behind the parent.
722 Tab* child = 770 Tab* child =
723 [tab_model_ insertTabWithURL:kURL 771 [tab_model_ insertTabWithURL:GURL(kURL1)
724 referrer:kEmptyReferrer 772 referrer:web::Referrer()
725 transition:ui::PAGE_TRANSITION_LINK 773 transition:ui::PAGE_TRANSITION_LINK
726 opener:parent 774 opener:parent
727 openedByDOM:NO 775 openedByDOM:NO
728 atIndex:TabModelConstants::kTabPositionAutomatically 776 atIndex:TabModelConstants::kTabPositionAutomatically
729 inBackground:NO]; 777 inBackground:NO];
730 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); 778 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U);
731 EXPECT_EQ([tab_model_ indexOfTab:child], 1U); 779 EXPECT_EQ([tab_model_ indexOfTab:child], 1U);
732 780
733 // Add another new tab without a parent, should go at the end. 781 // Add another new tab without a parent, should go at the end.
734 Tab* tab = 782 Tab* tab =
735 [tab_model_ insertTabWithURL:kURL 783 [tab_model_ insertTabWithURL:GURL(kURL1)
736 referrer:kEmptyReferrer 784 referrer:web::Referrer()
737 transition:ui::PAGE_TRANSITION_LINK 785 transition:ui::PAGE_TRANSITION_LINK
738 opener:nil 786 opener:nil
739 openedByDOM:NO 787 openedByDOM:NO
740 atIndex:TabModelConstants::kTabPositionAutomatically 788 atIndex:TabModelConstants::kTabPositionAutomatically
741 inBackground:NO]; 789 inBackground:NO];
742 EXPECT_EQ([tab_model_ indexOfTab:tab], [tab_model_ count] - 1); 790 EXPECT_EQ([tab_model_ indexOfTab:tab], [tab_model_ count] - 1);
743 791
744 // Same for a tab that's not opened via a LINK transition. 792 // Same for a tab that's not opened via a LINK transition.
745 Tab* tab2 = [tab_model_ insertTabWithURL:kURL 793 Tab* tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
746 referrer:kEmptyReferrer 794 referrer:web::Referrer()
747 transition:ui::PAGE_TRANSITION_TYPED 795 transition:ui::PAGE_TRANSITION_TYPED
748 opener:nil 796 opener:nil
749 openedByDOM:NO 797 openedByDOM:NO
750 atIndex:[tab_model_ count] 798 atIndex:[tab_model_ count]
751 inBackground:NO]; 799 inBackground:NO];
752 EXPECT_EQ([tab_model_ indexOfTab:tab2], [tab_model_ count] - 1); 800 EXPECT_EQ([tab_model_ indexOfTab:tab2], [tab_model_ count] - 1);
753 801
754 // Add a tab in the background. It should appear behind the opening tab. 802 // Add a tab in the background. It should appear behind the opening tab.
755 Tab* tab3 = 803 Tab* tab3 =
756 [tab_model_ insertTabWithURL:kURL 804 [tab_model_ insertTabWithURL:GURL(kURL1)
757 referrer:kEmptyReferrer 805 referrer:web::Referrer()
758 transition:ui::PAGE_TRANSITION_LINK 806 transition:ui::PAGE_TRANSITION_LINK
759 opener:tab 807 opener:tab
760 openedByDOM:NO 808 openedByDOM:NO
761 atIndex:TabModelConstants::kTabPositionAutomatically 809 atIndex:TabModelConstants::kTabPositionAutomatically
762 inBackground:YES]; 810 inBackground:NO];
763 EXPECT_EQ([tab_model_ indexOfTab:tab3], [tab_model_ indexOfTab:tab] + 1); 811 EXPECT_EQ([tab_model_ indexOfTab:tab3], [tab_model_ indexOfTab:tab] + 1);
764 812
765 // Add another background tab behind the one we just opened. 813 // Add another background tab behind the one we just opened.
766 Tab* tab4 = 814 Tab* tab4 =
767 [tab_model_ insertTabWithURL:kURL 815 [tab_model_ insertTabWithURL:GURL(kURL1)
768 referrer:kEmptyReferrer 816 referrer:web::Referrer()
769 transition:ui::PAGE_TRANSITION_LINK 817 transition:ui::PAGE_TRANSITION_LINK
770 opener:tab3 818 opener:tab3
771 openedByDOM:NO 819 openedByDOM:NO
772 atIndex:TabModelConstants::kTabPositionAutomatically 820 atIndex:TabModelConstants::kTabPositionAutomatically
773 inBackground:YES]; 821 inBackground:NO];
774 EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1); 822 EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1);
775 } 823 }
776 824
777 TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) { 825 TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) {
778 // Create a few tabs with the controller at the front. 826 // Create a few tabs with the controller at the front.
779 Tab* parent = [tab_model_ insertTabWithURL:kURL 827 Tab* parent = [tab_model_ insertTabWithURL:GURL(kURL1)
780 referrer:kEmptyReferrer 828 referrer:web::Referrer()
781 transition:ui::PAGE_TRANSITION_TYPED 829 transition:ui::PAGE_TRANSITION_TYPED
782 opener:nil 830 opener:nil
783 openedByDOM:NO 831 openedByDOM:NO
784 atIndex:[tab_model_ count] 832 atIndex:[tab_model_ count]
785 inBackground:YES]; 833 inBackground:NO];
786 // Force the history to update, as it is used to determine grouping. 834 // Force the history to update, as it is used to determine grouping.
787 ASSERT_TRUE([parent navigationManagerImpl]); 835 ASSERT_TRUE([parent navigationManagerImpl]);
788 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; 836 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem];
789 [tab_model_ insertTabWithURL:kURL 837 [tab_model_ insertTabWithURL:GURL(kURL1)
790 referrer:kEmptyReferrer 838 referrer:web::Referrer()
791 transition:ui::PAGE_TRANSITION_TYPED 839 transition:ui::PAGE_TRANSITION_TYPED
792 opener:nil 840 opener:nil
793 openedByDOM:NO 841 openedByDOM:NO
794 atIndex:[tab_model_ count] 842 atIndex:[tab_model_ count]
795 inBackground:YES]; 843 inBackground:NO];
796 [tab_model_ insertTabWithURL:kURL 844 [tab_model_ insertTabWithURL:GURL(kURL1)
797 referrer:kEmptyReferrer 845 referrer:web::Referrer()
798 transition:ui::PAGE_TRANSITION_TYPED 846 transition:ui::PAGE_TRANSITION_TYPED
799 opener:nil 847 opener:nil
800 openedByDOM:NO 848 openedByDOM:NO
801 atIndex:[tab_model_ count] 849 atIndex:[tab_model_ count]
802 inBackground:YES]; 850 inBackground:NO];
803 851
804 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); 852 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true));
805 853
806 // Add a new tab, it should be added behind the parent. 854 // Add a new tab, it should be added behind the parent.
807 Tab* child1 = 855 Tab* child1 =
808 [tab_model_ insertTabWithURL:kURL 856 [tab_model_ insertTabWithURL:GURL(kURL1)
809 referrer:kEmptyReferrer 857 referrer:web::Referrer()
810 transition:ui::PAGE_TRANSITION_LINK 858 transition:ui::PAGE_TRANSITION_LINK
811 opener:parent 859 opener:parent
812 openedByDOM:NO 860 openedByDOM:NO
813 atIndex:TabModelConstants::kTabPositionAutomatically 861 atIndex:TabModelConstants::kTabPositionAutomatically
814 inBackground:NO]; 862 inBackground:NO];
815 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); 863 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U);
816 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U); 864 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U);
817 865
818 // Add a second child tab in the background. It should be added behind the 866 // Add a second child tab in the background. It should be added behind the
819 // first child. 867 // first child.
820 Tab* child2 = 868 Tab* child2 =
821 [tab_model_ insertTabWithURL:kURL 869 [tab_model_ insertTabWithURL:GURL(kURL1)
822 referrer:kEmptyReferrer 870 referrer:web::Referrer()
823 transition:ui::PAGE_TRANSITION_LINK 871 transition:ui::PAGE_TRANSITION_LINK
824 opener:parent 872 opener:parent
825 openedByDOM:NO 873 openedByDOM:NO
826 atIndex:TabModelConstants::kTabPositionAutomatically 874 atIndex:TabModelConstants::kTabPositionAutomatically
827 inBackground:YES]; 875 inBackground:NO];
828 EXPECT_EQ([tab_model_ indexOfTab:child2], 2U); 876 EXPECT_EQ([tab_model_ indexOfTab:child2], 2U);
829 877
830 // Navigate the parent tab to a new URL. It should not change any ordering. 878 // Navigate the parent tab to a new URL. It should not change any ordering.
831 web::NavigationManager::WebLoadParams parent_params( 879 web::NavigationManager::WebLoadParams parent_params(
832 GURL("http://www.espn.com")); 880 GURL("http://www.espn.com"));
833 parent_params.transition_type = ui::PAGE_TRANSITION_TYPED; 881 parent_params.transition_type = ui::PAGE_TRANSITION_TYPED;
834 [[parent webController] loadWithParams:parent_params]; 882 [[parent webController] loadWithParams:parent_params];
835 ASSERT_TRUE([parent navigationManagerImpl]); 883 ASSERT_TRUE([parent navigationManagerImpl]);
836 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; 884 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem];
837 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); 885 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U);
838 886
839 // Add a new tab. It should be added behind the parent. It should not be added 887 // Add a new tab. It should be added behind the parent. It should not be added
840 // after the previous two children. 888 // after the previous two children.
841 Tab* child3 = 889 Tab* child3 =
842 [tab_model_ insertTabWithURL:kURL 890 [tab_model_ insertTabWithURL:GURL(kURL1)
843 referrer:kEmptyReferrer 891 referrer:web::Referrer()
844 transition:ui::PAGE_TRANSITION_LINK 892 transition:ui::PAGE_TRANSITION_LINK
845 opener:parent 893 opener:parent
846 openedByDOM:NO 894 openedByDOM:NO
847 atIndex:TabModelConstants::kTabPositionAutomatically 895 atIndex:TabModelConstants::kTabPositionAutomatically
848 inBackground:NO]; 896 inBackground:NO];
849 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); 897 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U);
850 898
851 // Add a fourt child tab in the background. It should be added behind the 899 // Add a fourt child tab in the background. It should be added behind the
852 // third child. 900 // third child.
853 Tab* child4 = 901 Tab* child4 =
854 [tab_model_ insertTabWithURL:kURL 902 [tab_model_ insertTabWithURL:GURL(kURL1)
855 referrer:kEmptyReferrer 903 referrer:web::Referrer()
856 transition:ui::PAGE_TRANSITION_LINK 904 transition:ui::PAGE_TRANSITION_LINK
857 opener:parent 905 opener:parent
858 openedByDOM:NO 906 openedByDOM:NO
859 atIndex:TabModelConstants::kTabPositionAutomatically 907 atIndex:TabModelConstants::kTabPositionAutomatically
860 inBackground:YES]; 908 inBackground:NO];
861 EXPECT_EQ([tab_model_ indexOfTab:child4], 2U); 909 EXPECT_EQ([tab_model_ indexOfTab:child4], 2U);
862 910
863 // The first two children should have been moved to the right. 911 // The first two children should have been moved to the right.
864 EXPECT_EQ([tab_model_ indexOfTab:child1], 3U); 912 EXPECT_EQ([tab_model_ indexOfTab:child1], 3U);
865 EXPECT_EQ([tab_model_ indexOfTab:child2], 4U); 913 EXPECT_EQ([tab_model_ indexOfTab:child2], 4U);
866 914
867 // Now add a non-owned tab and make sure it is added at the end. 915 // Now add a non-owned tab and make sure it is added at the end.
868 Tab* nonChild = [tab_model_ insertTabWithURL:kURL 916 Tab* nonChild = [tab_model_ insertTabWithURL:GURL(kURL1)
869 referrer:kEmptyReferrer 917 referrer:web::Referrer()
870 transition:ui::PAGE_TRANSITION_TYPED 918 transition:ui::PAGE_TRANSITION_TYPED
871 opener:nil 919 opener:nil
872 openedByDOM:NO 920 openedByDOM:NO
873 atIndex:[tab_model_ count] 921 atIndex:[tab_model_ count]
874 inBackground:YES]; 922 inBackground:NO];
875 EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1); 923 EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1);
876 } 924 }
877 925
878 TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) { 926 TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) {
879 // Create a few tabs with the controller at the front. 927 // Create a few tabs with the controller at the front.
880 Tab* parent = [tab_model_ insertTabWithURL:kURL 928 Tab* parent = [tab_model_ insertTabWithURL:GURL(kURL1)
881 referrer:kEmptyReferrer 929 referrer:web::Referrer()
882 transition:ui::PAGE_TRANSITION_TYPED 930 transition:ui::PAGE_TRANSITION_TYPED
883 opener:nil 931 opener:nil
884 openedByDOM:NO 932 openedByDOM:NO
885 atIndex:[tab_model_ count] 933 atIndex:[tab_model_ count]
886 inBackground:YES]; 934 inBackground:NO];
887 // Force the history to update, as it is used to determine grouping. 935 // Force the history to update, as it is used to determine grouping.
888 ASSERT_TRUE([parent navigationManagerImpl]); 936 ASSERT_TRUE([parent navigationManagerImpl]);
889 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; 937 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem];
890 [tab_model_ insertTabWithURL:kURL 938 [tab_model_ insertTabWithURL:GURL(kURL1)
891 referrer:kEmptyReferrer 939 referrer:web::Referrer()
892 transition:ui::PAGE_TRANSITION_TYPED 940 transition:ui::PAGE_TRANSITION_TYPED
893 opener:nil 941 opener:nil
894 openedByDOM:NO 942 openedByDOM:NO
895 atIndex:[tab_model_ count] 943 atIndex:[tab_model_ count]
896 inBackground:YES]; 944 inBackground:NO];
897 [tab_model_ insertTabWithURL:kURL 945 [tab_model_ insertTabWithURL:GURL(kURL1)
898 referrer:kEmptyReferrer 946 referrer:web::Referrer()
899 transition:ui::PAGE_TRANSITION_TYPED 947 transition:ui::PAGE_TRANSITION_TYPED
900 opener:nil 948 opener:nil
901 openedByDOM:NO 949 openedByDOM:NO
902 atIndex:[tab_model_ count] 950 atIndex:[tab_model_ count]
903 inBackground:YES]; 951 inBackground:NO];
904 952
905 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); 953 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true));
906 954
907 // Add a new tab, it should be added before the parent since the index 955 // Add a new tab, it should be added before the parent since the index
908 // parameter has been specified with a valid value. 956 // parameter has been specified with a valid value.
909 Tab* child1 = [tab_model_ insertTabWithURL:kURL 957 Tab* child1 = [tab_model_ insertTabWithURL:GURL(kURL1)
910 referrer:kEmptyReferrer 958 referrer:web::Referrer()
911 transition:ui::PAGE_TRANSITION_LINK 959 transition:ui::PAGE_TRANSITION_LINK
912 opener:parent 960 opener:parent
913 openedByDOM:NO 961 openedByDOM:NO
914 atIndex:0 962 atIndex:0
915 inBackground:NO]; 963 inBackground:NO];
916 EXPECT_EQ([tab_model_ indexOfTab:parent], 1U); 964 EXPECT_EQ([tab_model_ indexOfTab:parent], 1U);
917 EXPECT_EQ([tab_model_ indexOfTab:child1], 0U); 965 EXPECT_EQ([tab_model_ indexOfTab:child1], 0U);
918 966
919 // Add a new tab, it should be added at the beginning of the stack because 967 // Add a new tab, it should be added at the beginning of the stack because
920 // the index parameter has been specified with a valid value. 968 // the index parameter has been specified with a valid value.
921 Tab* child2 = [tab_model_ insertTabWithURL:kURL 969 Tab* child2 = [tab_model_ insertTabWithURL:GURL(kURL1)
922 referrer:kEmptyReferrer 970 referrer:web::Referrer()
923 transition:ui::PAGE_TRANSITION_LINK 971 transition:ui::PAGE_TRANSITION_LINK
924 opener:parent 972 opener:parent
925 openedByDOM:NO 973 openedByDOM:NO
926 atIndex:0 974 atIndex:0
927 inBackground:NO]; 975 inBackground:NO];
928 EXPECT_EQ([tab_model_ indexOfTab:parent], 2U); 976 EXPECT_EQ([tab_model_ indexOfTab:parent], 2U);
929 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U); 977 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U);
930 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); 978 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U);
931 979
932 // Add a new tab, it should be added at position 1 because the index parameter 980 // Add a new tab, it should be added at position 1 because the index parameter
933 // has been specified with a valid value. 981 // has been specified with a valid value.
934 Tab* child3 = [tab_model_ insertTabWithURL:kURL 982 Tab* child3 = [tab_model_ insertTabWithURL:GURL(kURL1)
935 referrer:kEmptyReferrer 983 referrer:web::Referrer()
936 transition:ui::PAGE_TRANSITION_LINK 984 transition:ui::PAGE_TRANSITION_LINK
937 opener:parent 985 opener:parent
938 openedByDOM:NO 986 openedByDOM:NO
939 atIndex:1 987 atIndex:1
940 inBackground:NO]; 988 inBackground:NO];
941 EXPECT_EQ([tab_model_ indexOfTab:parent], 3U); 989 EXPECT_EQ([tab_model_ indexOfTab:parent], 3U);
942 EXPECT_EQ([tab_model_ indexOfTab:child1], 2U); 990 EXPECT_EQ([tab_model_ indexOfTab:child1], 2U);
943 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); 991 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U);
944 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); 992 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U);
945 } 993 }
946 994
947 TEST_F(TabModelTest, MoveTabs) { 995 TEST_F(TabModelTest, MoveTabs) {
948 Tab* tab0 = [tab_model_ insertTabWithURL:kURL 996 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kURL1)
949 referrer:kReferrer 997 referrer:web::Referrer()
950 transition:ui::PAGE_TRANSITION_TYPED 998 transition:ui::PAGE_TRANSITION_TYPED
951 opener:nil 999 opener:nil
952 openedByDOM:NO 1000 openedByDOM:NO
953 atIndex:[tab_model_ count] 1001 atIndex:[tab_model_ count]
954 inBackground:YES]; 1002 inBackground:NO];
955 Tab* tab1 = [tab_model_ insertTabWithURL:kURL 1003 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kURL1)
956 referrer:kReferrer 1004 referrer:web::Referrer()
957 transition:ui::PAGE_TRANSITION_TYPED 1005 transition:ui::PAGE_TRANSITION_TYPED
958 opener:nil 1006 opener:nil
959 openedByDOM:NO 1007 openedByDOM:NO
960 atIndex:[tab_model_ count] 1008 atIndex:[tab_model_ count]
961 inBackground:YES]; 1009 inBackground:NO];
962 Tab* tab2 = [tab_model_ insertTabWithURL:kURL 1010 Tab* tab2 = [tab_model_ insertTabWithURL:GURL(kURL1)
963 referrer:kReferrer 1011 referrer:web::Referrer()
964 transition:ui::PAGE_TRANSITION_TYPED 1012 transition:ui::PAGE_TRANSITION_TYPED
965 opener:nil 1013 opener:nil
966 openedByDOM:NO 1014 openedByDOM:NO
967 atIndex:[tab_model_ count] 1015 atIndex:[tab_model_ count]
968 inBackground:YES]; 1016 inBackground:NO];
969 1017
970 // Basic sanity checks before moving on. 1018 // Basic sanity checks before moving on.
971 ASSERT_EQ(3U, [tab_model_ count]); 1019 ASSERT_EQ(3U, [tab_model_ count]);
972 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); 1020 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]);
973 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); 1021 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]);
974 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); 1022 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]);
975 1023
1024 // Check that observer methods are called.
1025 base::scoped_nsobject<TabModelObserverPong> tab_model_observer;
1026 tab_model_observer.reset([[TabModelObserverPong alloc] init]);
1027 [tab_model_ addObserver:tab_model_observer.get()];
1028
976 // Move a tab from index 1 to index 0 (move tab left by one). 1029 // Move a tab from index 1 to index 0 (move tab left by one).
977 [tab_model_observer_ setTabMovedWasCalled:NO]; 1030 [tab_model_observer setTabMovedWasCalled:NO];
978 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0]; 1031 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0];
979 ASSERT_EQ(3U, [tab_model_ count]); 1032 ASSERT_EQ(3U, [tab_model_ count]);
980 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1033 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
981 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]); 1034 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]);
982 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); 1035 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]);
983 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); 1036 EXPECT_TRUE([tab_model_observer tabMovedWasCalled]);
984 1037
985 // Move a tab from index 1 to index 2 (move tab right by one). 1038 // Move a tab from index 1 to index 2 (move tab right by one).
986 [tab_model_observer_ setTabMovedWasCalled:NO]; 1039 [tab_model_observer setTabMovedWasCalled:NO];
987 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:2]; 1040 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:2];
988 ASSERT_EQ(3U, [tab_model_ count]); 1041 ASSERT_EQ(3U, [tab_model_ count]);
989 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1042 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
990 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 1043 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
991 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); 1044 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]);
992 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); 1045 EXPECT_TRUE([tab_model_observer tabMovedWasCalled]);
993 1046
994 // Move a tab from index 0 to index 2 (move tab right by more than one). 1047 // Move a tab from index 0 to index 2 (move tab right by more than one).
995 [tab_model_observer_ setTabMovedWasCalled:NO]; 1048 [tab_model_observer setTabMovedWasCalled:NO];
996 [tab_model_ moveTab:[tab_model_ tabAtIndex:0] toIndex:2]; 1049 [tab_model_ moveTab:[tab_model_ tabAtIndex:0] toIndex:2];
997 ASSERT_EQ(3U, [tab_model_ count]); 1050 ASSERT_EQ(3U, [tab_model_ count]);
998 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:0]); 1051 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:0]);
999 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]); 1052 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]);
1000 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:2]); 1053 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:2]);
1001 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); 1054 EXPECT_TRUE([tab_model_observer tabMovedWasCalled]);
1002 1055
1003 // Move a tab from index 2 to index 0 (move tab left by more than one). 1056 // Move a tab from index 2 to index 0 (move tab left by more than one).
1004 [tab_model_observer_ setTabMovedWasCalled:NO]; 1057 [tab_model_observer setTabMovedWasCalled:NO];
1005 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:0]; 1058 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:0];
1006 ASSERT_EQ(3U, [tab_model_ count]); 1059 ASSERT_EQ(3U, [tab_model_ count]);
1007 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1060 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
1008 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 1061 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
1009 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); 1062 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]);
1010 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); 1063 EXPECT_TRUE([tab_model_observer tabMovedWasCalled]);
1011 1064
1012 // Move a tab from index 2 to index 2 (move tab to the same index). 1065 // Move a tab from index 2 to index 2 (move tab to the same index).
1013 [tab_model_observer_ setTabMovedWasCalled:NO]; 1066 [tab_model_observer setTabMovedWasCalled:NO];
1014 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:2]; 1067 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:2];
1015 ASSERT_EQ(3U, [tab_model_ count]); 1068 ASSERT_EQ(3U, [tab_model_ count]);
1016 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1069 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
1017 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 1070 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
1018 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); 1071 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]);
1019 EXPECT_FALSE([tab_model_observer_ tabMovedWasCalled]); 1072 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]);
1073
1074 // TabModel asserts that there are no observer when it is deallocated,
1075 // so remove the observer before the end of the method.
1076 [tab_model_ removeObserver:tab_model_observer.get()];
1020 } 1077 }
1021 1078
1022 TEST_F(TabModelTest, SetParentModel) { 1079 TEST_F(TabModelTest, SetParentModel) {
1023 // Create a tab without a parent model and make sure it doesn't crash. Then 1080 // Create a tab without a parent model and make sure it doesn't crash. Then
1024 // set its parent TabModel and make sure that works as well. 1081 // set its parent TabModel and make sure that works as well.
1025 base::scoped_nsobject<Tab> tab([[Tab alloc] 1082 base::scoped_nsobject<Tab> tab([[Tab alloc]
1026 initWithBrowserState:chrome_browser_state_.get() 1083 initWithBrowserState:chrome_browser_state_.get()
1027 opener:nil 1084 opener:nil
1028 openedByDOM:NO 1085 openedByDOM:NO
1029 model:nil]); 1086 model:nil]);
1030 EXPECT_TRUE([tab parentTabModel] == nil); 1087 EXPECT_TRUE([tab parentTabModel] == nil);
1031 [tab_model_ insertTab:tab atIndex:0]; 1088 [tab_model_ insertTab:tab atIndex:0];
1032 [tab setParentTabModel:tab_model_.get()]; 1089 [tab setParentTabModel:tab_model_.get()];
1033 EXPECT_FALSE([tab parentTabModel] == nil); 1090 EXPECT_FALSE([tab parentTabModel] == nil);
1034 [tab_model_ closeTabAtIndex:0]; 1091 [tab_model_ closeTabAtIndex:0];
1035 } 1092 }
1036 1093
1037 TEST_F(TabModelTest, PersistSelectionChange) { 1094 TEST_F(TabModelTest, PersistSelectionChange) {
1038 TestChromeBrowserState::Builder test_cbs_builder; 1095 NSString* stashPath =
1039 auto chrome_browser_state = test_cbs_builder.Build(); 1096 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value());
1040 1097
1041 // Tabs register some observers with the ChromeBrowserState in an ObserverList 1098 [tab_model_ insertTabWithURL:GURL(kURL1)
1042 // that assert it is empty in its destructor. As Tab are Objective-C object, 1099 referrer:web::Referrer()
1043 // it is necessary to use a local pool to ensure all autoreleased object that 1100 transition:ui::PAGE_TRANSITION_TYPED
1044 // may reference those Tabs are deallocated before the TestChromeBrowserState 1101 opener:nil
1045 // is destroyed (this cannot use the TabModelTest ScopedNSAutoreleasePool as 1102 openedByDOM:NO
1046 // it will be drained after the local variable chrome_browser_state). 1103 atIndex:[tab_model_ count]
1047 base::mac::ScopedNSAutoreleasePool pool; 1104 inBackground:NO];
1105 [tab_model_ insertTabWithURL:GURL(kURL1)
1106 referrer:web::Referrer()
1107 transition:ui::PAGE_TRANSITION_TYPED
1108 opener:[tab_model_ tabAtIndex:0]
1109 openedByDOM:NO
1110 atIndex:[tab_model_ count]
1111 inBackground:NO];
1112 [tab_model_ insertTabWithURL:GURL(kURL1)
1113 referrer:web::Referrer()
1114 transition:ui::PAGE_TRANSITION_TYPED
1115 opener:[tab_model_ tabAtIndex:1]
1116 openedByDOM:NO
1117 atIndex:0
1118 inBackground:NO];
1048 1119
1049 NSString* stashPath = 1120 ASSERT_EQ(3U, [tab_model_ count]);
1050 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); 1121 [tab_model_ setCurrentTab:[tab_model_ tabAtIndex:1]];
1051 1122
1052 base::scoped_nsobject<TabModel> model([[TabModel alloc] 1123 EXPECT_EQ(nil, [tab_model_ openerOfTab:[tab_model_ tabAtIndex:1]]);
1053 initWithSessionWindow:session_window_.get() 1124 EXPECT_EQ([tab_model_ tabAtIndex:1],
1054 sessionService:[SessionServiceIOS sharedService] 1125 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]);
1055 browserState:chrome_browser_state.get()]); 1126 EXPECT_EQ([tab_model_ tabAtIndex:2],
1056 1127 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]);
1057 [model insertTabWithURL:kURL
1058 referrer:kReferrer
1059 transition:ui::PAGE_TRANSITION_TYPED
1060 opener:nil
1061 openedByDOM:NO
1062 atIndex:[model count]
1063 inBackground:YES];
1064 [model insertTabWithURL:kURL
1065 referrer:kReferrer
1066 transition:ui::PAGE_TRANSITION_TYPED
1067 opener:[model tabAtIndex:0]
1068 openedByDOM:NO
1069 atIndex:[model count]
1070 inBackground:YES];
1071 [model insertTabWithURL:kURL
1072 referrer:kReferrer
1073 transition:ui::PAGE_TRANSITION_TYPED
1074 opener:[model tabAtIndex:1]
1075 openedByDOM:NO
1076 atIndex:0
1077 inBackground:YES];
1078
1079 ASSERT_EQ(3U, [model count]);
1080 [model setCurrentTab:[model tabAtIndex:1]];
1081
1082 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]);
1083 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]);
1084 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]);
1085 1128
1086 // Force state to flush to disk on the main thread so it can be immediately 1129 // Force state to flush to disk on the main thread so it can be immediately
1087 // tested below. 1130 // tested below.
1088 SessionWindowIOS* window = [model windowForSavingSession]; 1131 SessionWindowIOS* window = [tab_model_ windowForSavingSession];
1089 [[SessionServiceIOS sharedService] performSaveWindow:window 1132 [[SessionServiceIOS sharedService] performSaveWindow:window
1090 toDirectory:stashPath]; 1133 toDirectory:stashPath];
1091 [model browserStateDestroyed]; 1134 [tab_model_ browserStateDestroyed];
1092 model.reset(); 1135 tab_model_.reset();
1093 1136
1094 // Restoring TabModel session sends asynchronous tasks to IO thread, wait 1137 // Restoring TabModel session sends asynchronous tasks to IO thread, wait
1095 // for them to complete after destroying the TabModel. 1138 // for them to complete after destroying the TabModel.
1096 base::RunLoop().RunUntilIdle(); 1139 base::RunLoop().RunUntilIdle();
1097 1140
1098 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService] 1141 SessionWindowIOS* sessionWindow = [[SessionServiceIOS sharedService]
1099 loadWindowForBrowserState:chrome_browser_state.get()]; 1142 loadWindowForBrowserState:chrome_browser_state_.get()];
1100 1143
1101 // Create tab model from saved session. 1144 // Create tab model from saved session.
1102 base::scoped_nsobject<TestSessionService> test_service( 1145 base::scoped_nsobject<TestSessionService> test_service(
1103 [[TestSessionService alloc] init]); 1146 [[TestSessionService alloc] init]);
1104 1147
1105 model.reset([[TabModel alloc] 1148 tab_model_.reset([[TabModel alloc]
1106 initWithSessionWindow:sessionWindow 1149 initWithSessionWindow:sessionWindow
1107 sessionService:test_service 1150 sessionService:test_service
1108 browserState:chrome_browser_state.get()]); 1151 browserState:chrome_browser_state_.get()]);
1109 ASSERT_EQ(3u, [model count]); 1152 ASSERT_EQ(3u, [tab_model_ count]);
1110 1153
1111 EXPECT_EQ([model tabAtIndex:1], [model currentTab]); 1154 EXPECT_EQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]);
1112 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); 1155 EXPECT_EQ(nil, [tab_model_ openerOfTab:[tab_model_ tabAtIndex:1]]);
1113 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); 1156 EXPECT_EQ([tab_model_ tabAtIndex:1],
1114 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); 1157 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]);
1115 1158 EXPECT_EQ([tab_model_ tabAtIndex:2],
1116 [model browserStateDestroyed]; 1159 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]);
1117 model.reset();
1118
1119 // Restoring TabModel session sends asynchronous tasks to IO thread, wait
1120 // for them to complete after destroying the TabModel.
1121 base::RunLoop().RunUntilIdle();
1122 1160
1123 // Clean up. 1161 // Clean up.
1124 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath 1162 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath
1125 error:nullptr]); 1163 error:nullptr]);
1126 } 1164 }
1127 1165
1128 } // anonymous namespace 1166 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_model_observers_bridge.mm ('k') | ios/web/navigation/crw_session_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698