OLD | NEW |
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 session_window_.reset([[SessionWindowIOS alloc] init]); | 101 session_window_.reset([[SessionWindowIOS alloc] init]); |
102 // Create tab model with just a dummy session service so the async state | 102 // Create tab model with just a dummy session service so the async state |
103 // saving doesn't trigger unless actually wanted. | 103 // saving doesn't trigger unless actually wanted. |
104 base::scoped_nsobject<TestSessionService> test_service( | 104 base::scoped_nsobject<TestSessionService> test_service( |
105 [[TestSessionService alloc] init]); | 105 [[TestSessionService alloc] init]); |
106 tab_model_.reset([[TabModel alloc] | 106 tab_model_.reset([[TabModel alloc] |
107 initWithSessionWindow:session_window_.get() | 107 initWithSessionWindow:session_window_.get() |
108 sessionService:test_service | 108 sessionService:test_service |
109 browserState:chrome_browser_state_.get()]); | 109 browserState:chrome_browser_state_.get()]); |
110 [tab_model_ setWebUsageEnabled:YES]; | 110 [tab_model_ setWebUsageEnabled:NO]; |
111 [tab_model_ setPrimary:YES]; | 111 [tab_model_ setPrimary:YES]; |
112 tab_model_observer_.reset([[TabModelObserverPong alloc] init]); | 112 tab_model_observer_.reset([[TabModelObserverPong alloc] init]); |
113 [tab_model_ addObserver:tab_model_observer_]; | 113 [tab_model_ addObserver:tab_model_observer_]; |
114 } | 114 } |
115 | 115 |
116 ~TabModelTest() override { | 116 ~TabModelTest() override { |
117 [tab_model_ removeObserver:tab_model_observer_]; | 117 [tab_model_ removeObserver:tab_model_observer_]; |
118 [tab_model_ browserStateDestroyed]; | 118 [tab_model_ browserStateDestroyed]; |
119 } | 119 } |
120 | 120 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 base::mac::ScopedNSAutoreleasePool pool_; | 168 base::mac::ScopedNSAutoreleasePool pool_; |
169 base::scoped_nsobject<TabModel> tab_model_; | 169 base::scoped_nsobject<TabModel> tab_model_; |
170 base::scoped_nsobject<TabModelObserverPong> tab_model_observer_; | 170 base::scoped_nsobject<TabModelObserverPong> tab_model_observer_; |
171 }; | 171 }; |
172 | 172 |
173 TEST_F(TabModelTest, IsEmpty) { | 173 TEST_F(TabModelTest, IsEmpty) { |
174 EXPECT_EQ([tab_model_ count], 0U); | 174 EXPECT_EQ([tab_model_ count], 0U); |
175 EXPECT_TRUE([tab_model_ isEmpty]); | 175 EXPECT_TRUE([tab_model_ isEmpty]); |
176 [tab_model_ insertTabWithURL:kURL | 176 [tab_model_ insertTabWithURL:kURL |
177 referrer:kReferrer | 177 referrer:kReferrer |
| 178 transition:ui::PAGE_TRANSITION_TYPED |
178 opener:nil | 179 opener:nil |
179 atIndex:0]; | 180 openedByDOM:NO |
| 181 atIndex:0 |
| 182 inBackground:YES]; |
180 ASSERT_EQ(1U, [tab_model_ count]); | 183 ASSERT_EQ(1U, [tab_model_ count]); |
181 EXPECT_FALSE([tab_model_ isEmpty]); | 184 EXPECT_FALSE([tab_model_ isEmpty]); |
182 } | 185 } |
183 | 186 |
184 TEST_F(TabModelTest, InsertUrlSingle) { | 187 TEST_F(TabModelTest, InsertUrlSingle) { |
185 Tab* tab = [tab_model_ insertTabWithURL:kURL | 188 Tab* tab = [tab_model_ insertTabWithURL:kURL |
186 referrer:kReferrer | 189 referrer:kReferrer |
| 190 transition:ui::PAGE_TRANSITION_TYPED |
187 opener:nil | 191 opener:nil |
188 atIndex:0]; | 192 openedByDOM:NO |
| 193 atIndex:0 |
| 194 inBackground:YES]; |
189 ASSERT_EQ(1U, [tab_model_ count]); | 195 ASSERT_EQ(1U, [tab_model_ count]); |
190 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); | 196 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); |
191 } | 197 } |
192 | 198 |
193 TEST_F(TabModelTest, InsertUrlMultiple) { | 199 TEST_F(TabModelTest, InsertUrlMultiple) { |
194 Tab* tab0 = [tab_model_ insertTabWithURL:kURL | 200 Tab* tab0 = [tab_model_ insertTabWithURL:kURL |
195 referrer:kReferrer | 201 referrer:kReferrer |
| 202 transition:ui::PAGE_TRANSITION_TYPED |
196 opener:nil | 203 opener:nil |
197 atIndex:0]; | 204 openedByDOM:NO |
| 205 atIndex:0 |
| 206 inBackground:YES]; |
198 Tab* tab1 = [tab_model_ insertTabWithURL:kURL | 207 Tab* tab1 = [tab_model_ insertTabWithURL:kURL |
199 referrer:kReferrer | 208 referrer:kReferrer |
| 209 transition:ui::PAGE_TRANSITION_TYPED |
200 opener:nil | 210 opener:nil |
201 atIndex:0]; | 211 openedByDOM:NO |
| 212 atIndex:0 |
| 213 inBackground:YES]; |
202 Tab* tab2 = [tab_model_ insertTabWithURL:kURL | 214 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
203 referrer:kReferrer | 215 referrer:kReferrer |
| 216 transition:ui::PAGE_TRANSITION_TYPED |
204 opener:nil | 217 opener:nil |
205 atIndex:1]; | 218 openedByDOM:NO |
| 219 atIndex:1 |
| 220 inBackground:YES]; |
206 | 221 |
207 ASSERT_EQ(3U, [tab_model_ count]); | 222 ASSERT_EQ(3U, [tab_model_ count]); |
208 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); | 223 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
209 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); | 224 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
210 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); | 225 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); |
211 } | 226 } |
212 | 227 |
213 TEST_F(TabModelTest, AppendUrlSingle) { | 228 TEST_F(TabModelTest, AppendUrlSingle) { |
214 Tab* tab = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 229 Tab* tab = [tab_model_ insertTabWithURL:kURL |
| 230 referrer:kReferrer |
| 231 transition:ui::PAGE_TRANSITION_TYPED |
| 232 opener:nil |
| 233 openedByDOM:NO |
| 234 atIndex:[tab_model_ count] |
| 235 inBackground:YES]; |
215 ASSERT_EQ(1U, [tab_model_ count]); | 236 ASSERT_EQ(1U, [tab_model_ count]); |
216 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); | 237 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); |
217 } | 238 } |
218 | 239 |
219 TEST_F(TabModelTest, AppendUrlMultiple) { | 240 TEST_F(TabModelTest, AppendUrlMultiple) { |
220 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 241 Tab* tab0 = [tab_model_ insertTabWithURL:kURL |
221 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 242 referrer:kReferrer |
222 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 243 transition:ui::PAGE_TRANSITION_TYPED |
| 244 opener:nil |
| 245 openedByDOM:NO |
| 246 atIndex:[tab_model_ count] |
| 247 inBackground:YES]; |
| 248 Tab* tab1 = [tab_model_ insertTabWithURL:kURL |
| 249 referrer:kReferrer |
| 250 transition:ui::PAGE_TRANSITION_TYPED |
| 251 opener:nil |
| 252 openedByDOM:NO |
| 253 atIndex:[tab_model_ count] |
| 254 inBackground:YES]; |
| 255 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
| 256 referrer:kReferrer |
| 257 transition:ui::PAGE_TRANSITION_TYPED |
| 258 opener:nil |
| 259 openedByDOM:NO |
| 260 atIndex:[tab_model_ count] |
| 261 inBackground:YES]; |
223 | 262 |
224 ASSERT_EQ(3U, [tab_model_ count]); | 263 ASSERT_EQ(3U, [tab_model_ count]); |
225 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); | 264 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
226 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); | 265 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
227 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); | 266 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); |
228 } | 267 } |
229 | 268 |
230 TEST_F(TabModelTest, CloseTabAtIndexBeginning) { | 269 TEST_F(TabModelTest, CloseTabAtIndexBeginning) { |
231 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 270 [tab_model_ insertTabWithURL:kURL |
232 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 271 referrer:kReferrer |
233 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 272 transition:ui::PAGE_TRANSITION_TYPED |
| 273 opener:nil |
| 274 openedByDOM:NO |
| 275 atIndex:[tab_model_ count] |
| 276 inBackground:YES]; |
| 277 Tab* tab1 = [tab_model_ insertTabWithURL:kURL |
| 278 referrer:kReferrer |
| 279 transition:ui::PAGE_TRANSITION_TYPED |
| 280 opener:nil |
| 281 openedByDOM:NO |
| 282 atIndex:[tab_model_ count] |
| 283 inBackground:YES]; |
| 284 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
| 285 referrer:kReferrer |
| 286 transition:ui::PAGE_TRANSITION_TYPED |
| 287 opener:nil |
| 288 openedByDOM:NO |
| 289 atIndex:[tab_model_ count] |
| 290 inBackground:YES]; |
234 | 291 |
235 [tab_model_ closeTabAtIndex:0]; | 292 [tab_model_ closeTabAtIndex:0]; |
236 | 293 |
237 ASSERT_EQ(2U, [tab_model_ count]); | 294 ASSERT_EQ(2U, [tab_model_ count]); |
238 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); | 295 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
239 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); | 296 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
240 } | 297 } |
241 | 298 |
242 TEST_F(TabModelTest, CloseTabAtIndexMiddle) { | 299 TEST_F(TabModelTest, CloseTabAtIndexMiddle) { |
243 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 300 Tab* tab0 = [tab_model_ insertTabWithURL:kURL |
244 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 301 referrer:kReferrer |
245 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 302 transition:ui::PAGE_TRANSITION_TYPED |
| 303 opener:nil |
| 304 openedByDOM:NO |
| 305 atIndex:[tab_model_ count] |
| 306 inBackground:YES]; |
| 307 [tab_model_ insertTabWithURL:kURL |
| 308 referrer:kReferrer |
| 309 transition:ui::PAGE_TRANSITION_TYPED |
| 310 opener:nil |
| 311 openedByDOM:NO |
| 312 atIndex:[tab_model_ count] |
| 313 inBackground:YES]; |
| 314 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
| 315 referrer:kReferrer |
| 316 transition:ui::PAGE_TRANSITION_TYPED |
| 317 opener:nil |
| 318 openedByDOM:NO |
| 319 atIndex:[tab_model_ count] |
| 320 inBackground:YES]; |
246 | 321 |
247 [tab_model_ closeTabAtIndex:1]; | 322 [tab_model_ closeTabAtIndex:1]; |
248 | 323 |
249 ASSERT_EQ(2U, [tab_model_ count]); | 324 ASSERT_EQ(2U, [tab_model_ count]); |
250 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); | 325 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
251 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); | 326 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
252 } | 327 } |
253 | 328 |
254 TEST_F(TabModelTest, CloseTabAtIndexLast) { | 329 TEST_F(TabModelTest, CloseTabAtIndexLast) { |
255 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 330 Tab* tab0 = [tab_model_ insertTabWithURL:kURL |
256 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 331 referrer:kReferrer |
257 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 332 transition:ui::PAGE_TRANSITION_TYPED |
| 333 opener:nil |
| 334 openedByDOM:NO |
| 335 atIndex:[tab_model_ count] |
| 336 inBackground:YES]; |
| 337 Tab* tab1 = [tab_model_ insertTabWithURL:kURL |
| 338 referrer:kReferrer |
| 339 transition:ui::PAGE_TRANSITION_TYPED |
| 340 opener:nil |
| 341 openedByDOM:NO |
| 342 atIndex:[tab_model_ count] |
| 343 inBackground:YES]; |
| 344 [tab_model_ insertTabWithURL:kURL |
| 345 referrer:kReferrer |
| 346 transition:ui::PAGE_TRANSITION_TYPED |
| 347 opener:nil |
| 348 openedByDOM:NO |
| 349 atIndex:[tab_model_ count] |
| 350 inBackground:YES]; |
258 | 351 |
259 [tab_model_ closeTabAtIndex:2]; | 352 [tab_model_ closeTabAtIndex:2]; |
260 | 353 |
261 ASSERT_EQ(2U, [tab_model_ count]); | 354 ASSERT_EQ(2U, [tab_model_ count]); |
262 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); | 355 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
263 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); | 356 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
264 } | 357 } |
265 | 358 |
266 TEST_F(TabModelTest, CloseTabAtIndexOnlyOne) { | 359 TEST_F(TabModelTest, CloseTabAtIndexOnlyOne) { |
267 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 360 [tab_model_ insertTabWithURL:kURL |
| 361 referrer:kReferrer |
| 362 transition:ui::PAGE_TRANSITION_TYPED |
| 363 opener:nil |
| 364 openedByDOM:NO |
| 365 atIndex:[tab_model_ count] |
| 366 inBackground:YES]; |
268 | 367 |
269 [tab_model_ closeTabAtIndex:0]; | 368 [tab_model_ closeTabAtIndex:0]; |
270 | 369 |
271 EXPECT_EQ(0U, [tab_model_ count]); | 370 EXPECT_EQ(0U, [tab_model_ count]); |
272 } | 371 } |
273 | 372 |
274 TEST_F(TabModelTest, RestoreSessionOnNTPTest) { | 373 TEST_F(TabModelTest, RestoreSessionOnNTPTest) { |
275 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) | 374 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) |
276 referrer:kEmptyReferrer | 375 referrer:kEmptyReferrer |
| 376 transition:ui::PAGE_TRANSITION_TYPED |
277 opener:nil | 377 opener:nil |
278 atIndex:0]; | 378 openedByDOM:NO |
| 379 atIndex:0 |
| 380 inBackground:YES]; |
279 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); | 381 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); |
280 | 382 |
281 RestoreSession(window.get()); | 383 RestoreSession(window.get()); |
282 ASSERT_EQ(3U, [tab_model_ count]); | 384 ASSERT_EQ(3U, [tab_model_ count]); |
283 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]); | 385 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]); |
284 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]); | 386 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]); |
285 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); | 387 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); |
286 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); | 388 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); |
287 } | 389 } |
288 | 390 |
289 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) { | 391 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) { |
290 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) | 392 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) |
291 referrer:kEmptyReferrer | 393 referrer:kEmptyReferrer |
| 394 transition:ui::PAGE_TRANSITION_TYPED |
292 opener:nil | 395 opener:nil |
293 atIndex:0]; | 396 openedByDOM:NO |
| 397 atIndex:0 |
| 398 inBackground:YES]; |
294 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) | 399 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) |
295 referrer:kEmptyReferrer | 400 referrer:kEmptyReferrer |
| 401 transition:ui::PAGE_TRANSITION_TYPED |
296 opener:nil | 402 opener:nil |
297 atIndex:1]; | 403 openedByDOM:NO |
| 404 atIndex:1 |
| 405 inBackground:YES]; |
298 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); | 406 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); |
299 | 407 |
300 RestoreSession(window.get()); | 408 RestoreSession(window.get()); |
301 ASSERT_EQ(5U, [tab_model_ count]); | 409 ASSERT_EQ(5U, [tab_model_ count]); |
302 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]); | 410 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]); |
303 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); | 411 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
304 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); | 412 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
305 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]); | 413 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]); |
306 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]); | 414 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]); |
307 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]); | 415 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]); |
308 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]); | 416 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]); |
309 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]); | 417 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]); |
310 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]); | 418 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]); |
311 } | 419 } |
312 | 420 |
313 TEST_F(TabModelTest, RestoreSessionOnAnyTest) { | 421 TEST_F(TabModelTest, RestoreSessionOnAnyTest) { |
314 Tab* tab = [tab_model_ insertTabWithURL:kURL | 422 Tab* tab = [tab_model_ insertTabWithURL:kURL |
315 referrer:kEmptyReferrer | 423 referrer:kEmptyReferrer |
| 424 transition:ui::PAGE_TRANSITION_TYPED |
316 opener:nil | 425 opener:nil |
317 atIndex:0]; | 426 openedByDOM:NO |
| 427 atIndex:0 |
| 428 inBackground:YES]; |
318 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); | 429 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); |
319 | 430 |
320 RestoreSession(window.get()); | 431 RestoreSession(window.get()); |
321 ASSERT_EQ(4U, [tab_model_ count]); | 432 ASSERT_EQ(4U, [tab_model_ count]); |
322 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]); | 433 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]); |
323 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); | 434 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); |
324 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); | 435 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); |
325 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); | 436 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); |
326 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]); | 437 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]); |
327 } | 438 } |
328 | 439 |
329 TEST_F(TabModelTest, CloseAllTabs) { | 440 TEST_F(TabModelTest, CloseAllTabs) { |
330 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 441 [tab_model_ insertTabWithURL:kURL |
331 [tab_model_ addTabWithURL:GURL("https://www.some.url2.com") | 442 referrer:kReferrer |
332 referrer:kReferrer2]; | 443 transition:ui::PAGE_TRANSITION_TYPED |
333 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 444 opener:nil |
| 445 openedByDOM:NO |
| 446 atIndex:[tab_model_ count] |
| 447 inBackground:YES]; |
| 448 [tab_model_ insertTabWithURL:GURL("https://www.some.url2.com") |
| 449 referrer:kReferrer2 |
| 450 transition:ui::PAGE_TRANSITION_TYPED |
| 451 opener:nil |
| 452 openedByDOM:NO |
| 453 atIndex:[tab_model_ count] |
| 454 inBackground:YES]; |
| 455 [tab_model_ insertTabWithURL:kURL |
| 456 referrer:kReferrer |
| 457 transition:ui::PAGE_TRANSITION_TYPED |
| 458 opener:nil |
| 459 openedByDOM:NO |
| 460 atIndex:[tab_model_ count] |
| 461 inBackground:YES]; |
334 | 462 |
335 [tab_model_ closeAllTabs]; | 463 [tab_model_ closeAllTabs]; |
336 | 464 |
337 EXPECT_EQ(0U, [tab_model_ count]); | 465 EXPECT_EQ(0U, [tab_model_ count]); |
338 } | 466 } |
339 | 467 |
340 TEST_F(TabModelTest, CloseAllTabsWithNoTabs) { | 468 TEST_F(TabModelTest, CloseAllTabsWithNoTabs) { |
341 [tab_model_ closeAllTabs]; | 469 [tab_model_ closeAllTabs]; |
342 | 470 |
343 EXPECT_EQ(0U, [tab_model_ count]); | 471 EXPECT_EQ(0U, [tab_model_ count]); |
344 } | 472 } |
345 | 473 |
346 TEST_F(TabModelTest, InsertWithSessionController) { | 474 TEST_F(TabModelTest, InsertWithSessionController) { |
347 EXPECT_EQ([tab_model_ count], 0U); | 475 EXPECT_EQ([tab_model_ count], 0U); |
348 EXPECT_TRUE([tab_model_ isEmpty]); | 476 EXPECT_TRUE([tab_model_ isEmpty]); |
349 | 477 |
350 Tab* new_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"opener", -1) | 478 Tab* new_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"opener", -1) |
351 atIndex:0]; | 479 atIndex:0]; |
352 EXPECT_EQ([tab_model_ count], 1U); | 480 EXPECT_EQ([tab_model_ count], 1U); |
353 [tab_model_ setCurrentTab:new_tab]; | 481 [tab_model_ setCurrentTab:new_tab]; |
354 Tab* current_tab = [tab_model_ currentTab]; | 482 Tab* current_tab = [tab_model_ currentTab]; |
355 EXPECT_TRUE(current_tab); | 483 EXPECT_TRUE(current_tab); |
356 } | 484 } |
357 | 485 |
358 TEST_F(TabModelTest, OpenerOfTab) { | 486 TEST_F(TabModelTest, OpenerOfTab) { |
359 // Start off with a couple tabs. | 487 // Start off with a couple tabs. |
360 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 488 [tab_model_ insertTabWithURL:kURL |
361 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 489 referrer:kEmptyReferrer |
362 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 490 transition:ui::PAGE_TRANSITION_TYPED |
| 491 opener:nil |
| 492 openedByDOM:NO |
| 493 atIndex:[tab_model_ count] |
| 494 inBackground:YES]; |
| 495 [tab_model_ insertTabWithURL:kURL |
| 496 referrer:kEmptyReferrer |
| 497 transition:ui::PAGE_TRANSITION_TYPED |
| 498 opener:nil |
| 499 openedByDOM:NO |
| 500 atIndex:[tab_model_ count] |
| 501 inBackground:YES]; |
| 502 [tab_model_ insertTabWithURL:kURL |
| 503 referrer:kEmptyReferrer |
| 504 transition:ui::PAGE_TRANSITION_TYPED |
| 505 opener:nil |
| 506 openedByDOM:NO |
| 507 atIndex:[tab_model_ count] |
| 508 inBackground:YES]; |
363 | 509 |
364 // Create parent tab. | 510 // Create parent tab. |
365 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() | 511 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
366 atIndex:[tab_model_ count]]; | 512 atIndex:[tab_model_ count]]; |
367 // Create child tab. | 513 // Create child tab. |
368 Tab* child_tab = | 514 Tab* child_tab = |
369 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 515 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
370 atIndex:[tab_model_ count]]; | 516 atIndex:[tab_model_ count]]; |
371 // Create another unrelated tab. | 517 // Create another unrelated tab. |
372 Tab* another_tab = [tab_model_ insertTabWithWebState:CreateWebState() | 518 Tab* another_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
(...skipping 16 matching lines...) Expand all Loading... |
389 | 535 |
390 TEST_F(TabModelTest, OpenersEmptyModel) { | 536 TEST_F(TabModelTest, OpenersEmptyModel) { |
391 // Empty model. | 537 // Empty model. |
392 EXPECT_TRUE([tab_model_ isEmpty]); | 538 EXPECT_TRUE([tab_model_ isEmpty]); |
393 EXPECT_FALSE([tab_model_ nextTabWithOpener:nil afterTab:nil]); | 539 EXPECT_FALSE([tab_model_ nextTabWithOpener:nil afterTab:nil]); |
394 EXPECT_FALSE([tab_model_ lastTabWithOpener:nil]); | 540 EXPECT_FALSE([tab_model_ lastTabWithOpener:nil]); |
395 } | 541 } |
396 | 542 |
397 TEST_F(TabModelTest, OpenersNothingOpenedGeneral) { | 543 TEST_F(TabModelTest, OpenersNothingOpenedGeneral) { |
398 // Start with a few tabs. | 544 // Start with a few tabs. |
399 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 545 [tab_model_ insertTabWithURL:kURL |
400 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 546 referrer:kEmptyReferrer |
| 547 transition:ui::PAGE_TRANSITION_TYPED |
| 548 opener:nil |
| 549 openedByDOM:NO |
| 550 atIndex:[tab_model_ count] |
| 551 inBackground:YES]; |
| 552 [tab_model_ insertTabWithURL:kURL |
| 553 referrer:kEmptyReferrer |
| 554 transition:ui::PAGE_TRANSITION_TYPED |
| 555 opener:nil |
| 556 openedByDOM:NO |
| 557 atIndex:[tab_model_ count] |
| 558 inBackground:YES]; |
401 | 559 |
402 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() | 560 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() |
403 atIndex:[tab_model_ count]]; | 561 atIndex:[tab_model_ count]]; |
404 | 562 |
405 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 563 [tab_model_ insertTabWithURL:kURL |
406 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 564 referrer:kEmptyReferrer |
| 565 transition:ui::PAGE_TRANSITION_TYPED |
| 566 opener:nil |
| 567 openedByDOM:NO |
| 568 atIndex:[tab_model_ count] |
| 569 inBackground:YES]; |
| 570 [tab_model_ insertTabWithURL:kURL |
| 571 referrer:kEmptyReferrer |
| 572 transition:ui::PAGE_TRANSITION_TYPED |
| 573 opener:nil |
| 574 openedByDOM:NO |
| 575 atIndex:[tab_model_ count] |
| 576 inBackground:YES]; |
407 | 577 |
408 // All should fail since this hasn't opened anything else. | 578 // All should fail since this hasn't opened anything else. |
409 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 579 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
410 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 580 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
411 | 581 |
412 // Add more items to the tab, expect the same results. | 582 // Add more items to the tab, expect the same results. |
413 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 583 [tab_model_ insertTabWithURL:kURL |
414 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 584 referrer:kEmptyReferrer |
| 585 transition:ui::PAGE_TRANSITION_TYPED |
| 586 opener:nil |
| 587 openedByDOM:NO |
| 588 atIndex:[tab_model_ count] |
| 589 inBackground:YES]; |
| 590 [tab_model_ insertTabWithURL:kURL |
| 591 referrer:kEmptyReferrer |
| 592 transition:ui::PAGE_TRANSITION_TYPED |
| 593 opener:nil |
| 594 openedByDOM:NO |
| 595 atIndex:[tab_model_ count] |
| 596 inBackground:YES]; |
| 597 |
415 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 598 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
416 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 599 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
417 } | 600 } |
418 | 601 |
419 TEST_F(TabModelTest, OpenersNothingOpenedFirst) { | 602 TEST_F(TabModelTest, OpenersNothingOpenedFirst) { |
420 // Our tab is first. | 603 // Our tab is first. |
421 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() | 604 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() |
422 atIndex:[tab_model_ count]]; | 605 atIndex:[tab_model_ count]]; |
423 | 606 |
424 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 607 [tab_model_ insertTabWithURL:kURL |
425 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 608 referrer:kEmptyReferrer |
| 609 transition:ui::PAGE_TRANSITION_TYPED |
| 610 opener:nil |
| 611 openedByDOM:NO |
| 612 atIndex:[tab_model_ count] |
| 613 inBackground:YES]; |
| 614 [tab_model_ insertTabWithURL:kURL |
| 615 referrer:kEmptyReferrer |
| 616 transition:ui::PAGE_TRANSITION_TYPED |
| 617 opener:nil |
| 618 openedByDOM:NO |
| 619 atIndex:[tab_model_ count] |
| 620 inBackground:YES]; |
426 | 621 |
427 // All should fail since this hasn't opened anything else. | 622 // All should fail since this hasn't opened anything else. |
428 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 623 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
429 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 624 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
430 } | 625 } |
431 | 626 |
432 TEST_F(TabModelTest, OpenersNothingOpenedLast) { | 627 TEST_F(TabModelTest, OpenersNothingOpenedLast) { |
433 // Our tab is last. | 628 // Our tab is last. |
434 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 629 [tab_model_ insertTabWithURL:kURL |
435 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 630 referrer:kEmptyReferrer |
| 631 transition:ui::PAGE_TRANSITION_TYPED |
| 632 opener:nil |
| 633 openedByDOM:NO |
| 634 atIndex:[tab_model_ count] |
| 635 inBackground:YES]; |
| 636 [tab_model_ insertTabWithURL:kURL |
| 637 referrer:kEmptyReferrer |
| 638 transition:ui::PAGE_TRANSITION_TYPED |
| 639 opener:nil |
| 640 openedByDOM:NO |
| 641 atIndex:[tab_model_ count] |
| 642 inBackground:YES]; |
436 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() | 643 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() |
437 atIndex:[tab_model_ count]]; | 644 atIndex:[tab_model_ count]]; |
438 | 645 |
439 // All should fail since this hasn't opened anything else. | 646 // All should fail since this hasn't opened anything else. |
440 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 647 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
441 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 648 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
442 } | 649 } |
443 | 650 |
444 TEST_F(TabModelTest, OpenersChildTabBeforeOpener) { | 651 TEST_F(TabModelTest, OpenersChildTabBeforeOpener) { |
445 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() | 652 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
446 atIndex:[tab_model_ count]]; | 653 atIndex:[tab_model_ count]]; |
447 // Insert child at start | 654 // Insert child at start |
448 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) atIndex:0]; | 655 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) atIndex:0]; |
449 | 656 |
450 // Insert a few more between them. | 657 // Insert a few more between them. |
451 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; | 658 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; |
452 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; | 659 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; |
453 | 660 |
454 EXPECT_FALSE([tab_model_ nextTabWithOpener:parent_tab afterTab:nil]); | 661 EXPECT_FALSE([tab_model_ nextTabWithOpener:parent_tab afterTab:nil]); |
455 EXPECT_FALSE([tab_model_ lastTabWithOpener:parent_tab]); | 662 EXPECT_FALSE([tab_model_ lastTabWithOpener:parent_tab]); |
456 } | 663 } |
457 | 664 |
458 TEST_F(TabModelTest, OpenersChildTabAfterOpener) { | 665 TEST_F(TabModelTest, OpenersChildTabAfterOpener) { |
459 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() | 666 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
460 atIndex:[tab_model_ count]]; | 667 atIndex:[tab_model_ count]]; |
461 | 668 |
462 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 669 [tab_model_ insertTabWithURL:kURL |
463 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 670 referrer:kEmptyReferrer |
| 671 transition:ui::PAGE_TRANSITION_TYPED |
| 672 opener:nil |
| 673 openedByDOM:NO |
| 674 atIndex:[tab_model_ count] |
| 675 inBackground:YES]; |
| 676 [tab_model_ insertTabWithURL:kURL |
| 677 referrer:kEmptyReferrer |
| 678 transition:ui::PAGE_TRANSITION_TYPED |
| 679 opener:nil |
| 680 openedByDOM:NO |
| 681 atIndex:[tab_model_ count] |
| 682 inBackground:YES]; |
464 // Insert two children at end. | 683 // Insert two children at end. |
465 Tab* child_tab1 = | 684 Tab* child_tab1 = |
466 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 685 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
467 atIndex:[tab_model_ count]]; | 686 atIndex:[tab_model_ count]]; |
468 Tab* child_tab2 = | 687 Tab* child_tab2 = |
469 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 688 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
470 atIndex:[tab_model_ count]]; | 689 atIndex:[tab_model_ count]]; |
471 | 690 |
472 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:nil], child_tab1); | 691 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:nil], child_tab1); |
473 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:child_tab1], | 692 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:child_tab1], |
474 child_tab2); | 693 child_tab2); |
475 EXPECT_EQ([tab_model_ lastTabWithOpener:parent_tab], child_tab2); | 694 EXPECT_EQ([tab_model_ lastTabWithOpener:parent_tab], child_tab2); |
476 } | 695 } |
477 | 696 |
478 TEST_F(TabModelTest, AddWithOrderController) { | 697 TEST_F(TabModelTest, AddWithOrderController) { |
479 // Create a few tabs with the controller at the front. | 698 // Create a few tabs with the controller at the front. |
480 Tab* parent = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 699 Tab* parent = [tab_model_ insertTabWithURL:kURL |
481 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 700 referrer:kEmptyReferrer |
482 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 701 transition:ui::PAGE_TRANSITION_TYPED |
| 702 opener:nil |
| 703 openedByDOM:NO |
| 704 atIndex:[tab_model_ count] |
| 705 inBackground:YES]; |
| 706 [tab_model_ insertTabWithURL:kURL |
| 707 referrer:kEmptyReferrer |
| 708 transition:ui::PAGE_TRANSITION_TYPED |
| 709 opener:nil |
| 710 openedByDOM:NO |
| 711 atIndex:[tab_model_ count] |
| 712 inBackground:YES]; |
| 713 [tab_model_ insertTabWithURL:kURL |
| 714 referrer:kEmptyReferrer |
| 715 transition:ui::PAGE_TRANSITION_TYPED |
| 716 opener:nil |
| 717 openedByDOM:NO |
| 718 atIndex:[tab_model_ count] |
| 719 inBackground:YES]; |
483 | 720 |
484 // Add a new tab, it should be added behind the parent. | 721 // Add a new tab, it should be added behind the parent. |
485 Tab* child = | 722 Tab* child = |
486 [tab_model_ insertTabWithURL:kURL | 723 [tab_model_ insertTabWithURL:kURL |
487 referrer:kEmptyReferrer | 724 referrer:kEmptyReferrer |
488 transition:ui::PAGE_TRANSITION_LINK | 725 transition:ui::PAGE_TRANSITION_LINK |
489 opener:parent | 726 opener:parent |
490 openedByDOM:NO | 727 openedByDOM:NO |
491 atIndex:TabModelConstants::kTabPositionAutomatically | 728 atIndex:TabModelConstants::kTabPositionAutomatically |
492 inBackground:NO]; | 729 inBackground:NO]; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 transition:ui::PAGE_TRANSITION_LINK | 769 transition:ui::PAGE_TRANSITION_LINK |
533 opener:tab3 | 770 opener:tab3 |
534 openedByDOM:NO | 771 openedByDOM:NO |
535 atIndex:TabModelConstants::kTabPositionAutomatically | 772 atIndex:TabModelConstants::kTabPositionAutomatically |
536 inBackground:YES]; | 773 inBackground:YES]; |
537 EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1); | 774 EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1); |
538 } | 775 } |
539 | 776 |
540 TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) { | 777 TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) { |
541 // Create a few tabs with the controller at the front. | 778 // Create a few tabs with the controller at the front. |
542 Tab* parent = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 779 Tab* parent = [tab_model_ insertTabWithURL:kURL |
| 780 referrer:kEmptyReferrer |
| 781 transition:ui::PAGE_TRANSITION_TYPED |
| 782 opener:nil |
| 783 openedByDOM:NO |
| 784 atIndex:[tab_model_ count] |
| 785 inBackground:YES]; |
543 // Force the history to update, as it is used to determine grouping. | 786 // Force the history to update, as it is used to determine grouping. |
544 ASSERT_TRUE([parent navigationManager]); | 787 ASSERT_TRUE([parent navigationManagerImpl]); |
545 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; | 788 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; |
546 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 789 [tab_model_ insertTabWithURL:kURL |
547 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 790 referrer:kEmptyReferrer |
| 791 transition:ui::PAGE_TRANSITION_TYPED |
| 792 opener:nil |
| 793 openedByDOM:NO |
| 794 atIndex:[tab_model_ count] |
| 795 inBackground:YES]; |
| 796 [tab_model_ insertTabWithURL:kURL |
| 797 referrer:kEmptyReferrer |
| 798 transition:ui::PAGE_TRANSITION_TYPED |
| 799 opener:nil |
| 800 openedByDOM:NO |
| 801 atIndex:[tab_model_ count] |
| 802 inBackground:YES]; |
548 | 803 |
549 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); | 804 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); |
550 | 805 |
551 // Add a new tab, it should be added behind the parent. | 806 // Add a new tab, it should be added behind the parent. |
552 Tab* child1 = | 807 Tab* child1 = |
553 [tab_model_ insertTabWithURL:kURL | 808 [tab_model_ insertTabWithURL:kURL |
554 referrer:kEmptyReferrer | 809 referrer:kEmptyReferrer |
555 transition:ui::PAGE_TRANSITION_LINK | 810 transition:ui::PAGE_TRANSITION_LINK |
556 opener:parent | 811 opener:parent |
557 openedByDOM:NO | 812 openedByDOM:NO |
(...skipping 12 matching lines...) Expand all Loading... |
570 openedByDOM:NO | 825 openedByDOM:NO |
571 atIndex:TabModelConstants::kTabPositionAutomatically | 826 atIndex:TabModelConstants::kTabPositionAutomatically |
572 inBackground:YES]; | 827 inBackground:YES]; |
573 EXPECT_EQ([tab_model_ indexOfTab:child2], 2U); | 828 EXPECT_EQ([tab_model_ indexOfTab:child2], 2U); |
574 | 829 |
575 // Navigate the parent tab to a new URL. It should not change any ordering. | 830 // Navigate the parent tab to a new URL. It should not change any ordering. |
576 web::NavigationManager::WebLoadParams parent_params( | 831 web::NavigationManager::WebLoadParams parent_params( |
577 GURL("http://www.espn.com")); | 832 GURL("http://www.espn.com")); |
578 parent_params.transition_type = ui::PAGE_TRANSITION_TYPED; | 833 parent_params.transition_type = ui::PAGE_TRANSITION_TYPED; |
579 [[parent webController] loadWithParams:parent_params]; | 834 [[parent webController] loadWithParams:parent_params]; |
580 ASSERT_TRUE([parent navigationManager]); | 835 ASSERT_TRUE([parent navigationManagerImpl]); |
581 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; | 836 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; |
582 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); | 837 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); |
583 | 838 |
584 // Add a new tab. It should be added behind the parent. It should not be added | 839 // Add a new tab. It should be added behind the parent. It should not be added |
585 // after the previous two children. | 840 // after the previous two children. |
586 Tab* child3 = | 841 Tab* child3 = |
587 [tab_model_ insertTabWithURL:kURL | 842 [tab_model_ insertTabWithURL:kURL |
588 referrer:kEmptyReferrer | 843 referrer:kEmptyReferrer |
589 transition:ui::PAGE_TRANSITION_LINK | 844 transition:ui::PAGE_TRANSITION_LINK |
590 opener:parent | 845 opener:parent |
(...skipping 12 matching lines...) Expand all Loading... |
603 openedByDOM:NO | 858 openedByDOM:NO |
604 atIndex:TabModelConstants::kTabPositionAutomatically | 859 atIndex:TabModelConstants::kTabPositionAutomatically |
605 inBackground:YES]; | 860 inBackground:YES]; |
606 EXPECT_EQ([tab_model_ indexOfTab:child4], 2U); | 861 EXPECT_EQ([tab_model_ indexOfTab:child4], 2U); |
607 | 862 |
608 // The first two children should have been moved to the right. | 863 // The first two children should have been moved to the right. |
609 EXPECT_EQ([tab_model_ indexOfTab:child1], 3U); | 864 EXPECT_EQ([tab_model_ indexOfTab:child1], 3U); |
610 EXPECT_EQ([tab_model_ indexOfTab:child2], 4U); | 865 EXPECT_EQ([tab_model_ indexOfTab:child2], 4U); |
611 | 866 |
612 // Now add a non-owned tab and make sure it is added at the end. | 867 // Now add a non-owned tab and make sure it is added at the end. |
613 Tab* nonChild = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 868 Tab* nonChild = [tab_model_ insertTabWithURL:kURL |
| 869 referrer:kEmptyReferrer |
| 870 transition:ui::PAGE_TRANSITION_TYPED |
| 871 opener:nil |
| 872 openedByDOM:NO |
| 873 atIndex:[tab_model_ count] |
| 874 inBackground:YES]; |
614 EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1); | 875 EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1); |
615 } | 876 } |
616 | 877 |
617 TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) { | 878 TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) { |
618 // Create a few tabs with the controller at the front. | 879 // Create a few tabs with the controller at the front. |
619 Tab* parent = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 880 Tab* parent = [tab_model_ insertTabWithURL:kURL |
| 881 referrer:kEmptyReferrer |
| 882 transition:ui::PAGE_TRANSITION_TYPED |
| 883 opener:nil |
| 884 openedByDOM:NO |
| 885 atIndex:[tab_model_ count] |
| 886 inBackground:YES]; |
620 // Force the history to update, as it is used to determine grouping. | 887 // Force the history to update, as it is used to determine grouping. |
621 ASSERT_TRUE([parent navigationManager]); | 888 ASSERT_TRUE([parent navigationManagerImpl]); |
622 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; | 889 [[parent navigationManagerImpl]->GetSessionController() commitPendingItem]; |
623 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 890 [tab_model_ insertTabWithURL:kURL |
624 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; | 891 referrer:kEmptyReferrer |
| 892 transition:ui::PAGE_TRANSITION_TYPED |
| 893 opener:nil |
| 894 openedByDOM:NO |
| 895 atIndex:[tab_model_ count] |
| 896 inBackground:YES]; |
| 897 [tab_model_ insertTabWithURL:kURL |
| 898 referrer:kEmptyReferrer |
| 899 transition:ui::PAGE_TRANSITION_TYPED |
| 900 opener:nil |
| 901 openedByDOM:NO |
| 902 atIndex:[tab_model_ count] |
| 903 inBackground:YES]; |
625 | 904 |
626 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); | 905 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); |
627 | 906 |
628 // Add a new tab, it should be added before the parent since the index | 907 // Add a new tab, it should be added before the parent since the index |
629 // parameter has been specified with a valid value. | 908 // parameter has been specified with a valid value. |
630 Tab* child1 = [tab_model_ insertTabWithURL:kURL | 909 Tab* child1 = [tab_model_ insertTabWithURL:kURL |
631 referrer:kEmptyReferrer | 910 referrer:kEmptyReferrer |
632 transition:ui::PAGE_TRANSITION_LINK | 911 transition:ui::PAGE_TRANSITION_LINK |
633 opener:parent | 912 opener:parent |
634 openedByDOM:NO | 913 openedByDOM:NO |
(...skipping 24 matching lines...) Expand all Loading... |
659 openedByDOM:NO | 938 openedByDOM:NO |
660 atIndex:1 | 939 atIndex:1 |
661 inBackground:NO]; | 940 inBackground:NO]; |
662 EXPECT_EQ([tab_model_ indexOfTab:parent], 3U); | 941 EXPECT_EQ([tab_model_ indexOfTab:parent], 3U); |
663 EXPECT_EQ([tab_model_ indexOfTab:child1], 2U); | 942 EXPECT_EQ([tab_model_ indexOfTab:child1], 2U); |
664 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); | 943 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); |
665 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); | 944 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); |
666 } | 945 } |
667 | 946 |
668 TEST_F(TabModelTest, MoveTabs) { | 947 TEST_F(TabModelTest, MoveTabs) { |
669 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 948 Tab* tab0 = [tab_model_ insertTabWithURL:kURL |
670 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 949 referrer:kReferrer |
671 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; | 950 transition:ui::PAGE_TRANSITION_TYPED |
| 951 opener:nil |
| 952 openedByDOM:NO |
| 953 atIndex:[tab_model_ count] |
| 954 inBackground:YES]; |
| 955 Tab* tab1 = [tab_model_ insertTabWithURL:kURL |
| 956 referrer:kReferrer |
| 957 transition:ui::PAGE_TRANSITION_TYPED |
| 958 opener:nil |
| 959 openedByDOM:NO |
| 960 atIndex:[tab_model_ count] |
| 961 inBackground:YES]; |
| 962 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
| 963 referrer:kReferrer |
| 964 transition:ui::PAGE_TRANSITION_TYPED |
| 965 opener:nil |
| 966 openedByDOM:NO |
| 967 atIndex:[tab_model_ count] |
| 968 inBackground:YES]; |
672 | 969 |
673 // Basic sanity checks before moving on. | 970 // Basic sanity checks before moving on. |
674 ASSERT_EQ(3U, [tab_model_ count]); | 971 ASSERT_EQ(3U, [tab_model_ count]); |
675 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); | 972 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
676 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); | 973 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
677 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); | 974 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); |
678 | 975 |
679 // Move a tab from index 1 to index 0 (move tab left by one). | 976 // Move a tab from index 1 to index 0 (move tab left by one). |
680 [tab_model_observer_ setTabMovedWasCalled:NO]; | 977 [tab_model_observer_ setTabMovedWasCalled:NO]; |
681 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0]; | 978 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0]; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 base::mac::ScopedNSAutoreleasePool pool; | 1047 base::mac::ScopedNSAutoreleasePool pool; |
751 | 1048 |
752 NSString* stashPath = | 1049 NSString* stashPath = |
753 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); | 1050 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); |
754 | 1051 |
755 base::scoped_nsobject<TabModel> model([[TabModel alloc] | 1052 base::scoped_nsobject<TabModel> model([[TabModel alloc] |
756 initWithSessionWindow:session_window_.get() | 1053 initWithSessionWindow:session_window_.get() |
757 sessionService:[SessionServiceIOS sharedService] | 1054 sessionService:[SessionServiceIOS sharedService] |
758 browserState:chrome_browser_state.get()]); | 1055 browserState:chrome_browser_state.get()]); |
759 | 1056 |
760 [model addTabWithURL:kURL referrer:kReferrer]; | |
761 [model insertTabWithURL:kURL | 1057 [model insertTabWithURL:kURL |
762 referrer:kReferrer | 1058 referrer:kReferrer |
763 opener:[model tabAtIndex:0] | 1059 transition:ui::PAGE_TRANSITION_TYPED |
764 atIndex:[model count]]; | 1060 opener:nil |
| 1061 openedByDOM:NO |
| 1062 atIndex:[model count] |
| 1063 inBackground:YES]; |
765 [model insertTabWithURL:kURL | 1064 [model insertTabWithURL:kURL |
766 referrer:kReferrer | 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 |
767 opener:[model tabAtIndex:1] | 1074 opener:[model tabAtIndex:1] |
768 atIndex:0]; | 1075 openedByDOM:NO |
| 1076 atIndex:0 |
| 1077 inBackground:YES]; |
769 | 1078 |
770 ASSERT_EQ(3U, [model count]); | 1079 ASSERT_EQ(3U, [model count]); |
771 [model setCurrentTab:[model tabAtIndex:1]]; | 1080 [model setCurrentTab:[model tabAtIndex:1]]; |
772 | 1081 |
773 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); | 1082 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); |
774 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); | 1083 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); |
775 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); | 1084 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); |
776 | 1085 |
777 // Force state to flush to disk on the main thread so it can be immediately | 1086 // Force state to flush to disk on the main thread so it can be immediately |
778 // tested below. | 1087 // tested below. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 // Restoring TabModel session sends asynchronous tasks to IO thread, wait | 1119 // Restoring TabModel session sends asynchronous tasks to IO thread, wait |
811 // for them to complete after destroying the TabModel. | 1120 // for them to complete after destroying the TabModel. |
812 base::RunLoop().RunUntilIdle(); | 1121 base::RunLoop().RunUntilIdle(); |
813 | 1122 |
814 // Clean up. | 1123 // Clean up. |
815 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath | 1124 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath |
816 error:nullptr]); | 1125 error:nullptr]); |
817 } | 1126 } |
818 | 1127 |
819 } // anonymous namespace | 1128 } // anonymous namespace |
OLD | NEW |