OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 RegisterForAllNavNotifications(¬ifications, &controller); | 310 RegisterForAllNavNotifications(¬ifications, &controller); |
311 | 311 |
312 const int kNumUrls = 5; | 312 const int kNumUrls = 5; |
313 std::vector<GURL> urls(kNumUrls); | 313 std::vector<GURL> urls(kNumUrls); |
314 for (int i = 0; i < kNumUrls; ++i) { | 314 for (int i = 0; i < kNumUrls; ++i) { |
315 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 315 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
316 } | 316 } |
317 | 317 |
318 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); | 318 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); |
319 main_test_rfh()->PrepareForCommit(); | 319 main_test_rfh()->PrepareForCommit(); |
320 main_test_rfh()->SendNavigate(0, urls[0]); | 320 main_test_rfh()->SendNavigate(0, 0, true, urls[0]); |
321 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 321 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
322 navigation_entry_committed_counter_ = 0; | 322 navigation_entry_committed_counter_ = 0; |
323 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); | 323 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
324 EXPECT_FALSE(controller.CanGoBack()); | 324 EXPECT_FALSE(controller.CanGoBack()); |
325 EXPECT_FALSE(controller.CanGoForward()); | 325 EXPECT_FALSE(controller.CanGoForward()); |
326 EXPECT_FALSE(controller.CanGoToOffset(1)); | 326 EXPECT_FALSE(controller.CanGoToOffset(1)); |
327 | 327 |
328 for (int i = 1; i <= 4; ++i) { | 328 for (int i = 1; i <= 4; ++i) { |
329 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); | 329 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); |
330 main_test_rfh()->PrepareForCommit(); | 330 main_test_rfh()->PrepareForCommit(); |
331 main_test_rfh()->SendNavigate(i, urls[i]); | 331 main_test_rfh()->SendNavigate(i, 0, true, urls[i]); |
332 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 332 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
333 navigation_entry_committed_counter_ = 0; | 333 navigation_entry_committed_counter_ = 0; |
334 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); | 334 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
335 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 335 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
336 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 336 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
337 EXPECT_FALSE(controller.CanGoToOffset(1)); | 337 EXPECT_FALSE(controller.CanGoToOffset(1)); |
338 } | 338 } |
339 | 339 |
340 // We have loaded 5 pages, and are currently at the last-loaded page. | 340 // We have loaded 5 pages, and are currently at the last-loaded page. |
341 int url_index = 4; | 341 int url_index = 4; |
(...skipping 11 matching lines...) Expand all Loading... |
353 GO_TO_MIDDLE_PAGE, | 353 GO_TO_MIDDLE_PAGE, |
354 GO_FORWARDS, | 354 GO_FORWARDS, |
355 GO_BACKWARDS, | 355 GO_BACKWARDS, |
356 GO_TO_BEGINNING, | 356 GO_TO_BEGINNING, |
357 GO_TO_END | 357 GO_TO_END |
358 }; | 358 }; |
359 | 359 |
360 for (int test = 0; test < NUM_TESTS; ++test) { | 360 for (int test = 0; test < NUM_TESTS; ++test) { |
361 int offset = test_offsets[test]; | 361 int offset = test_offsets[test]; |
362 controller.GoToOffset(offset); | 362 controller.GoToOffset(offset); |
| 363 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
363 url_index += offset; | 364 url_index += offset; |
364 // Check that the GoToOffset will land on the expected page. | 365 // Check that the GoToOffset will land on the expected page. |
365 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 366 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
366 main_test_rfh()->PrepareForCommit(); | 367 main_test_rfh()->PrepareForCommit(); |
367 main_test_rfh()->SendNavigate(url_index, urls[url_index]); | 368 main_test_rfh()->SendNavigate(url_index, entry_id, false, urls[url_index]); |
368 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 369 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
369 navigation_entry_committed_counter_ = 0; | 370 navigation_entry_committed_counter_ = 0; |
370 // Check that we can go to any valid offset into the history. | 371 // Check that we can go to any valid offset into the history. |
371 for (size_t j = 0; j < urls.size(); ++j) | 372 for (size_t j = 0; j < urls.size(); ++j) |
372 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 373 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
373 // Check that we can't go beyond the beginning or end of the history. | 374 // Check that we can't go beyond the beginning or end of the history. |
374 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 375 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
375 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 376 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
376 } | 377 } |
377 } | 378 } |
378 | 379 |
379 TEST_F(NavigationControllerTest, LoadURL) { | 380 TEST_F(NavigationControllerTest, LoadURL) { |
380 NavigationControllerImpl& controller = controller_impl(); | 381 NavigationControllerImpl& controller = controller_impl(); |
381 TestNotificationTracker notifications; | 382 TestNotificationTracker notifications; |
382 RegisterForAllNavNotifications(¬ifications, &controller); | 383 RegisterForAllNavNotifications(¬ifications, &controller); |
383 | 384 |
384 const GURL url1("http://foo1"); | 385 const GURL url1("http://foo1"); |
385 const GURL url2("http://foo2"); | 386 const GURL url2("http://foo2"); |
386 | 387 |
387 controller.LoadURL( | 388 controller.LoadURL( |
388 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 389 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 390 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
389 // Creating a pending notification should not have issued any of the | 391 // Creating a pending notification should not have issued any of the |
390 // notifications we're listening for. | 392 // notifications we're listening for. |
391 EXPECT_EQ(0U, notifications.size()); | 393 EXPECT_EQ(0U, notifications.size()); |
392 | 394 |
393 // The load should now be pending. | 395 // The load should now be pending. |
394 EXPECT_EQ(controller.GetEntryCount(), 0); | 396 EXPECT_EQ(controller.GetEntryCount(), 0); |
395 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); | 397 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), -1); |
396 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 398 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
397 EXPECT_FALSE(controller.GetLastCommittedEntry()); | 399 EXPECT_FALSE(controller.GetLastCommittedEntry()); |
398 ASSERT_TRUE(controller.GetPendingEntry()); | 400 ASSERT_TRUE(controller.GetPendingEntry()); |
399 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 401 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
400 EXPECT_FALSE(controller.CanGoBack()); | 402 EXPECT_FALSE(controller.CanGoBack()); |
401 EXPECT_FALSE(controller.CanGoForward()); | 403 EXPECT_FALSE(controller.CanGoForward()); |
402 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 404 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
403 | 405 |
404 // Neither the timestamp nor the status code should have been set yet. | 406 // Neither the timestamp nor the status code should have been set yet. |
405 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 407 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
406 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 408 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
407 | 409 |
408 // We should have gotten no notifications from the preceeding checks. | 410 // We should have gotten no notifications from the preceeding checks. |
409 EXPECT_EQ(0U, notifications.size()); | 411 EXPECT_EQ(0U, notifications.size()); |
410 | 412 |
411 main_test_rfh()->PrepareForCommit(); | 413 main_test_rfh()->PrepareForCommit(); |
412 main_test_rfh()->SendNavigate(0, url1); | 414 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
413 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 415 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
414 navigation_entry_committed_counter_ = 0; | 416 navigation_entry_committed_counter_ = 0; |
415 | 417 |
416 // The load should now be committed. | 418 // The load should now be committed. |
417 EXPECT_EQ(controller.GetEntryCount(), 1); | 419 EXPECT_EQ(controller.GetEntryCount(), 1); |
418 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 420 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
419 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 421 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
420 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 422 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
421 EXPECT_FALSE(controller.GetPendingEntry()); | 423 EXPECT_FALSE(controller.GetPendingEntry()); |
422 ASSERT_TRUE(controller.GetVisibleEntry()); | 424 ASSERT_TRUE(controller.GetVisibleEntry()); |
423 EXPECT_FALSE(controller.CanGoBack()); | 425 EXPECT_FALSE(controller.CanGoBack()); |
424 EXPECT_FALSE(controller.CanGoForward()); | 426 EXPECT_FALSE(controller.CanGoForward()); |
425 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 427 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
426 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 428 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
427 | 429 |
428 // The timestamp should have been set. | 430 // The timestamp should have been set. |
429 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); | 431 EXPECT_FALSE(controller.GetVisibleEntry()->GetTimestamp().is_null()); |
430 | 432 |
431 // Load another... | 433 // Load another... |
432 controller.LoadURL( | 434 controller.LoadURL( |
433 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 435 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 436 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
434 | 437 |
435 // The load should now be pending. | 438 // The load should now be pending. |
436 EXPECT_EQ(controller.GetEntryCount(), 1); | 439 EXPECT_EQ(controller.GetEntryCount(), 1); |
437 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 440 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
438 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 441 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
439 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 442 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
440 ASSERT_TRUE(controller.GetPendingEntry()); | 443 ASSERT_TRUE(controller.GetPendingEntry()); |
441 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 444 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
442 // TODO(darin): maybe this should really be true? | 445 // TODO(darin): maybe this should really be true? |
443 EXPECT_FALSE(controller.CanGoBack()); | 446 EXPECT_FALSE(controller.CanGoBack()); |
444 EXPECT_FALSE(controller.CanGoForward()); | 447 EXPECT_FALSE(controller.CanGoForward()); |
445 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 448 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
446 | 449 |
447 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 450 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
448 | 451 |
449 // Simulate the beforeunload ack for the cross-site transition, and then the | 452 // Simulate the beforeunload ack for the cross-site transition, and then the |
450 // commit. | 453 // commit. |
451 main_test_rfh()->PrepareForCommit(); | 454 main_test_rfh()->PrepareForCommit(); |
452 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 455 contents()->GetPendingMainFrame()->SendNavigate(1, entry_id, true, url2); |
453 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 456 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
454 navigation_entry_committed_counter_ = 0; | 457 navigation_entry_committed_counter_ = 0; |
455 | 458 |
456 // The load should now be committed. | 459 // The load should now be committed. |
457 EXPECT_EQ(controller.GetEntryCount(), 2); | 460 EXPECT_EQ(controller.GetEntryCount(), 2); |
458 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 461 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
459 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 462 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
460 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 463 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
461 EXPECT_FALSE(controller.GetPendingEntry()); | 464 EXPECT_FALSE(controller.GetPendingEntry()); |
462 ASSERT_TRUE(controller.GetVisibleEntry()); | 465 ASSERT_TRUE(controller.GetVisibleEntry()); |
(...skipping 19 matching lines...) Expand all Loading... |
482 | 485 |
483 // Set the clock to always return a timestamp of 1. | 486 // Set the clock to always return a timestamp of 1. |
484 controller.SetGetTimestampCallbackForTest( | 487 controller.SetGetTimestampCallbackForTest( |
485 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 488 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
486 | 489 |
487 const GURL url1("http://foo1"); | 490 const GURL url1("http://foo1"); |
488 const GURL url2("http://foo2"); | 491 const GURL url2("http://foo2"); |
489 | 492 |
490 controller.LoadURL( | 493 controller.LoadURL( |
491 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 494 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 495 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
492 | 496 |
493 main_test_rfh()->PrepareForCommit(); | 497 main_test_rfh()->PrepareForCommit(); |
494 main_test_rfh()->SendNavigate(0, url1); | 498 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
495 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 499 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
496 navigation_entry_committed_counter_ = 0; | 500 navigation_entry_committed_counter_ = 0; |
497 | 501 |
498 // Load another... | 502 // Load another... |
499 controller.LoadURL( | 503 controller.LoadURL( |
500 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 504 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 505 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
501 | 506 |
502 // Simulate the beforeunload ack for the cross-site transition, and then the | 507 // Simulate the beforeunload ack for the cross-site transition, and then the |
503 // commit. | 508 // commit. |
504 main_test_rfh()->PrepareForCommit(); | 509 main_test_rfh()->PrepareForCommit(); |
505 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 510 contents()->GetPendingMainFrame()->SendNavigate(1, entry_id, true, url2); |
506 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 511 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
507 navigation_entry_committed_counter_ = 0; | 512 navigation_entry_committed_counter_ = 0; |
508 | 513 |
509 // The two loads should now be committed. | 514 // The two loads should now be committed. |
510 ASSERT_EQ(controller.GetEntryCount(), 2); | 515 ASSERT_EQ(controller.GetEntryCount(), 2); |
511 | 516 |
512 // Timestamps should be distinct despite the clock returning the | 517 // Timestamps should be distinct despite the clock returning the |
513 // same value. | 518 // same value. |
514 EXPECT_EQ(1u, | 519 EXPECT_EQ(1u, |
515 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); | 520 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 // the load commits (because WebCore didn't actually make a new entry). | 617 // the load commits (because WebCore didn't actually make a new entry). |
613 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 618 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
614 NavigationControllerImpl& controller = controller_impl(); | 619 NavigationControllerImpl& controller = controller_impl(); |
615 TestNotificationTracker notifications; | 620 TestNotificationTracker notifications; |
616 RegisterForAllNavNotifications(¬ifications, &controller); | 621 RegisterForAllNavNotifications(¬ifications, &controller); |
617 | 622 |
618 const GURL url1("http://foo1"); | 623 const GURL url1("http://foo1"); |
619 | 624 |
620 controller.LoadURL( | 625 controller.LoadURL( |
621 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 626 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 627 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
622 EXPECT_EQ(0U, notifications.size()); | 628 EXPECT_EQ(0U, notifications.size()); |
623 main_test_rfh()->PrepareForCommit(); | 629 main_test_rfh()->PrepareForCommit(); |
624 main_test_rfh()->SendNavigate(0, url1); | 630 main_test_rfh()->SendNavigateWithTransition( |
| 631 0, entry_id, true, url1, ui::PAGE_TRANSITION_TYPED); |
625 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 632 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
626 navigation_entry_committed_counter_ = 0; | 633 navigation_entry_committed_counter_ = 0; |
627 | 634 |
628 ASSERT_TRUE(controller.GetVisibleEntry()); | 635 ASSERT_TRUE(controller.GetVisibleEntry()); |
629 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 636 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
630 EXPECT_FALSE(timestamp.is_null()); | 637 EXPECT_FALSE(timestamp.is_null()); |
631 | 638 |
632 controller.LoadURL( | 639 controller.LoadURL( |
633 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 640 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 641 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
634 EXPECT_EQ(0U, notifications.size()); | 642 EXPECT_EQ(0U, notifications.size()); |
635 main_test_rfh()->PrepareForCommit(); | 643 main_test_rfh()->PrepareForCommit(); |
636 main_test_rfh()->SendNavigate(0, url1); | 644 main_test_rfh()->SendNavigateWithTransition( |
| 645 0, entry_id, false, url1, ui::PAGE_TRANSITION_TYPED); |
637 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 646 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
638 navigation_entry_committed_counter_ = 0; | 647 navigation_entry_committed_counter_ = 0; |
639 | 648 |
640 // We should not have produced a new session history entry. | 649 // We should not have produced a new session history entry. |
641 EXPECT_EQ(controller.GetEntryCount(), 1); | 650 EXPECT_EQ(controller.GetEntryCount(), 1); |
642 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 651 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
643 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 652 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
644 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 653 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
645 EXPECT_FALSE(controller.GetPendingEntry()); | 654 EXPECT_FALSE(controller.GetPendingEntry()); |
646 ASSERT_TRUE(controller.GetVisibleEntry()); | 655 ASSERT_TRUE(controller.GetVisibleEntry()); |
(...skipping 13 matching lines...) Expand all Loading... |
660 NavigationControllerImpl& controller = controller_impl(); | 669 NavigationControllerImpl& controller = controller_impl(); |
661 TestNotificationTracker notifications; | 670 TestNotificationTracker notifications; |
662 RegisterForAllNavNotifications(¬ifications, &controller); | 671 RegisterForAllNavNotifications(¬ifications, &controller); |
663 | 672 |
664 const GURL url1("http://foo1"); | 673 const GURL url1("http://foo1"); |
665 | 674 |
666 controller.LoadURL( | 675 controller.LoadURL( |
667 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 676 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
668 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 677 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
669 params.page_id = 0; | 678 params.page_id = 0; |
| 679 params.nav_entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 680 params.did_create_new_entry = true; |
670 params.url = url1; | 681 params.url = url1; |
671 params.transition = ui::PAGE_TRANSITION_TYPED; | 682 params.transition = ui::PAGE_TRANSITION_TYPED; |
672 params.is_post = true; | 683 params.is_post = true; |
673 params.post_id = 123; | 684 params.post_id = 123; |
674 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); | 685 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); |
675 main_test_rfh()->PrepareForCommit(); | 686 main_test_rfh()->PrepareForCommit(); |
676 main_test_rfh()->SendNavigateWithParams(¶ms); | 687 main_test_rfh()->SendNavigateWithParams(¶ms); |
677 | 688 |
678 // The post data should be visible. | 689 // The post data should be visible. |
679 NavigationEntry* entry = controller.GetVisibleEntry(); | 690 NavigationEntry* entry = controller.GetVisibleEntry(); |
680 ASSERT_TRUE(entry); | 691 ASSERT_TRUE(entry); |
681 EXPECT_TRUE(entry->GetHasPostData()); | 692 EXPECT_TRUE(entry->GetHasPostData()); |
682 EXPECT_EQ(entry->GetPostID(), 123); | 693 EXPECT_EQ(entry->GetPostID(), 123); |
683 | 694 |
684 controller.LoadURL( | 695 controller.LoadURL( |
685 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 696 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
686 main_test_rfh()->PrepareForCommit(); | 697 main_test_rfh()->PrepareForCommit(); |
687 main_test_rfh()->SendNavigate(0, url1); | 698 main_test_rfh()->SendNavigateWithTransition( |
| 699 0, controller.GetPendingEntry()->GetUniqueID(), |
| 700 false, url1, ui::PAGE_TRANSITION_TYPED); |
688 | 701 |
689 // We should not have produced a new session history entry. | 702 // We should not have produced a new session history entry. |
690 ASSERT_EQ(controller.GetVisibleEntry(), entry); | 703 ASSERT_EQ(controller.GetVisibleEntry(), entry); |
691 | 704 |
692 // The post data should have been cleared due to the GET. | 705 // The post data should have been cleared due to the GET. |
693 EXPECT_FALSE(entry->GetHasPostData()); | 706 EXPECT_FALSE(entry->GetHasPostData()); |
694 EXPECT_EQ(entry->GetPostID(), 0); | 707 EXPECT_EQ(entry->GetPostID(), 0); |
695 } | 708 } |
696 | 709 |
697 // Tests loading a URL but discarding it before the load commits. | 710 // Tests loading a URL but discarding it before the load commits. |
698 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 711 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
699 NavigationControllerImpl& controller = controller_impl(); | 712 NavigationControllerImpl& controller = controller_impl(); |
700 TestNotificationTracker notifications; | 713 TestNotificationTracker notifications; |
701 RegisterForAllNavNotifications(¬ifications, &controller); | 714 RegisterForAllNavNotifications(¬ifications, &controller); |
702 | 715 |
703 const GURL url1("http://foo1"); | 716 const GURL url1("http://foo1"); |
704 const GURL url2("http://foo2"); | 717 const GURL url2("http://foo2"); |
705 | 718 |
706 controller.LoadURL( | 719 controller.LoadURL( |
707 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 720 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 721 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
708 EXPECT_EQ(0U, notifications.size()); | 722 EXPECT_EQ(0U, notifications.size()); |
709 main_test_rfh()->PrepareForCommit(); | 723 main_test_rfh()->PrepareForCommit(); |
710 main_test_rfh()->SendNavigate(0, url1); | 724 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
711 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 725 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
712 navigation_entry_committed_counter_ = 0; | 726 navigation_entry_committed_counter_ = 0; |
713 | 727 |
714 ASSERT_TRUE(controller.GetVisibleEntry()); | 728 ASSERT_TRUE(controller.GetVisibleEntry()); |
715 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 729 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
716 EXPECT_FALSE(timestamp.is_null()); | 730 EXPECT_FALSE(timestamp.is_null()); |
717 | 731 |
718 controller.LoadURL( | 732 controller.LoadURL( |
719 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 733 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
720 controller.DiscardNonCommittedEntries(); | 734 controller.DiscardNonCommittedEntries(); |
(...skipping 17 matching lines...) Expand all Loading... |
738 // navigates from the web page, and here we test that there is no pending entry. | 752 // navigates from the web page, and here we test that there is no pending entry. |
739 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 753 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
740 NavigationControllerImpl& controller = controller_impl(); | 754 NavigationControllerImpl& controller = controller_impl(); |
741 TestNotificationTracker notifications; | 755 TestNotificationTracker notifications; |
742 RegisterForAllNavNotifications(¬ifications, &controller); | 756 RegisterForAllNavNotifications(¬ifications, &controller); |
743 | 757 |
744 // First make an existing committed entry. | 758 // First make an existing committed entry. |
745 const GURL kExistingURL1("http://eh"); | 759 const GURL kExistingURL1("http://eh"); |
746 controller.LoadURL( | 760 controller.LoadURL( |
747 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 761 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 762 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
748 main_test_rfh()->PrepareForCommit(); | 763 main_test_rfh()->PrepareForCommit(); |
749 main_test_rfh()->SendNavigate(0, kExistingURL1); | 764 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
750 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 765 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
751 navigation_entry_committed_counter_ = 0; | 766 navigation_entry_committed_counter_ = 0; |
752 | 767 |
753 // Do a new navigation without making a pending one. | 768 // Do a new navigation without making a pending one. |
754 const GURL kNewURL("http://see"); | 769 const GURL kNewURL("http://see"); |
755 main_test_rfh()->NavigateAndCommitRendererInitiated(99, kNewURL); | 770 main_test_rfh()->NavigateAndCommitRendererInitiated(99, true, kNewURL); |
756 | 771 |
757 // There should no longer be any pending entry, and the third navigation we | 772 // There should no longer be any pending entry, and the second navigation we |
758 // just made should be committed. | 773 // just made should be committed. |
759 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 774 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
760 navigation_entry_committed_counter_ = 0; | 775 navigation_entry_committed_counter_ = 0; |
761 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 776 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
762 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 777 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
763 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 778 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
764 } | 779 } |
765 | 780 |
766 // Tests navigating to a new URL when there is a new pending navigation that is | 781 // Tests navigating to a new URL when there is a new pending navigation that is |
767 // not the one that just loaded. This will happen if the user types in a URL to | 782 // not the one that just loaded. This will happen if the user types in a URL to |
768 // somewhere slow, and then navigates the current page before the typed URL | 783 // somewhere slow, and then navigates the current page before the typed URL |
769 // commits. | 784 // commits. |
770 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 785 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
771 NavigationControllerImpl& controller = controller_impl(); | 786 NavigationControllerImpl& controller = controller_impl(); |
772 TestNotificationTracker notifications; | 787 TestNotificationTracker notifications; |
773 RegisterForAllNavNotifications(¬ifications, &controller); | 788 RegisterForAllNavNotifications(¬ifications, &controller); |
774 | 789 |
775 // First make an existing committed entry. | 790 // First make an existing committed entry. |
776 const GURL kExistingURL1("http://eh"); | 791 const GURL kExistingURL1("http://eh"); |
777 controller.LoadURL( | 792 controller.LoadURL( |
778 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 793 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 794 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
779 main_test_rfh()->PrepareForCommit(); | 795 main_test_rfh()->PrepareForCommit(); |
780 main_test_rfh()->SendNavigate(0, kExistingURL1); | 796 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
781 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 797 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
782 navigation_entry_committed_counter_ = 0; | 798 navigation_entry_committed_counter_ = 0; |
783 | 799 |
784 // Make a pending entry to somewhere new. | 800 // Make a pending entry to somewhere new. |
785 const GURL kExistingURL2("http://bee"); | 801 const GURL kExistingURL2("http://bee"); |
786 controller.LoadURL( | 802 controller.LoadURL( |
787 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 803 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
788 EXPECT_EQ(0U, notifications.size()); | 804 EXPECT_EQ(0U, notifications.size()); |
789 | 805 |
790 // After the beforeunload but before it commits... | 806 // After the beforeunload but before it commits... |
791 main_test_rfh()->PrepareForCommit(); | 807 main_test_rfh()->PrepareForCommit(); |
792 | 808 |
793 // ... Do a new navigation. | 809 // ... Do a new navigation. |
794 const GURL kNewURL("http://see"); | 810 const GURL kNewURL("http://see"); |
795 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); | 811 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); |
796 main_test_rfh()->PrepareForCommit(); | 812 main_test_rfh()->PrepareForCommit(); |
797 contents()->GetMainFrame()->SendNavigate(3, kNewURL); | 813 contents()->GetMainFrame()->SendNavigate(3, 0, true, kNewURL); |
798 | 814 |
799 // There should no longer be any pending entry, and the third navigation we | 815 // There should no longer be any pending entry, and the third navigation we |
800 // just made should be committed. | 816 // just made should be committed. |
801 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 817 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
802 navigation_entry_committed_counter_ = 0; | 818 navigation_entry_committed_counter_ = 0; |
803 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 819 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
804 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 820 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
805 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 821 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
806 } | 822 } |
807 | 823 |
808 // Tests navigating to a new URL when there is a pending back/forward | 824 // Tests navigating to a new URL when there is a pending back/forward |
809 // navigation. This will happen if the user hits back, but before that commits, | 825 // navigation. This will happen if the user hits back, but before that commits, |
810 // they navigate somewhere new. | 826 // they navigate somewhere new. |
811 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 827 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
812 NavigationControllerImpl& controller = controller_impl(); | 828 NavigationControllerImpl& controller = controller_impl(); |
813 TestNotificationTracker notifications; | 829 TestNotificationTracker notifications; |
814 RegisterForAllNavNotifications(¬ifications, &controller); | 830 RegisterForAllNavNotifications(¬ifications, &controller); |
815 | 831 |
816 // First make some history. | 832 // First make some history. |
817 const GURL kExistingURL1("http://foo/eh"); | 833 const GURL kExistingURL1("http://foo/eh"); |
818 controller.LoadURL( | 834 controller.LoadURL( |
819 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 835 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 836 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
820 main_test_rfh()->PrepareForCommit(); | 837 main_test_rfh()->PrepareForCommit(); |
821 main_test_rfh()->SendNavigate(0, kExistingURL1); | 838 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
822 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 839 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
823 navigation_entry_committed_counter_ = 0; | 840 navigation_entry_committed_counter_ = 0; |
824 | 841 |
825 const GURL kExistingURL2("http://foo/bee"); | 842 const GURL kExistingURL2("http://foo/bee"); |
826 controller.LoadURL( | 843 controller.LoadURL( |
827 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 844 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 845 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
828 main_test_rfh()->PrepareForCommit(); | 846 main_test_rfh()->PrepareForCommit(); |
829 main_test_rfh()->SendNavigate(1, kExistingURL2); | 847 main_test_rfh()->SendNavigate(1, entry_id, true, kExistingURL2); |
830 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 848 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
831 navigation_entry_committed_counter_ = 0; | 849 navigation_entry_committed_counter_ = 0; |
832 | 850 |
833 // Now make a pending back/forward navigation. The zeroth entry should be | 851 // Now make a pending back/forward navigation. The zeroth entry should be |
834 // pending. | 852 // pending. |
835 controller.GoBack(); | 853 controller.GoBack(); |
836 EXPECT_EQ(0U, notifications.size()); | 854 EXPECT_EQ(0U, notifications.size()); |
837 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 855 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
838 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 856 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
839 | 857 |
840 // Before that commits, do a new navigation. | 858 // Before that commits, do a new navigation. |
841 const GURL kNewURL("http://foo/see"); | 859 const GURL kNewURL("http://foo/see"); |
842 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); | 860 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); |
843 main_test_rfh()->PrepareForCommit(); | 861 main_test_rfh()->PrepareForCommit(); |
844 main_test_rfh()->SendNavigate(3, kNewURL); | 862 main_test_rfh()->SendNavigate(3, 0, true, kNewURL); |
845 | 863 |
846 // There should no longer be any pending entry, and the third navigation we | 864 // There should no longer be any pending entry, and the new navigation we |
847 // just made should be committed. | 865 // just made should be committed. |
848 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 866 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
849 navigation_entry_committed_counter_ = 0; | 867 navigation_entry_committed_counter_ = 0; |
850 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 868 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
851 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 869 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
852 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 870 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
853 } | 871 } |
854 | 872 |
855 // Tests navigating to a new URL when there is a pending back/forward | 873 // Tests navigating to a new URL when there is a pending back/forward |
856 // navigation to a cross-process, privileged URL. This will happen if the user | 874 // navigation to a cross-process, privileged URL. This will happen if the user |
857 // hits back, but before that commits, they navigate somewhere new. | 875 // hits back, but before that commits, they navigate somewhere new. |
858 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { | 876 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { |
859 NavigationControllerImpl& controller = controller_impl(); | 877 NavigationControllerImpl& controller = controller_impl(); |
860 TestNotificationTracker notifications; | 878 TestNotificationTracker notifications; |
861 RegisterForAllNavNotifications(¬ifications, &controller); | 879 RegisterForAllNavNotifications(¬ifications, &controller); |
862 | 880 |
863 // First make some history, starting with a privileged URL. | 881 // First make some history, starting with a privileged URL. |
864 const GURL kExistingURL1("http://privileged"); | 882 const GURL kExistingURL1("http://privileged"); |
865 controller.LoadURL( | 883 controller.LoadURL( |
866 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 884 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 885 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
867 // Pretend it has bindings so we can tell if we incorrectly copy it. | 886 // Pretend it has bindings so we can tell if we incorrectly copy it. |
868 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); | 887 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); |
869 main_test_rfh()->PrepareForCommit(); | 888 main_test_rfh()->PrepareForCommit(); |
870 main_test_rfh()->SendNavigate(0, kExistingURL1); | 889 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
871 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 890 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
872 navigation_entry_committed_counter_ = 0; | 891 navigation_entry_committed_counter_ = 0; |
873 | 892 |
874 // Navigate cross-process to a second URL. | 893 // Navigate cross-process to a second URL. |
875 const GURL kExistingURL2("http://foo/eh"); | 894 const GURL kExistingURL2("http://foo/eh"); |
876 controller.LoadURL( | 895 controller.LoadURL( |
877 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 896 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 897 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
878 main_test_rfh()->PrepareForCommit(); | 898 main_test_rfh()->PrepareForCommit(); |
879 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); | 899 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); |
880 foo_rfh->SendNavigate(1, kExistingURL2); | 900 foo_rfh->SendNavigate(1, entry_id, true, kExistingURL2); |
881 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 901 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
882 navigation_entry_committed_counter_ = 0; | 902 navigation_entry_committed_counter_ = 0; |
883 | 903 |
884 // Now make a pending back/forward navigation to a privileged entry. | 904 // Now make a pending back/forward navigation to a privileged entry. |
885 // The zeroth entry should be pending. | 905 // The zeroth entry should be pending. |
886 controller.GoBack(); | 906 controller.GoBack(); |
887 foo_rfh->SendBeforeUnloadACK(true); | 907 foo_rfh->SendBeforeUnloadACK(true); |
888 EXPECT_EQ(0U, notifications.size()); | 908 EXPECT_EQ(0U, notifications.size()); |
889 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 909 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
890 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 910 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
891 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); | 911 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); |
892 | 912 |
893 // Before that commits, do a new navigation. | 913 // Before that commits, do a new navigation. |
894 const GURL kNewURL("http://foo/bee"); | 914 const GURL kNewURL("http://foo/bee"); |
895 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); | 915 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); |
896 foo_rfh->PrepareForCommit(); | 916 foo_rfh->PrepareForCommit(); |
897 foo_rfh->SendNavigate(3, kNewURL); | 917 foo_rfh->SendNavigate(3, 0, true, kNewURL); |
898 | 918 |
899 // There should no longer be any pending entry, and the third navigation we | 919 // There should no longer be any pending entry, and the new navigation we |
900 // just made should be committed. | 920 // just made should be committed. |
901 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 921 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
902 navigation_entry_committed_counter_ = 0; | 922 navigation_entry_committed_counter_ = 0; |
903 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 923 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
904 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 924 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
905 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 925 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
906 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 926 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
907 } | 927 } |
908 | 928 |
909 // Tests navigating to an existing URL when there is a pending new navigation. | 929 // Tests navigating to an existing URL when there is a pending new navigation. |
910 // This will happen if the user enters a URL, but before that commits, the | 930 // This will happen if the user enters a URL, but before that commits, the |
911 // current page fires history.back(). | 931 // current page fires history.back(). |
912 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 932 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
913 NavigationControllerImpl& controller = controller_impl(); | 933 NavigationControllerImpl& controller = controller_impl(); |
914 TestNotificationTracker notifications; | 934 TestNotificationTracker notifications; |
915 RegisterForAllNavNotifications(¬ifications, &controller); | 935 RegisterForAllNavNotifications(¬ifications, &controller); |
916 | 936 |
917 // First make some history. | 937 // First make some history. |
918 const GURL kExistingURL1("http://foo/eh"); | 938 const GURL kExistingURL1("http://foo/eh"); |
919 controller.LoadURL( | 939 controller.LoadURL( |
920 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 940 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 941 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
921 main_test_rfh()->PrepareForCommit(); | 942 main_test_rfh()->PrepareForCommit(); |
922 main_test_rfh()->SendNavigate(0, kExistingURL1); | 943 main_test_rfh()->SendNavigate(0, entry_id, true, kExistingURL1); |
923 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 944 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
924 navigation_entry_committed_counter_ = 0; | 945 navigation_entry_committed_counter_ = 0; |
925 | 946 |
926 const GURL kExistingURL2("http://foo/bee"); | 947 const GURL kExistingURL2("http://foo/bee"); |
927 controller.LoadURL( | 948 controller.LoadURL( |
928 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 949 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 950 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
929 main_test_rfh()->PrepareForCommit(); | 951 main_test_rfh()->PrepareForCommit(); |
930 main_test_rfh()->SendNavigate(1, kExistingURL2); | 952 main_test_rfh()->SendNavigate(1, entry_id, true, kExistingURL2); |
931 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 953 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
932 navigation_entry_committed_counter_ = 0; | 954 navigation_entry_committed_counter_ = 0; |
933 | 955 |
934 // A back navigation comes in from the renderer... | 956 // A back navigation comes in from the renderer... |
935 controller.GoToOffset(-1); | 957 controller.GoToOffset(-1); |
| 958 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
936 | 959 |
937 // ...while the user tries to navigate to a new page... | 960 // ...while the user tries to navigate to a new page... |
938 const GURL kNewURL("http://foo/see"); | 961 const GURL kNewURL("http://foo/see"); |
939 controller.LoadURL( | 962 controller.LoadURL( |
940 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 963 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
941 EXPECT_EQ(0U, notifications.size()); | 964 EXPECT_EQ(0U, notifications.size()); |
942 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 965 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
943 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 966 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
944 | 967 |
945 // ...and the back navigation commits. | 968 // ...and the back navigation commits. |
946 main_test_rfh()->PrepareForCommit(); | 969 main_test_rfh()->PrepareForCommit(); |
947 main_test_rfh()->SendNavigate(0, kExistingURL1); | 970 main_test_rfh()->SendNavigate(0, entry_id, false, kExistingURL1); |
948 | 971 |
949 // There should no longer be any pending entry, and the back navigation should | 972 // There should no longer be any pending entry, and the back navigation should |
950 // be committed. | 973 // be committed. |
951 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 974 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
952 navigation_entry_committed_counter_ = 0; | 975 navigation_entry_committed_counter_ = 0; |
953 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 976 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
954 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 977 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
955 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); | 978 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
956 } | 979 } |
957 | 980 |
(...skipping 17 matching lines...) Expand all Loading... |
975 const GURL kNewURL("http://eh"); | 998 const GURL kNewURL("http://eh"); |
976 controller.LoadURL( | 999 controller.LoadURL( |
977 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1000 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
978 EXPECT_EQ(0U, notifications.size()); | 1001 EXPECT_EQ(0U, notifications.size()); |
979 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1002 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
980 EXPECT_TRUE(controller.GetPendingEntry()); | 1003 EXPECT_TRUE(controller.GetPendingEntry()); |
981 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1004 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
982 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 1005 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
983 | 1006 |
984 // Before that commits, a document.write and location.reload can cause the | 1007 // Before that commits, a document.write and location.reload can cause the |
985 // renderer to send a FrameNavigate with page_id -1. | 1008 // renderer to send a FrameNavigate with page_id -1 and nav_entry_id 0. |
986 // PlzNavigate: this will stop the old navigation and start a new one. | 1009 // PlzNavigate: this will stop the old navigation and start a new one. |
987 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); | 1010 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); |
988 main_test_rfh()->PrepareForCommit(); | 1011 main_test_rfh()->PrepareForCommit(); |
989 main_test_rfh()->SendNavigate(-1, kExistingURL); | 1012 main_test_rfh()->SendNavigate(-1, 0, false, kExistingURL); |
990 | 1013 |
991 // This should clear the pending entry and notify of a navigation state | 1014 // This should clear the pending entry and notify of a navigation state |
992 // change, so that we do not keep displaying kNewURL. | 1015 // change, so that we do not keep displaying kNewURL. |
993 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1016 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
994 EXPECT_FALSE(controller.GetPendingEntry()); | 1017 EXPECT_FALSE(controller.GetPendingEntry()); |
995 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 1018 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
996 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1019 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
997 switches::kEnableBrowserSideNavigation)) | 1020 switches::kEnableBrowserSideNavigation)) |
998 EXPECT_EQ(4, delegate->navigation_state_change_count()); | 1021 EXPECT_EQ(4, delegate->navigation_state_change_count()); |
999 else | 1022 else |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 // redirect and abort. See http://crbug.com/83031. | 1082 // redirect and abort. See http://crbug.com/83031. |
1060 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { | 1083 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { |
1061 NavigationControllerImpl& controller = controller_impl(); | 1084 NavigationControllerImpl& controller = controller_impl(); |
1062 TestNotificationTracker notifications; | 1085 TestNotificationTracker notifications; |
1063 RegisterForAllNavNotifications(¬ifications, &controller); | 1086 RegisterForAllNavNotifications(¬ifications, &controller); |
1064 | 1087 |
1065 // First make an existing committed entry. | 1088 // First make an existing committed entry. |
1066 const GURL kExistingURL("http://foo/eh"); | 1089 const GURL kExistingURL("http://foo/eh"); |
1067 controller.LoadURL(kExistingURL, content::Referrer(), | 1090 controller.LoadURL(kExistingURL, content::Referrer(), |
1068 ui::PAGE_TRANSITION_TYPED, std::string()); | 1091 ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1092 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1069 main_test_rfh()->PrepareForCommit(); | 1093 main_test_rfh()->PrepareForCommit(); |
1070 main_test_rfh()->SendNavigate(1, kExistingURL); | 1094 main_test_rfh()->SendNavigate(1, entry_id, true, kExistingURL); |
1071 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1095 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1072 navigation_entry_committed_counter_ = 0; | 1096 navigation_entry_committed_counter_ = 0; |
1073 | 1097 |
1074 // Set a WebContentsDelegate to listen for state changes. | 1098 // Set a WebContentsDelegate to listen for state changes. |
1075 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 1099 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
1076 EXPECT_FALSE(contents()->GetDelegate()); | 1100 EXPECT_FALSE(contents()->GetDelegate()); |
1077 contents()->SetDelegate(delegate.get()); | 1101 contents()->SetDelegate(delegate.get()); |
1078 | 1102 |
1079 // Now make a pending new navigation, initiated by the renderer. | 1103 // Now make a pending new navigation, initiated by the renderer. |
1080 const GURL kNewURL("http://foo/bee"); | 1104 const GURL kNewURL("http://foo/bee"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 std::vector<GURL> url_chain; | 1156 std::vector<GURL> url_chain; |
1133 | 1157 |
1134 const GURL url1("http://foo1"); | 1158 const GURL url1("http://foo1"); |
1135 const GURL url2("http://foo2"); | 1159 const GURL url2("http://foo2"); |
1136 | 1160 |
1137 // Navigate to a first, unprivileged URL. | 1161 // Navigate to a first, unprivileged URL. |
1138 controller.LoadURL( | 1162 controller.LoadURL( |
1139 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1163 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1140 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, | 1164 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, |
1141 controller.GetPendingEntry()->bindings()); | 1165 controller.GetPendingEntry()->bindings()); |
| 1166 int entry1_id = controller.GetPendingEntry()->GetUniqueID(); |
1142 | 1167 |
1143 // Commit. | 1168 // Commit. |
1144 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1169 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1145 orig_rfh->PrepareForCommit(); | 1170 orig_rfh->PrepareForCommit(); |
1146 orig_rfh->SendNavigate(0, url1); | 1171 orig_rfh->SendNavigate(0, entry1_id, true, url1); |
1147 EXPECT_EQ(controller.GetEntryCount(), 1); | 1172 EXPECT_EQ(controller.GetEntryCount(), 1); |
1148 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1173 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1149 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1174 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
| 1175 entry1_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
1150 | 1176 |
1151 // Manually increase the number of active frames in the SiteInstance | 1177 // Manually increase the number of active frames in the SiteInstance |
1152 // that orig_rfh belongs to, to prevent it from being destroyed when | 1178 // that orig_rfh belongs to, to prevent it from being destroyed when |
1153 // it gets swapped out, so that we can reuse orig_rfh when the | 1179 // it gets swapped out, so that we can reuse orig_rfh when the |
1154 // controller goes back. | 1180 // controller goes back. |
1155 orig_rfh->GetSiteInstance()->increment_active_frame_count(); | 1181 orig_rfh->GetSiteInstance()->increment_active_frame_count(); |
1156 | 1182 |
1157 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1183 // Navigate to a second URL, simulate the beforeunload ack for the cross-site |
1158 // transition, and set bindings on the pending RenderViewHost to simulate a | 1184 // transition, and set bindings on the pending RenderViewHost to simulate a |
1159 // privileged url. | 1185 // privileged url. |
1160 controller.LoadURL( | 1186 controller.LoadURL( |
1161 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1187 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1188 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1162 orig_rfh->PrepareForCommit(); | 1189 orig_rfh->PrepareForCommit(); |
1163 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); | 1190 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); |
1164 new_rfh->GetRenderViewHost()->AllowBindings(1); | 1191 new_rfh->GetRenderViewHost()->AllowBindings(1); |
1165 new_rfh->SendNavigate(1, url2); | 1192 new_rfh->SendNavigate(1, entry_id, true, url2); |
1166 | 1193 |
1167 // The second load should be committed, and bindings should be remembered. | 1194 // The second load should be committed, and bindings should be remembered. |
1168 EXPECT_EQ(controller.GetEntryCount(), 2); | 1195 EXPECT_EQ(controller.GetEntryCount(), 2); |
1169 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1196 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1170 EXPECT_TRUE(controller.CanGoBack()); | 1197 EXPECT_TRUE(controller.CanGoBack()); |
1171 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); | 1198 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); |
1172 | 1199 |
1173 // Going back, the first entry should still appear unprivileged. | 1200 // Going back, the first entry should still appear unprivileged. |
1174 controller.GoBack(); | 1201 controller.GoBack(); |
1175 new_rfh->PrepareForCommit(); | 1202 new_rfh->PrepareForCommit(); |
1176 orig_rfh->SendNavigate(0, url1); | 1203 orig_rfh->SendNavigate(0, entry1_id, false, url1); |
1177 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1204 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1178 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1205 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
1179 } | 1206 } |
1180 | 1207 |
1181 TEST_F(NavigationControllerTest, Reload) { | 1208 TEST_F(NavigationControllerTest, Reload) { |
1182 NavigationControllerImpl& controller = controller_impl(); | 1209 NavigationControllerImpl& controller = controller_impl(); |
1183 TestNotificationTracker notifications; | 1210 TestNotificationTracker notifications; |
1184 RegisterForAllNavNotifications(¬ifications, &controller); | 1211 RegisterForAllNavNotifications(¬ifications, &controller); |
1185 | 1212 |
1186 const GURL url1("http://foo1"); | 1213 const GURL url1("http://foo1"); |
1187 | 1214 |
1188 controller.LoadURL( | 1215 controller.LoadURL( |
1189 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1216 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1217 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1190 EXPECT_EQ(0U, notifications.size()); | 1218 EXPECT_EQ(0U, notifications.size()); |
1191 main_test_rfh()->PrepareForCommit(); | 1219 main_test_rfh()->PrepareForCommit(); |
1192 main_test_rfh()->SendNavigate(0, url1); | 1220 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
1193 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1221 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1194 navigation_entry_committed_counter_ = 0; | 1222 navigation_entry_committed_counter_ = 0; |
1195 ASSERT_TRUE(controller.GetVisibleEntry()); | 1223 ASSERT_TRUE(controller.GetVisibleEntry()); |
1196 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1224 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
| 1225 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1226 |
1197 controller.Reload(true); | 1227 controller.Reload(true); |
1198 EXPECT_EQ(0U, notifications.size()); | 1228 EXPECT_EQ(0U, notifications.size()); |
1199 | 1229 |
1200 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1230 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
1201 EXPECT_FALSE(timestamp.is_null()); | 1231 EXPECT_FALSE(timestamp.is_null()); |
1202 | 1232 |
1203 // The reload is pending. | 1233 // The reload is pending. |
1204 EXPECT_EQ(controller.GetEntryCount(), 1); | 1234 EXPECT_EQ(controller.GetEntryCount(), 1); |
1205 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1235 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1206 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1236 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1207 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1237 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1208 EXPECT_TRUE(controller.GetPendingEntry()); | 1238 EXPECT_TRUE(controller.GetPendingEntry()); |
1209 EXPECT_FALSE(controller.CanGoBack()); | 1239 EXPECT_FALSE(controller.CanGoBack()); |
1210 EXPECT_FALSE(controller.CanGoForward()); | 1240 EXPECT_FALSE(controller.CanGoForward()); |
1211 // Make sure the title has been cleared (will be redrawn just after reload). | 1241 // Make sure the title has been cleared (will be redrawn just after reload). |
1212 // Avoids a stale cached title when the new page being reloaded has no title. | 1242 // Avoids a stale cached title when the new page being reloaded has no title. |
1213 // See http://crbug.com/96041. | 1243 // See http://crbug.com/96041. |
1214 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1244 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
1215 | 1245 |
1216 main_test_rfh()->PrepareForCommit(); | 1246 main_test_rfh()->PrepareForCommit(); |
1217 main_test_rfh()->SendNavigate(0, url1); | 1247 main_test_rfh()->SendNavigate(0, entry_id, false, url1); |
1218 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1248 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1219 navigation_entry_committed_counter_ = 0; | 1249 navigation_entry_committed_counter_ = 0; |
1220 | 1250 |
1221 // Now the reload is committed. | 1251 // Now the reload is committed. |
1222 EXPECT_EQ(controller.GetEntryCount(), 1); | 1252 EXPECT_EQ(controller.GetEntryCount(), 1); |
1223 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1253 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1224 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1254 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1225 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1255 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1226 EXPECT_FALSE(controller.GetPendingEntry()); | 1256 EXPECT_FALSE(controller.GetPendingEntry()); |
1227 EXPECT_FALSE(controller.CanGoBack()); | 1257 EXPECT_FALSE(controller.CanGoBack()); |
1228 EXPECT_FALSE(controller.CanGoForward()); | 1258 EXPECT_FALSE(controller.CanGoForward()); |
1229 | 1259 |
1230 // The timestamp should have been updated. | 1260 // The timestamp should have been updated. |
1231 ASSERT_TRUE(controller.GetVisibleEntry()); | 1261 ASSERT_TRUE(controller.GetVisibleEntry()); |
1232 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); | 1262 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
1233 } | 1263 } |
1234 | 1264 |
1235 // Tests what happens when a reload navigation produces a new page. | 1265 // Tests what happens when a reload navigation produces a new page. |
1236 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1266 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
1237 NavigationControllerImpl& controller = controller_impl(); | 1267 NavigationControllerImpl& controller = controller_impl(); |
1238 TestNotificationTracker notifications; | 1268 TestNotificationTracker notifications; |
1239 RegisterForAllNavNotifications(¬ifications, &controller); | 1269 RegisterForAllNavNotifications(¬ifications, &controller); |
1240 | 1270 |
1241 const GURL url1("http://foo1"); | 1271 const GURL url1("http://foo1"); |
1242 const GURL url2("http://foo2"); | 1272 const GURL url2("http://foo2"); |
1243 | 1273 |
1244 controller.LoadURL( | 1274 controller.LoadURL( |
1245 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1275 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1276 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1246 main_test_rfh()->PrepareForCommit(); | 1277 main_test_rfh()->PrepareForCommit(); |
1247 main_test_rfh()->SendNavigate(0, url1); | 1278 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
1248 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1279 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1249 navigation_entry_committed_counter_ = 0; | 1280 navigation_entry_committed_counter_ = 0; |
| 1281 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
1250 | 1282 |
1251 controller.Reload(true); | 1283 controller.Reload(true); |
1252 EXPECT_EQ(0U, notifications.size()); | 1284 EXPECT_EQ(0U, notifications.size()); |
1253 | 1285 |
1254 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); | 1286 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); |
1255 main_test_rfh()->SendNavigate(1, url2); | 1287 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
1256 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1288 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1257 navigation_entry_committed_counter_ = 0; | 1289 navigation_entry_committed_counter_ = 0; |
1258 | 1290 |
1259 // Now the reload is committed. | 1291 // Now the reload is committed. |
1260 EXPECT_EQ(controller.GetEntryCount(), 2); | 1292 EXPECT_EQ(controller.GetEntryCount(), 2); |
1261 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1293 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1262 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1294 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1263 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1295 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1264 EXPECT_FALSE(controller.GetPendingEntry()); | 1296 EXPECT_FALSE(controller.GetPendingEntry()); |
1265 EXPECT_TRUE(controller.CanGoBack()); | 1297 EXPECT_TRUE(controller.CanGoBack()); |
1266 EXPECT_FALSE(controller.CanGoForward()); | 1298 EXPECT_FALSE(controller.CanGoForward()); |
1267 } | 1299 } |
1268 | 1300 |
1269 // This test ensures that when a guest renderer reloads, the reload goes through | 1301 // This test ensures that when a guest renderer reloads, the reload goes through |
1270 // without ending up in the "we have a wrong process for the URL" branch in | 1302 // without ending up in the "we have a wrong process for the URL" branch in |
1271 // NavigationControllerImpl::ReloadInternal. | 1303 // NavigationControllerImpl::ReloadInternal. |
1272 TEST_F(NavigationControllerTest, ReloadWithGuest) { | 1304 TEST_F(NavigationControllerTest, ReloadWithGuest) { |
1273 NavigationControllerImpl& controller = controller_impl(); | 1305 NavigationControllerImpl& controller = controller_impl(); |
1274 | 1306 |
1275 const GURL url1("http://foo1"); | 1307 const GURL url1("http://foo1"); |
1276 controller.LoadURL( | 1308 controller.LoadURL( |
1277 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1309 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1310 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1278 main_test_rfh()->PrepareForCommit(); | 1311 main_test_rfh()->PrepareForCommit(); |
1279 main_test_rfh()->SendNavigate(0, url1); | 1312 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
1280 ASSERT_TRUE(controller.GetVisibleEntry()); | 1313 ASSERT_TRUE(controller.GetVisibleEntry()); |
1281 | 1314 |
1282 // Make the entry believe its RenderProcessHost is a guest. | 1315 // Make the entry believe its RenderProcessHost is a guest. |
1283 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); | 1316 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); |
1284 reinterpret_cast<MockRenderProcessHost*>( | 1317 reinterpret_cast<MockRenderProcessHost*>( |
1285 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); | 1318 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); |
1286 | 1319 |
1287 // And reload. | 1320 // And reload. |
1288 controller.Reload(true); | 1321 controller.Reload(true); |
1289 | 1322 |
(...skipping 12 matching lines...) Expand all Loading... |
1302 NavigationControllerImpl& controller = controller_impl(); | 1335 NavigationControllerImpl& controller = controller_impl(); |
1303 TestNotificationTracker notifications; | 1336 TestNotificationTracker notifications; |
1304 RegisterForAllNavNotifications(¬ifications, &controller); | 1337 RegisterForAllNavNotifications(¬ifications, &controller); |
1305 | 1338 |
1306 const GURL original_url("http://foo1"); | 1339 const GURL original_url("http://foo1"); |
1307 const GURL final_url("http://foo2"); | 1340 const GURL final_url("http://foo2"); |
1308 | 1341 |
1309 // Load up the original URL, but get redirected. | 1342 // Load up the original URL, but get redirected. |
1310 controller.LoadURL( | 1343 controller.LoadURL( |
1311 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1344 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1345 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1312 EXPECT_EQ(0U, notifications.size()); | 1346 EXPECT_EQ(0U, notifications.size()); |
1313 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); | 1347 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); |
1314 main_test_rfh()->SendNavigateWithOriginalRequestURL( | 1348 main_test_rfh()->SendNavigateWithOriginalRequestURL(0, entry_id, true, |
1315 0, final_url, original_url); | 1349 final_url, original_url); |
1316 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1350 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1317 navigation_entry_committed_counter_ = 0; | 1351 navigation_entry_committed_counter_ = 0; |
| 1352 entry_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
1318 | 1353 |
1319 // The NavigationEntry should save both the original URL and the final | 1354 // The NavigationEntry should save both the original URL and the final |
1320 // redirected URL. | 1355 // redirected URL. |
1321 EXPECT_EQ( | 1356 EXPECT_EQ( |
1322 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1357 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
1323 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1358 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
1324 | 1359 |
1325 // Reload using the original URL. | 1360 // Reload using the original URL. |
1326 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1361 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
1327 controller.ReloadOriginalRequestURL(false); | 1362 controller.ReloadOriginalRequestURL(false); |
1328 EXPECT_EQ(0U, notifications.size()); | 1363 EXPECT_EQ(0U, notifications.size()); |
1329 | 1364 |
1330 // The reload is pending. The request should point to the original URL. | 1365 // The reload is pending. The request should point to the original URL. |
1331 EXPECT_EQ(original_url, navigated_url()); | 1366 EXPECT_EQ(original_url, navigated_url()); |
1332 EXPECT_EQ(controller.GetEntryCount(), 1); | 1367 EXPECT_EQ(controller.GetEntryCount(), 1); |
1333 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1368 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1334 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1369 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1335 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1370 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1336 EXPECT_TRUE(controller.GetPendingEntry()); | 1371 EXPECT_TRUE(controller.GetPendingEntry()); |
1337 EXPECT_FALSE(controller.CanGoBack()); | 1372 EXPECT_FALSE(controller.CanGoBack()); |
1338 EXPECT_FALSE(controller.CanGoForward()); | 1373 EXPECT_FALSE(controller.CanGoForward()); |
1339 | 1374 |
1340 // Make sure the title has been cleared (will be redrawn just after reload). | 1375 // Make sure the title has been cleared (will be redrawn just after reload). |
1341 // Avoids a stale cached title when the new page being reloaded has no title. | 1376 // Avoids a stale cached title when the new page being reloaded has no title. |
1342 // See http://crbug.com/96041. | 1377 // See http://crbug.com/96041. |
1343 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1378 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
1344 | 1379 |
1345 // Send that the navigation has proceeded; say it got redirected again. | 1380 // Send that the navigation has proceeded; say it got redirected again. |
1346 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); | 1381 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); |
1347 main_test_rfh()->SendNavigate(0, final_url); | 1382 main_test_rfh()->SendNavigate(0, entry_id, false, final_url); |
1348 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1383 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1349 navigation_entry_committed_counter_ = 0; | 1384 navigation_entry_committed_counter_ = 0; |
1350 | 1385 |
1351 // Now the reload is committed. | 1386 // Now the reload is committed. |
1352 EXPECT_EQ(controller.GetEntryCount(), 1); | 1387 EXPECT_EQ(controller.GetEntryCount(), 1); |
1353 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1388 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1354 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1389 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1355 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1390 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1356 EXPECT_FALSE(controller.GetPendingEntry()); | 1391 EXPECT_FALSE(controller.GetPendingEntry()); |
1357 EXPECT_FALSE(controller.CanGoBack()); | 1392 EXPECT_FALSE(controller.CanGoBack()); |
1358 EXPECT_FALSE(controller.CanGoForward()); | 1393 EXPECT_FALSE(controller.CanGoForward()); |
1359 } | 1394 } |
1360 | 1395 |
1361 #endif // !defined(OS_ANDROID) | 1396 #endif // !defined(OS_ANDROID) |
1362 | 1397 |
1363 // Test that certain non-persisted NavigationEntryImpl values get reset after | 1398 // Test that certain non-persisted NavigationEntryImpl values get reset after |
1364 // commit. | 1399 // commit. |
1365 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { | 1400 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { |
1366 NavigationControllerImpl& controller = controller_impl(); | 1401 NavigationControllerImpl& controller = controller_impl(); |
1367 | 1402 |
1368 // The value of "should replace entry" will be tested, but it's an error to | 1403 // The value of "should replace entry" will be tested, but it's an error to |
1369 // specify it when there are no entries. Create a simple entry to be replaced. | 1404 // specify it when there are no entries. Create a simple entry to be replaced. |
1370 const GURL url0("http://foo/0"); | 1405 const GURL url0("http://foo/0"); |
1371 controller.LoadURL( | 1406 controller.LoadURL( |
1372 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1407 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1408 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1373 main_test_rfh()->PrepareForCommit(); | 1409 main_test_rfh()->PrepareForCommit(); |
1374 main_test_rfh()->SendNavigate(0, url0); | 1410 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
1375 | 1411 |
1376 // Set up the pending entry. | 1412 // Set up the pending entry. |
1377 const GURL url1("http://foo/1"); | 1413 const GURL url1("http://foo/1"); |
1378 controller.LoadURL( | 1414 controller.LoadURL( |
1379 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1415 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1416 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1380 | 1417 |
1381 // Set up some sample values. | 1418 // Set up some sample values. |
1382 const unsigned char* raw_data = | 1419 const unsigned char* raw_data = |
1383 reinterpret_cast<const unsigned char*>("post\n\n\0data"); | 1420 reinterpret_cast<const unsigned char*>("post\n\n\0data"); |
1384 const int length = 11; | 1421 const int length = 11; |
1385 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | 1422 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); |
1386 scoped_refptr<base::RefCountedBytes> post_data = | 1423 scoped_refptr<base::RefCountedBytes> post_data = |
1387 base::RefCountedBytes::TakeVector(&post_data_vector); | 1424 base::RefCountedBytes::TakeVector(&post_data_vector); |
1388 GlobalRequestID transfer_id(3, 4); | 1425 GlobalRequestID transfer_id(3, 4); |
1389 | 1426 |
1390 // Set non-persisted values on the pending entry. | 1427 // Set non-persisted values on the pending entry. |
1391 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); | 1428 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
1392 pending_entry->SetBrowserInitiatedPostData(post_data.get()); | 1429 pending_entry->SetBrowserInitiatedPostData(post_data.get()); |
1393 pending_entry->set_is_renderer_initiated(true); | 1430 pending_entry->set_is_renderer_initiated(true); |
1394 pending_entry->set_transferred_global_request_id(transfer_id); | 1431 pending_entry->set_transferred_global_request_id(transfer_id); |
1395 pending_entry->set_should_replace_entry(true); | 1432 pending_entry->set_should_replace_entry(true); |
1396 pending_entry->set_should_clear_history_list(true); | 1433 pending_entry->set_should_clear_history_list(true); |
1397 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); | 1434 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); |
1398 EXPECT_TRUE(pending_entry->is_renderer_initiated()); | 1435 EXPECT_TRUE(pending_entry->is_renderer_initiated()); |
1399 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); | 1436 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); |
1400 EXPECT_TRUE(pending_entry->should_replace_entry()); | 1437 EXPECT_TRUE(pending_entry->should_replace_entry()); |
1401 EXPECT_TRUE(pending_entry->should_clear_history_list()); | 1438 EXPECT_TRUE(pending_entry->should_clear_history_list()); |
1402 | 1439 |
1403 // Fake a commit response. | 1440 // Fake a commit response. |
1404 main_test_rfh()->PrepareForCommit(); | 1441 main_test_rfh()->PrepareForCommit(); |
1405 main_test_rfh()->SendNavigate(1, url1); | 1442 main_test_rfh()->SendNavigate(1, entry_id, true, url1); |
1406 | 1443 |
1407 // Certain values that are only used for pending entries get reset after | 1444 // Certain values that are only used for pending entries get reset after |
1408 // commit. | 1445 // commit. |
1409 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); | 1446 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
1410 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); | 1447 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); |
1411 EXPECT_FALSE(committed_entry->is_renderer_initiated()); | 1448 EXPECT_FALSE(committed_entry->is_renderer_initiated()); |
1412 EXPECT_EQ(GlobalRequestID(-1, -1), | 1449 EXPECT_EQ(GlobalRequestID(-1, -1), |
1413 committed_entry->transferred_global_request_id()); | 1450 committed_entry->transferred_global_request_id()); |
1414 EXPECT_FALSE(committed_entry->should_replace_entry()); | 1451 EXPECT_FALSE(committed_entry->should_replace_entry()); |
1415 EXPECT_FALSE(committed_entry->should_clear_history_list()); | 1452 EXPECT_FALSE(committed_entry->should_clear_history_list()); |
1416 } | 1453 } |
1417 | 1454 |
1418 // Test that Redirects are preserved after a commit. | 1455 // Test that Redirects are preserved after a commit. |
1419 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { | 1456 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { |
1420 NavigationControllerImpl& controller = controller_impl(); | 1457 NavigationControllerImpl& controller = controller_impl(); |
1421 const GURL url1("http://foo1"); | 1458 const GURL url1("http://foo1"); |
1422 const GURL url2("http://foo2"); | 1459 const GURL url2("http://foo2"); |
1423 controller.LoadURL( | 1460 controller.LoadURL( |
1424 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1461 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1462 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1425 | 1463 |
1426 // Set up some redirect values. | 1464 // Set up some redirect values. |
1427 std::vector<GURL> redirects; | 1465 std::vector<GURL> redirects; |
1428 redirects.push_back(url2); | 1466 redirects.push_back(url2); |
1429 | 1467 |
1430 // Set redirects on the pending entry. | 1468 // Set redirects on the pending entry. |
1431 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); | 1469 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
1432 pending_entry->SetRedirectChain(redirects); | 1470 pending_entry->SetRedirectChain(redirects); |
1433 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); | 1471 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); |
1434 EXPECT_EQ(url2, pending_entry->GetRedirectChain()[0]); | 1472 EXPECT_EQ(url2, pending_entry->GetRedirectChain()[0]); |
1435 | 1473 |
1436 // Normal navigation will preserve redirects in the committed entry. | 1474 // Normal navigation will preserve redirects in the committed entry. |
1437 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); | 1475 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); |
1438 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects); | 1476 main_test_rfh()->SendNavigateWithRedirects(0, entry_id, true, url1, |
| 1477 redirects); |
1439 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); | 1478 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
1440 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); | 1479 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); |
1441 EXPECT_EQ(url2, committed_entry->GetRedirectChain()[0]); | 1480 EXPECT_EQ(url2, committed_entry->GetRedirectChain()[0]); |
1442 } | 1481 } |
1443 | 1482 |
1444 // Tests what happens when we navigate back successfully | 1483 // Tests what happens when we navigate back successfully |
1445 TEST_F(NavigationControllerTest, Back) { | 1484 TEST_F(NavigationControllerTest, Back) { |
1446 NavigationControllerImpl& controller = controller_impl(); | 1485 NavigationControllerImpl& controller = controller_impl(); |
1447 TestNotificationTracker notifications; | 1486 TestNotificationTracker notifications; |
1448 RegisterForAllNavNotifications(¬ifications, &controller); | 1487 RegisterForAllNavNotifications(¬ifications, &controller); |
1449 | 1488 |
1450 const GURL url1("http://foo1"); | 1489 const GURL url1("http://foo1"); |
1451 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 1490 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
1452 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1491 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1453 navigation_entry_committed_counter_ = 0; | 1492 navigation_entry_committed_counter_ = 0; |
1454 | 1493 |
1455 const GURL url2("http://foo2"); | 1494 const GURL url2("http://foo2"); |
1456 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2); | 1495 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url2); |
1457 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1496 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1458 navigation_entry_committed_counter_ = 0; | 1497 navigation_entry_committed_counter_ = 0; |
1459 | 1498 |
1460 controller.GoBack(); | 1499 controller.GoBack(); |
| 1500 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1461 EXPECT_EQ(0U, notifications.size()); | 1501 EXPECT_EQ(0U, notifications.size()); |
1462 | 1502 |
1463 // We should now have a pending navigation to go back. | 1503 // We should now have a pending navigation to go back. |
1464 EXPECT_EQ(controller.GetEntryCount(), 2); | 1504 EXPECT_EQ(controller.GetEntryCount(), 2); |
1465 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1505 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1466 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1506 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1467 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1507 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1468 EXPECT_TRUE(controller.GetPendingEntry()); | 1508 EXPECT_TRUE(controller.GetPendingEntry()); |
1469 EXPECT_FALSE(controller.CanGoBack()); | 1509 EXPECT_FALSE(controller.CanGoBack()); |
1470 EXPECT_FALSE(controller.CanGoToOffset(-1)); | 1510 EXPECT_FALSE(controller.CanGoToOffset(-1)); |
1471 EXPECT_TRUE(controller.CanGoForward()); | 1511 EXPECT_TRUE(controller.CanGoForward()); |
1472 EXPECT_TRUE(controller.CanGoToOffset(1)); | 1512 EXPECT_TRUE(controller.CanGoToOffset(1)); |
1473 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps. | 1513 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go forward 2 steps. |
1474 | 1514 |
1475 // Timestamp for entry 1 should be on or after that of entry 0. | 1515 // Timestamp for entry 1 should be on or after that of entry 0. |
1476 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1516 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1477 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), | 1517 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), |
1478 controller.GetEntryAtIndex(0)->GetTimestamp()); | 1518 controller.GetEntryAtIndex(0)->GetTimestamp()); |
1479 | 1519 |
1480 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url2); | 1520 main_test_rfh()->SendNavigate(0, entry_id, false, url2); |
1481 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1521 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1482 navigation_entry_committed_counter_ = 0; | 1522 navigation_entry_committed_counter_ = 0; |
1483 | 1523 |
1484 // The back navigation completed successfully. | 1524 // The back navigation completed successfully. |
1485 EXPECT_EQ(controller.GetEntryCount(), 2); | 1525 EXPECT_EQ(controller.GetEntryCount(), 2); |
1486 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1526 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1487 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1527 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1488 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1528 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1489 EXPECT_FALSE(controller.GetPendingEntry()); | 1529 EXPECT_FALSE(controller.GetPendingEntry()); |
1490 EXPECT_FALSE(controller.CanGoBack()); | 1530 EXPECT_FALSE(controller.CanGoBack()); |
(...skipping 13 matching lines...) Expand all Loading... |
1504 NavigationControllerImpl& controller = controller_impl(); | 1544 NavigationControllerImpl& controller = controller_impl(); |
1505 TestNotificationTracker notifications; | 1545 TestNotificationTracker notifications; |
1506 RegisterForAllNavNotifications(¬ifications, &controller); | 1546 RegisterForAllNavNotifications(¬ifications, &controller); |
1507 | 1547 |
1508 const GURL url1("http://foo/1"); | 1548 const GURL url1("http://foo/1"); |
1509 const GURL url2("http://foo/2"); | 1549 const GURL url2("http://foo/2"); |
1510 const GURL url3("http://foo/3"); | 1550 const GURL url3("http://foo/3"); |
1511 | 1551 |
1512 controller.LoadURL( | 1552 controller.LoadURL( |
1513 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1553 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1554 int entry1_id = controller.GetPendingEntry()->GetUniqueID(); |
1514 main_test_rfh()->PrepareForCommit(); | 1555 main_test_rfh()->PrepareForCommit(); |
1515 main_test_rfh()->SendNavigate(0, url1); | 1556 main_test_rfh()->SendNavigate(0, entry1_id, true, url1); |
| 1557 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1558 navigation_entry_committed_counter_ = 0; |
| 1559 entry1_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 1560 |
| 1561 controller.LoadURL( |
| 1562 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1563 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1564 main_test_rfh()->PrepareForCommit(); |
| 1565 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
1516 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1566 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1517 navigation_entry_committed_counter_ = 0; | 1567 navigation_entry_committed_counter_ = 0; |
1518 | 1568 |
1519 controller.LoadURL( | |
1520 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | |
1521 main_test_rfh()->PrepareForCommit(); | |
1522 main_test_rfh()->SendNavigate(1, url2); | |
1523 EXPECT_EQ(1U, navigation_entry_committed_counter_); | |
1524 navigation_entry_committed_counter_ = 0; | |
1525 | |
1526 controller.GoBack(); | 1569 controller.GoBack(); |
1527 EXPECT_EQ(0U, notifications.size()); | 1570 EXPECT_EQ(0U, notifications.size()); |
1528 | 1571 |
1529 // We should now have a pending navigation to go back. | 1572 // We should now have a pending navigation to go back. |
1530 EXPECT_EQ(controller.GetEntryCount(), 2); | 1573 EXPECT_EQ(controller.GetEntryCount(), 2); |
1531 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1574 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1532 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1575 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1533 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1576 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1534 EXPECT_TRUE(controller.GetPendingEntry()); | 1577 EXPECT_TRUE(controller.GetPendingEntry()); |
1535 EXPECT_FALSE(controller.CanGoBack()); | 1578 EXPECT_FALSE(controller.CanGoBack()); |
1536 EXPECT_TRUE(controller.CanGoForward()); | 1579 EXPECT_TRUE(controller.CanGoForward()); |
1537 | 1580 |
1538 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); | 1581 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); |
1539 main_test_rfh()->SendNavigate(2, url3); | 1582 main_test_rfh()->SendNavigate(2, entry1_id, true, url3); |
1540 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1583 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1541 navigation_entry_committed_counter_ = 0; | 1584 navigation_entry_committed_counter_ = 0; |
1542 | 1585 |
1543 // The back navigation resulted in a completely new navigation. | 1586 // The back navigation resulted in a completely new navigation. |
1544 // TODO(darin): perhaps this behavior will be confusing to users? | 1587 // TODO(darin): perhaps this behavior will be confusing to users? |
1545 EXPECT_EQ(controller.GetEntryCount(), 3); | 1588 EXPECT_EQ(controller.GetEntryCount(), 3); |
1546 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1589 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
1547 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1590 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1548 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1591 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1549 EXPECT_FALSE(controller.GetPendingEntry()); | 1592 EXPECT_FALSE(controller.GetPendingEntry()); |
1550 EXPECT_TRUE(controller.CanGoBack()); | 1593 EXPECT_TRUE(controller.CanGoBack()); |
1551 EXPECT_FALSE(controller.CanGoForward()); | 1594 EXPECT_FALSE(controller.CanGoForward()); |
1552 } | 1595 } |
1553 | 1596 |
1554 // Receives a back message when there is a new pending navigation entry. | 1597 // Receives a back message when there is a new pending navigation entry. |
1555 TEST_F(NavigationControllerTest, Back_NewPending) { | 1598 TEST_F(NavigationControllerTest, Back_NewPending) { |
1556 NavigationControllerImpl& controller = controller_impl(); | 1599 NavigationControllerImpl& controller = controller_impl(); |
1557 TestNotificationTracker notifications; | 1600 TestNotificationTracker notifications; |
1558 RegisterForAllNavNotifications(¬ifications, &controller); | 1601 RegisterForAllNavNotifications(¬ifications, &controller); |
1559 | 1602 |
1560 const GURL kUrl1("http://foo1"); | 1603 const GURL kUrl1("http://foo1"); |
1561 const GURL kUrl2("http://foo2"); | 1604 const GURL kUrl2("http://foo2"); |
1562 const GURL kUrl3("http://foo3"); | 1605 const GURL kUrl3("http://foo3"); |
1563 | 1606 |
1564 // First navigate two places so we have some back history. | 1607 // First navigate two places so we have some back history. |
1565 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1); | 1608 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, kUrl1); |
1566 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1609 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1567 navigation_entry_committed_counter_ = 0; | 1610 navigation_entry_committed_counter_ = 0; |
1568 | 1611 |
1569 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED); | 1612 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED); |
1570 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2); | 1613 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, kUrl2); |
1571 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1614 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1572 navigation_entry_committed_counter_ = 0; | 1615 navigation_entry_committed_counter_ = 0; |
1573 | 1616 |
1574 // Now start a new pending navigation and go back before it commits. | 1617 // Now start a new pending navigation and go back before it commits. |
1575 controller.LoadURL( | 1618 controller.LoadURL( |
1576 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1619 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1577 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1620 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1578 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); | 1621 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); |
1579 controller.GoBack(); | 1622 controller.GoBack(); |
1580 | 1623 |
1581 // The pending navigation should now be the "back" item and the new one | 1624 // The pending navigation should now be the "back" item and the new one |
1582 // should be gone. | 1625 // should be gone. |
1583 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 1626 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
1584 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); | 1627 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); |
1585 } | 1628 } |
1586 | 1629 |
1587 // Receives a back message when there is a different renavigation already | 1630 // Receives a back message when there is a different renavigation already |
1588 // pending. | 1631 // pending. |
1589 TEST_F(NavigationControllerTest, Back_OtherBackPending) { | 1632 TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
1590 NavigationControllerImpl& controller = controller_impl(); | 1633 NavigationControllerImpl& controller = controller_impl(); |
1591 const GURL kUrl1("http://foo/1"); | 1634 const GURL kUrl1("http://foo/1"); |
1592 const GURL kUrl2("http://foo/2"); | 1635 const GURL kUrl2("http://foo/2"); |
1593 const GURL kUrl3("http://foo/3"); | 1636 const GURL kUrl3("http://foo/3"); |
1594 | 1637 |
1595 // First navigate three places so we have some back history. | 1638 // First navigate three places so we have some back history. |
1596 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); | 1639 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); |
1597 main_test_rfh()->PrepareForCommit(); | 1640 main_test_rfh()->PrepareForCommit(); |
1598 main_test_rfh()->SendNavigate(0, kUrl1); | 1641 main_test_rfh()->SendNavigate(0, 0, true, kUrl1); |
1599 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); | 1642 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); |
1600 main_test_rfh()->PrepareForCommit(); | 1643 main_test_rfh()->PrepareForCommit(); |
1601 main_test_rfh()->SendNavigate(1, kUrl2); | 1644 main_test_rfh()->SendNavigate(1, 0, true, kUrl2); |
1602 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); | 1645 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); |
1603 main_test_rfh()->PrepareForCommit(); | 1646 main_test_rfh()->PrepareForCommit(); |
1604 main_test_rfh()->SendNavigate(2, kUrl3); | 1647 main_test_rfh()->SendNavigate(2, 0, true, kUrl3); |
1605 | 1648 |
1606 // With nothing pending, say we get a renderer back navigation request to the | 1649 // With nothing pending, say we get a renderer back navigation request to the |
1607 // second entry. | 1650 // second entry. |
1608 controller.GoToOffset(-1); | 1651 controller.GoToOffset(-1); |
| 1652 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1609 main_test_rfh()->PrepareForCommit(); | 1653 main_test_rfh()->PrepareForCommit(); |
1610 main_test_rfh()->SendNavigate(1, kUrl2); | 1654 main_test_rfh()->SendNavigate(1, entry_id, false, kUrl2); |
1611 | 1655 |
1612 // We know all the entries have the same site instance, so we can just grab | 1656 // We know all the entries have the same site instance, so we can just grab |
1613 // a random one for looking up other entries. | 1657 // a random one for looking up other entries. |
1614 SiteInstance* site_instance = | 1658 SiteInstance* site_instance = |
1615 controller.GetLastCommittedEntry()->site_instance(); | 1659 controller.GetLastCommittedEntry()->site_instance(); |
1616 | 1660 |
1617 // That second URL should be the last committed and it should have gotten the | 1661 // That second URL should be the last committed and it should have gotten the |
1618 // new title. | 1662 // new title. |
1619 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1663 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
1620 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1664 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1621 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1665 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1622 | 1666 |
1623 // Now go forward to the last item again and say it was committed. | 1667 // Now go forward to the last item again and say it was committed. |
1624 controller.GoForward(); | 1668 controller.GoForward(); |
| 1669 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1625 main_test_rfh()->PrepareForCommit(); | 1670 main_test_rfh()->PrepareForCommit(); |
1626 main_test_rfh()->SendNavigate(2, kUrl3); | 1671 main_test_rfh()->SendNavigate(2, entry_id, false, kUrl3); |
1627 | 1672 |
1628 // Now start going back one to the second page. It will be pending. | 1673 // Now start going back one to the second page. It will be pending. |
1629 controller.GoBack(); | 1674 controller.GoBack(); |
1630 EXPECT_EQ(1, controller.GetPendingEntryIndex()); | 1675 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
1631 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 1676 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
1632 | 1677 |
1633 // Now have the renderer request a navigation back to the first page. This | 1678 // Now have the renderer request a navigation back to the first page. This |
1634 // will not match the pending one. | 1679 // will not match the pending one. |
1635 controller.GoToOffset(-2); | 1680 controller.GoToOffset(-2); |
| 1681 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1636 main_test_rfh()->PrepareForCommit(); | 1682 main_test_rfh()->PrepareForCommit(); |
1637 main_test_rfh()->SendNavigate(0, kUrl1); | 1683 main_test_rfh()->SendNavigate(0, entry_id, false, kUrl1); |
1638 | 1684 |
1639 // The committed navigation should clear the pending entry. | 1685 // The committed navigation should clear the pending entry. |
1640 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1686 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1641 | 1687 |
1642 // But the navigated entry should be the last committed. | 1688 // But the navigated entry should be the last committed. |
1643 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1689 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1644 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); | 1690 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); |
1645 } | 1691 } |
1646 | 1692 |
1647 // Tests what happens when we navigate forward successfully. | 1693 // Tests what happens when we navigate forward successfully. |
1648 TEST_F(NavigationControllerTest, Forward) { | 1694 TEST_F(NavigationControllerTest, Forward) { |
1649 NavigationControllerImpl& controller = controller_impl(); | 1695 NavigationControllerImpl& controller = controller_impl(); |
1650 TestNotificationTracker notifications; | 1696 TestNotificationTracker notifications; |
1651 RegisterForAllNavNotifications(¬ifications, &controller); | 1697 RegisterForAllNavNotifications(¬ifications, &controller); |
1652 | 1698 |
1653 const GURL url1("http://foo1"); | 1699 const GURL url1("http://foo1"); |
1654 const GURL url2("http://foo2"); | 1700 const GURL url2("http://foo2"); |
1655 | 1701 |
1656 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); | 1702 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); |
1657 main_test_rfh()->PrepareForCommit(); | 1703 main_test_rfh()->PrepareForCommit(); |
1658 main_test_rfh()->SendNavigate(0, url1); | 1704 main_test_rfh()->SendNavigate(0, 0, true, url1); |
| 1705 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
1659 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1706 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1660 navigation_entry_committed_counter_ = 0; | 1707 navigation_entry_committed_counter_ = 0; |
1661 | 1708 |
1662 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); | 1709 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); |
1663 main_test_rfh()->PrepareForCommit(); | 1710 main_test_rfh()->PrepareForCommit(); |
1664 main_test_rfh()->SendNavigate(1, url2); | 1711 main_test_rfh()->SendNavigate(1, 0, true, url2); |
| 1712 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
1665 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1713 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1666 navigation_entry_committed_counter_ = 0; | 1714 navigation_entry_committed_counter_ = 0; |
1667 | 1715 |
1668 controller.GoBack(); | 1716 controller.GoBack(); |
1669 main_test_rfh()->PrepareForCommit(); | 1717 main_test_rfh()->PrepareForCommit(); |
1670 main_test_rfh()->SendNavigate(0, url1); | 1718 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), false, url1); |
1671 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1719 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1672 navigation_entry_committed_counter_ = 0; | 1720 navigation_entry_committed_counter_ = 0; |
1673 | 1721 |
1674 controller.GoForward(); | 1722 controller.GoForward(); |
1675 | 1723 |
1676 // We should now have a pending navigation to go forward. | 1724 // We should now have a pending navigation to go forward. |
1677 EXPECT_EQ(controller.GetEntryCount(), 2); | 1725 EXPECT_EQ(controller.GetEntryCount(), 2); |
1678 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1726 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1679 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1727 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1680 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1728 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1681 EXPECT_TRUE(controller.GetPendingEntry()); | 1729 EXPECT_TRUE(controller.GetPendingEntry()); |
1682 EXPECT_TRUE(controller.CanGoBack()); | 1730 EXPECT_TRUE(controller.CanGoBack()); |
1683 EXPECT_TRUE(controller.CanGoToOffset(-1)); | 1731 EXPECT_TRUE(controller.CanGoToOffset(-1)); |
1684 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. | 1732 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. |
1685 EXPECT_FALSE(controller.CanGoForward()); | 1733 EXPECT_FALSE(controller.CanGoForward()); |
1686 EXPECT_FALSE(controller.CanGoToOffset(1)); | 1734 EXPECT_FALSE(controller.CanGoToOffset(1)); |
1687 | 1735 |
1688 // Timestamp for entry 0 should be on or after that of entry 1 | 1736 // Timestamp for entry 0 should be on or after that of entry 1 |
1689 // (since we went back to it). | 1737 // (since we went back to it). |
1690 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1738 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1691 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1739 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
1692 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1740 controller.GetEntryAtIndex(1)->GetTimestamp()); |
1693 | 1741 |
1694 main_test_rfh()->PrepareForCommit(); | 1742 main_test_rfh()->PrepareForCommit(); |
1695 main_test_rfh()->SendNavigate(1, url2); | 1743 main_test_rfh()->SendNavigate(1, entry2->GetUniqueID(), false, url2); |
1696 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1744 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1697 navigation_entry_committed_counter_ = 0; | 1745 navigation_entry_committed_counter_ = 0; |
1698 | 1746 |
1699 // The forward navigation completed successfully. | 1747 // The forward navigation completed successfully. |
1700 EXPECT_EQ(controller.GetEntryCount(), 2); | 1748 EXPECT_EQ(controller.GetEntryCount(), 2); |
1701 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1749 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1702 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1750 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1703 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1751 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1704 EXPECT_FALSE(controller.GetPendingEntry()); | 1752 EXPECT_FALSE(controller.GetPendingEntry()); |
1705 EXPECT_TRUE(controller.CanGoBack()); | 1753 EXPECT_TRUE(controller.CanGoBack()); |
(...skipping 13 matching lines...) Expand all Loading... |
1719 NavigationControllerImpl& controller = controller_impl(); | 1767 NavigationControllerImpl& controller = controller_impl(); |
1720 TestNotificationTracker notifications; | 1768 TestNotificationTracker notifications; |
1721 RegisterForAllNavNotifications(¬ifications, &controller); | 1769 RegisterForAllNavNotifications(¬ifications, &controller); |
1722 | 1770 |
1723 const GURL url1("http://foo1"); | 1771 const GURL url1("http://foo1"); |
1724 const GURL url2("http://foo2"); | 1772 const GURL url2("http://foo2"); |
1725 const GURL url3("http://foo3"); | 1773 const GURL url3("http://foo3"); |
1726 | 1774 |
1727 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); | 1775 main_test_rfh()->SendRendererInitiatedNavigationRequest(url1, true); |
1728 main_test_rfh()->PrepareForCommit(); | 1776 main_test_rfh()->PrepareForCommit(); |
1729 main_test_rfh()->SendNavigate(0, url1); | 1777 main_test_rfh()->SendNavigate(0, 0, true, url1); |
1730 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1778 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1779 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
1731 navigation_entry_committed_counter_ = 0; | 1780 navigation_entry_committed_counter_ = 0; |
1732 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); | 1781 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); |
1733 main_test_rfh()->PrepareForCommit(); | 1782 main_test_rfh()->PrepareForCommit(); |
1734 main_test_rfh()->SendNavigate(1, url2); | 1783 main_test_rfh()->SendNavigate(1, 0, true, url2); |
1735 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1784 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 1785 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
1736 navigation_entry_committed_counter_ = 0; | 1786 navigation_entry_committed_counter_ = 0; |
1737 | 1787 |
1738 controller.GoBack(); | 1788 controller.GoBack(); |
1739 main_test_rfh()->PrepareForCommit(); | 1789 main_test_rfh()->PrepareForCommit(); |
1740 main_test_rfh()->SendNavigate(0, url1); | 1790 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), false, url1); |
1741 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1791 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1742 navigation_entry_committed_counter_ = 0; | 1792 navigation_entry_committed_counter_ = 0; |
1743 | 1793 |
1744 controller.GoForward(); | 1794 controller.GoForward(); |
1745 EXPECT_EQ(0U, notifications.size()); | 1795 EXPECT_EQ(0U, notifications.size()); |
1746 | 1796 |
1747 // Should now have a pending navigation to go forward. | 1797 // Should now have a pending navigation to go forward. |
1748 EXPECT_EQ(controller.GetEntryCount(), 2); | 1798 EXPECT_EQ(controller.GetEntryCount(), 2); |
1749 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1799 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1750 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1800 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1751 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1801 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1752 EXPECT_TRUE(controller.GetPendingEntry()); | 1802 EXPECT_TRUE(controller.GetPendingEntry()); |
1753 EXPECT_TRUE(controller.CanGoBack()); | 1803 EXPECT_TRUE(controller.CanGoBack()); |
1754 EXPECT_FALSE(controller.CanGoForward()); | 1804 EXPECT_FALSE(controller.CanGoForward()); |
1755 | 1805 |
1756 main_test_rfh()->PrepareForCommit(); | 1806 main_test_rfh()->PrepareForCommit(); |
1757 main_test_rfh()->SendNavigate(2, url3); | 1807 main_test_rfh()->SendNavigate(2, entry2->GetUniqueID(), true, url3); |
1758 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1808 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1759 navigation_entry_committed_counter_ = 0; | 1809 navigation_entry_committed_counter_ = 0; |
1760 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); | 1810 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); |
1761 | 1811 |
1762 EXPECT_EQ(controller.GetEntryCount(), 2); | 1812 EXPECT_EQ(controller.GetEntryCount(), 2); |
1763 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1813 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1764 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1814 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1765 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1815 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1766 EXPECT_FALSE(controller.GetPendingEntry()); | 1816 EXPECT_FALSE(controller.GetPendingEntry()); |
1767 EXPECT_TRUE(controller.CanGoBack()); | 1817 EXPECT_TRUE(controller.CanGoBack()); |
1768 EXPECT_FALSE(controller.CanGoForward()); | 1818 EXPECT_FALSE(controller.CanGoForward()); |
1769 } | 1819 } |
1770 | 1820 |
1771 // Two consecutive navigations for the same URL entered in should be considered | 1821 // Two consecutive navigations for the same URL entered in should be considered |
1772 // as SAME_PAGE navigation even when we are redirected to some other page. | 1822 // as SAME_PAGE navigation even when we are redirected to some other page. |
1773 TEST_F(NavigationControllerTest, Redirect) { | 1823 TEST_F(NavigationControllerTest, Redirect) { |
1774 NavigationControllerImpl& controller = controller_impl(); | 1824 NavigationControllerImpl& controller = controller_impl(); |
1775 TestNotificationTracker notifications; | 1825 TestNotificationTracker notifications; |
1776 RegisterForAllNavNotifications(¬ifications, &controller); | 1826 RegisterForAllNavNotifications(¬ifications, &controller); |
1777 | 1827 |
1778 const GURL url1("http://foo1"); | 1828 const GURL url1("http://foo1"); |
1779 const GURL url2("http://foo2"); // Redirection target | 1829 const GURL url2("http://foo2"); // Redirection target |
1780 | 1830 |
1781 // First request. | 1831 // First request. |
1782 controller.LoadURL( | 1832 controller.LoadURL( |
1783 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1833 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1834 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1784 | 1835 |
1785 EXPECT_EQ(0U, notifications.size()); | 1836 EXPECT_EQ(0U, notifications.size()); |
1786 | 1837 |
1787 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1838 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1788 params.page_id = 0; | 1839 params.page_id = 0; |
| 1840 params.nav_entry_id = entry_id; |
| 1841 params.did_create_new_entry = true; |
1789 params.url = url2; | 1842 params.url = url2; |
1790 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; | 1843 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; |
1791 params.redirects.push_back(GURL("http://foo1")); | 1844 params.redirects.push_back(GURL("http://foo1")); |
1792 params.redirects.push_back(GURL("http://foo2")); | 1845 params.redirects.push_back(GURL("http://foo2")); |
1793 params.should_update_history = false; | 1846 params.should_update_history = false; |
1794 params.gesture = NavigationGestureAuto; | 1847 params.gesture = NavigationGestureAuto; |
1795 params.is_post = false; | 1848 params.is_post = false; |
1796 params.page_state = PageState::CreateFromURL(url2); | 1849 params.page_state = PageState::CreateFromURL(url2); |
1797 | 1850 |
1798 LoadCommittedDetails details; | 1851 LoadCommittedDetails details; |
1799 | 1852 |
1800 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1853 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
1801 &details)); | 1854 &details)); |
1802 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1855 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1803 navigation_entry_committed_counter_ = 0; | 1856 navigation_entry_committed_counter_ = 0; |
1804 | 1857 |
1805 // Second request. | 1858 // Second request. |
1806 controller.LoadURL( | 1859 controller.LoadURL( |
1807 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1860 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1861 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1808 | 1862 |
1809 EXPECT_TRUE(controller.GetPendingEntry()); | 1863 EXPECT_TRUE(controller.GetPendingEntry()); |
1810 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1864 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1811 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1865 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
| 1866 |
| 1867 params.nav_entry_id = entry_id; |
| 1868 params.did_create_new_entry = false; |
| 1869 |
1812 EXPECT_EQ(0U, notifications.size()); | 1870 EXPECT_EQ(0U, notifications.size()); |
1813 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1871 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
1814 &details)); | 1872 &details)); |
1815 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1873 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1816 navigation_entry_committed_counter_ = 0; | 1874 navigation_entry_committed_counter_ = 0; |
1817 | 1875 |
1818 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); | 1876 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
1819 EXPECT_EQ(controller.GetEntryCount(), 1); | 1877 EXPECT_EQ(controller.GetEntryCount(), 1); |
1820 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1878 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1821 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1879 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
(...skipping 12 matching lines...) Expand all Loading... |
1834 NavigationControllerImpl& controller = controller_impl(); | 1892 NavigationControllerImpl& controller = controller_impl(); |
1835 TestNotificationTracker notifications; | 1893 TestNotificationTracker notifications; |
1836 RegisterForAllNavNotifications(¬ifications, &controller); | 1894 RegisterForAllNavNotifications(¬ifications, &controller); |
1837 | 1895 |
1838 const GURL url1("http://foo1"); | 1896 const GURL url1("http://foo1"); |
1839 const GURL url2("http://foo2"); // Redirection target | 1897 const GURL url2("http://foo2"); // Redirection target |
1840 | 1898 |
1841 // First request as POST. | 1899 // First request as POST. |
1842 controller.LoadURL( | 1900 controller.LoadURL( |
1843 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1901 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1902 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1844 controller.GetVisibleEntry()->SetHasPostData(true); | 1903 controller.GetVisibleEntry()->SetHasPostData(true); |
1845 | 1904 |
1846 EXPECT_EQ(0U, notifications.size()); | 1905 EXPECT_EQ(0U, notifications.size()); |
1847 | 1906 |
1848 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1907 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1849 params.page_id = 0; | 1908 params.page_id = 0; |
| 1909 params.nav_entry_id = entry_id; |
| 1910 params.did_create_new_entry = true; |
1850 params.url = url2; | 1911 params.url = url2; |
1851 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; | 1912 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; |
1852 params.redirects.push_back(GURL("http://foo1")); | 1913 params.redirects.push_back(GURL("http://foo1")); |
1853 params.redirects.push_back(GURL("http://foo2")); | 1914 params.redirects.push_back(GURL("http://foo2")); |
1854 params.should_update_history = false; | 1915 params.should_update_history = false; |
1855 params.gesture = NavigationGestureAuto; | 1916 params.gesture = NavigationGestureAuto; |
1856 params.is_post = true; | 1917 params.is_post = true; |
1857 params.page_state = PageState::CreateFromURL(url2); | 1918 params.page_state = PageState::CreateFromURL(url2); |
1858 | 1919 |
1859 LoadCommittedDetails details; | 1920 LoadCommittedDetails details; |
1860 | 1921 |
1861 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1922 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
1862 &details)); | 1923 &details)); |
1863 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1924 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1864 navigation_entry_committed_counter_ = 0; | 1925 navigation_entry_committed_counter_ = 0; |
1865 | 1926 |
1866 // Second request. | 1927 // Second request. |
1867 controller.LoadURL( | 1928 controller.LoadURL( |
1868 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1929 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1930 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1869 | 1931 |
1870 EXPECT_TRUE(controller.GetPendingEntry()); | 1932 EXPECT_TRUE(controller.GetPendingEntry()); |
1871 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1933 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1872 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1934 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
1873 | 1935 |
| 1936 params.nav_entry_id = entry_id; |
| 1937 params.did_create_new_entry = false; |
1874 params.is_post = false; | 1938 params.is_post = false; |
1875 | 1939 |
1876 EXPECT_EQ(0U, notifications.size()); | 1940 EXPECT_EQ(0U, notifications.size()); |
1877 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1941 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
1878 &details)); | 1942 &details)); |
1879 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1943 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1880 navigation_entry_committed_counter_ = 0; | 1944 navigation_entry_committed_counter_ = 0; |
1881 | 1945 |
1882 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); | 1946 EXPECT_TRUE(details.type == NAVIGATION_TYPE_SAME_PAGE); |
1883 EXPECT_EQ(controller.GetEntryCount(), 1); | 1947 EXPECT_EQ(controller.GetEntryCount(), 1); |
(...skipping 13 matching lines...) Expand all Loading... |
1897 NavigationControllerImpl& controller = controller_impl(); | 1961 NavigationControllerImpl& controller = controller_impl(); |
1898 TestNotificationTracker notifications; | 1962 TestNotificationTracker notifications; |
1899 RegisterForAllNavNotifications(¬ifications, &controller); | 1963 RegisterForAllNavNotifications(¬ifications, &controller); |
1900 | 1964 |
1901 const GURL url1("http://foo1"); | 1965 const GURL url1("http://foo1"); |
1902 const GURL url2("http://foo2"); // Redirection target | 1966 const GURL url2("http://foo2"); // Redirection target |
1903 | 1967 |
1904 // First request | 1968 // First request |
1905 controller.LoadURL( | 1969 controller.LoadURL( |
1906 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1970 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1971 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
1907 | 1972 |
1908 EXPECT_TRUE(controller.GetPendingEntry()); | 1973 EXPECT_TRUE(controller.GetPendingEntry()); |
1909 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1974 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1910 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1975 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
1911 | 1976 |
1912 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1977 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1913 params.page_id = 0; | 1978 params.page_id = 0; |
| 1979 params.nav_entry_id = entry_id; |
| 1980 params.did_create_new_entry = true; |
1914 params.url = url2; | 1981 params.url = url2; |
1915 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; | 1982 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; |
1916 params.redirects.push_back(GURL("http://foo1")); | 1983 params.redirects.push_back(GURL("http://foo1")); |
1917 params.redirects.push_back(GURL("http://foo2")); | 1984 params.redirects.push_back(GURL("http://foo2")); |
1918 params.should_update_history = false; | 1985 params.should_update_history = false; |
1919 params.gesture = NavigationGestureAuto; | 1986 params.gesture = NavigationGestureAuto; |
1920 params.is_post = false; | 1987 params.is_post = false; |
1921 params.page_state = PageState::CreateFromURL(url2); | 1988 params.page_state = PageState::CreateFromURL(url2); |
1922 | 1989 |
1923 LoadCommittedDetails details; | 1990 LoadCommittedDetails details; |
(...skipping 30 matching lines...) Expand all Loading... |
1954 // | 2021 // |
1955 // (This is a unit test rather than a browser test because it's not currently | 2022 // (This is a unit test rather than a browser test because it's not currently |
1956 // possible to force this sequence of events with a browser test.) | 2023 // possible to force this sequence of events with a browser test.) |
1957 TEST_F(NavigationControllerTest, | 2024 TEST_F(NavigationControllerTest, |
1958 NavigationTypeClassification_ExistingPageRace) { | 2025 NavigationTypeClassification_ExistingPageRace) { |
1959 NavigationControllerImpl& controller = controller_impl(); | 2026 NavigationControllerImpl& controller = controller_impl(); |
1960 const GURL url1("http://foo1"); | 2027 const GURL url1("http://foo1"); |
1961 const GURL url2("http://foo2"); | 2028 const GURL url2("http://foo2"); |
1962 | 2029 |
1963 // Start with a loaded page. | 2030 // Start with a loaded page. |
1964 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2031 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
1965 EXPECT_EQ(nullptr, controller_impl().GetPendingEntry()); | 2032 EXPECT_EQ(nullptr, controller_impl().GetPendingEntry()); |
1966 | 2033 |
1967 // Start a load of the same page again. | 2034 // Start a load of the same page again. |
1968 controller.LoadURL( | 2035 controller.LoadURL( |
1969 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2036 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1970 NavigationEntry* pending1 = controller.GetPendingEntry(); | 2037 int entry_id1 = controller.GetPendingEntry()->GetUniqueID(); |
1971 EXPECT_NE(nullptr, pending1); | |
1972 | 2038 |
1973 // Immediately start loading a different page... | 2039 // Immediately start loading a different page... |
1974 controller.LoadURL( | 2040 controller.LoadURL( |
1975 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2041 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1976 NavigationEntry* pending2 = controller.GetPendingEntry(); | 2042 int entry_id2 = controller.GetPendingEntry()->GetUniqueID(); |
1977 EXPECT_NE(nullptr, pending2); | 2043 EXPECT_NE(entry_id1, entry_id2); |
1978 EXPECT_NE(pending1, pending2); | |
1979 | 2044 |
1980 // ... and now the renderer sends a commit for the first navigation. | 2045 // ... and now the renderer sends a commit for the first navigation. |
1981 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2046 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1982 params.page_id = 0; | 2047 params.page_id = 0; |
| 2048 params.nav_entry_id = entry_id1; |
| 2049 params.intended_as_new_entry = true; |
| 2050 params.did_create_new_entry = false; |
1983 params.url = url1; | 2051 params.url = url1; |
1984 params.transition = ui::PAGE_TRANSITION_TYPED; | 2052 params.transition = ui::PAGE_TRANSITION_TYPED; |
1985 params.page_state = PageState::CreateFromURL(url1); | 2053 params.page_state = PageState::CreateFromURL(url1); |
1986 | 2054 |
1987 LoadCommittedDetails details; | 2055 LoadCommittedDetails details; |
1988 | 2056 |
1989 main_test_rfh()->PrepareForCommit(); | 2057 main_test_rfh()->PrepareForCommit(); |
1990 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2058 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
1991 &details)); | 2059 &details)); |
1992 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); | 2060 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); |
1993 } | 2061 } |
1994 | 2062 |
1995 // Tests navigation via link click within a subframe. A new navigation entry | 2063 // Tests navigation via link click within a subframe. A new navigation entry |
1996 // should be created. | 2064 // should be created. |
1997 TEST_F(NavigationControllerTest, NewSubframe) { | 2065 TEST_F(NavigationControllerTest, NewSubframe) { |
1998 NavigationControllerImpl& controller = controller_impl(); | 2066 NavigationControllerImpl& controller = controller_impl(); |
1999 TestNotificationTracker notifications; | 2067 TestNotificationTracker notifications; |
2000 RegisterForAllNavNotifications(¬ifications, &controller); | 2068 RegisterForAllNavNotifications(¬ifications, &controller); |
2001 | 2069 |
2002 const GURL url1("http://foo1"); | 2070 const GURL url1("http://foo1"); |
2003 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2071 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
2004 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2072 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2005 navigation_entry_committed_counter_ = 0; | 2073 navigation_entry_committed_counter_ = 0; |
2006 | 2074 |
2007 const GURL url2("http://foo2"); | 2075 const GURL url2("http://foo2"); |
2008 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2076 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2009 params.page_id = 1; | 2077 params.page_id = 1; |
| 2078 params.nav_entry_id = 0; |
| 2079 params.did_create_new_entry = true; |
2010 params.url = url2; | 2080 params.url = url2; |
2011 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2081 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2012 params.should_update_history = false; | 2082 params.should_update_history = false; |
2013 params.gesture = NavigationGestureUser; | 2083 params.gesture = NavigationGestureUser; |
2014 params.is_post = false; | 2084 params.is_post = false; |
2015 params.page_state = PageState::CreateFromURL(url2); | 2085 params.page_state = PageState::CreateFromURL(url2); |
2016 | 2086 |
2017 LoadCommittedDetails details; | 2087 LoadCommittedDetails details; |
2018 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2088 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2019 &details)); | 2089 &details)); |
(...skipping 15 matching lines...) Expand all Loading... |
2035 // Auto subframes are ones the page loads automatically like ads. They should | 2105 // Auto subframes are ones the page loads automatically like ads. They should |
2036 // not create new navigation entries. | 2106 // not create new navigation entries. |
2037 // TODO(creis): Test cross-site and nested iframes. | 2107 // TODO(creis): Test cross-site and nested iframes. |
2038 // TODO(creis): Test updating entries for history auto subframe navigations. | 2108 // TODO(creis): Test updating entries for history auto subframe navigations. |
2039 TEST_F(NavigationControllerTest, AutoSubframe) { | 2109 TEST_F(NavigationControllerTest, AutoSubframe) { |
2040 NavigationControllerImpl& controller = controller_impl(); | 2110 NavigationControllerImpl& controller = controller_impl(); |
2041 TestNotificationTracker notifications; | 2111 TestNotificationTracker notifications; |
2042 RegisterForAllNavNotifications(¬ifications, &controller); | 2112 RegisterForAllNavNotifications(¬ifications, &controller); |
2043 | 2113 |
2044 const GURL url1("http://foo/1"); | 2114 const GURL url1("http://foo/1"); |
2045 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url1); | 2115 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); |
2046 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2116 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2047 navigation_entry_committed_counter_ = 0; | 2117 navigation_entry_committed_counter_ = 0; |
2048 | 2118 |
2049 // Add a subframe and navigate it. | 2119 // Add a subframe and navigate it. |
2050 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), | 2120 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
2051 SandboxFlags::NONE); | 2121 SandboxFlags::NONE); |
2052 RenderFrameHostImpl* subframe = | 2122 RenderFrameHostImpl* subframe = |
2053 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); | 2123 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
2054 const GURL url2("http://foo/2"); | 2124 const GURL url2("http://foo/2"); |
2055 { | 2125 { |
2056 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2126 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2057 params.page_id = 1; | 2127 params.page_id = 1; |
| 2128 params.nav_entry_id = 0; |
| 2129 params.did_create_new_entry = false; |
2058 params.url = url2; | 2130 params.url = url2; |
2059 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2131 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
2060 params.should_update_history = false; | 2132 params.should_update_history = false; |
2061 params.gesture = NavigationGestureUser; | 2133 params.gesture = NavigationGestureUser; |
2062 params.is_post = false; | 2134 params.is_post = false; |
2063 params.page_state = PageState::CreateFromURL(url2); | 2135 params.page_state = PageState::CreateFromURL(url2); |
2064 | 2136 |
2065 // Navigating should do nothing. | 2137 // Navigating should do nothing. |
2066 LoadCommittedDetails details; | 2138 LoadCommittedDetails details; |
2067 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); | 2139 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 } | 2206 } |
2135 | 2207 |
2136 // Tests navigation and then going back to a subframe navigation. | 2208 // Tests navigation and then going back to a subframe navigation. |
2137 TEST_F(NavigationControllerTest, BackSubframe) { | 2209 TEST_F(NavigationControllerTest, BackSubframe) { |
2138 NavigationControllerImpl& controller = controller_impl(); | 2210 NavigationControllerImpl& controller = controller_impl(); |
2139 TestNotificationTracker notifications; | 2211 TestNotificationTracker notifications; |
2140 RegisterForAllNavNotifications(¬ifications, &controller); | 2212 RegisterForAllNavNotifications(¬ifications, &controller); |
2141 | 2213 |
2142 // Main page. | 2214 // Main page. |
2143 const GURL url1("http://foo1"); | 2215 const GURL url1("http://foo1"); |
2144 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2216 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
2145 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2217 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
| 2218 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
2146 navigation_entry_committed_counter_ = 0; | 2219 navigation_entry_committed_counter_ = 0; |
2147 | 2220 |
2148 // First manual subframe navigation. | 2221 // First manual subframe navigation. |
2149 const GURL url2("http://foo2"); | 2222 const GURL url2("http://foo2"); |
2150 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2223 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2151 params.page_id = 1; | 2224 params.page_id = 1; |
| 2225 params.nav_entry_id = 0; |
| 2226 params.did_create_new_entry = true; |
2152 params.url = url2; | 2227 params.url = url2; |
2153 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2228 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2154 params.should_update_history = false; | 2229 params.should_update_history = false; |
2155 params.gesture = NavigationGestureUser; | 2230 params.gesture = NavigationGestureUser; |
2156 params.is_post = false; | 2231 params.is_post = false; |
2157 params.page_state = PageState::CreateFromURL(url2); | 2232 params.page_state = PageState::CreateFromURL(url2); |
2158 | 2233 |
2159 // This should generate a new entry. | 2234 // This should generate a new entry. |
2160 LoadCommittedDetails details; | 2235 LoadCommittedDetails details; |
2161 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2236 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2162 &details)); | 2237 &details)); |
| 2238 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
2163 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2239 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2164 navigation_entry_committed_counter_ = 0; | 2240 navigation_entry_committed_counter_ = 0; |
2165 EXPECT_EQ(2, controller.GetEntryCount()); | 2241 EXPECT_EQ(2, controller.GetEntryCount()); |
2166 | 2242 |
2167 // Second manual subframe navigation should also make a new entry. | 2243 // Second manual subframe navigation should also make a new entry. |
2168 const GURL url3("http://foo3"); | 2244 const GURL url3("http://foo3"); |
2169 params.page_id = 2; | 2245 params.page_id = 2; |
| 2246 params.nav_entry_id = 0; |
| 2247 params.did_create_new_entry = true; |
2170 params.url = url3; | 2248 params.url = url3; |
2171 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2249 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2172 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2250 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2173 &details)); | 2251 &details)); |
2174 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2252 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2175 navigation_entry_committed_counter_ = 0; | 2253 navigation_entry_committed_counter_ = 0; |
2176 EXPECT_EQ(3, controller.GetEntryCount()); | 2254 EXPECT_EQ(3, controller.GetEntryCount()); |
2177 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2255 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2178 | 2256 |
2179 // Go back one. | 2257 // Go back one. |
2180 controller.GoBack(); | 2258 controller.GoBack(); |
2181 params.page_id = 1; | 2259 params.page_id = 1; |
| 2260 params.nav_entry_id = entry2->GetUniqueID(); |
| 2261 params.did_create_new_entry = false; |
2182 params.url = url2; | 2262 params.url = url2; |
2183 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2263 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
2184 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2264 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2185 &details)); | 2265 &details)); |
2186 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2266 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2187 navigation_entry_committed_counter_ = 0; | 2267 navigation_entry_committed_counter_ = 0; |
2188 EXPECT_EQ(3, controller.GetEntryCount()); | 2268 EXPECT_EQ(3, controller.GetEntryCount()); |
2189 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2269 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
2190 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2270 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2191 EXPECT_FALSE(controller.GetPendingEntry()); | 2271 EXPECT_FALSE(controller.GetPendingEntry()); |
2192 | 2272 |
2193 // Go back one more. | 2273 // Go back one more. |
2194 controller.GoBack(); | 2274 controller.GoBack(); |
2195 params.page_id = 0; | 2275 params.page_id = 0; |
| 2276 params.nav_entry_id = entry1->GetUniqueID(); |
| 2277 params.did_create_new_entry = false; |
2196 params.url = url1; | 2278 params.url = url1; |
2197 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2279 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
2198 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2280 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2199 &details)); | 2281 &details)); |
2200 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2282 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2201 navigation_entry_committed_counter_ = 0; | 2283 navigation_entry_committed_counter_ = 0; |
2202 EXPECT_EQ(3, controller.GetEntryCount()); | 2284 EXPECT_EQ(3, controller.GetEntryCount()); |
2203 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2285 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
2204 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2286 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2205 EXPECT_FALSE(controller.GetPendingEntry()); | 2287 EXPECT_FALSE(controller.GetPendingEntry()); |
2206 } | 2288 } |
2207 | 2289 |
2208 TEST_F(NavigationControllerTest, LinkClick) { | 2290 TEST_F(NavigationControllerTest, LinkClick) { |
2209 NavigationControllerImpl& controller = controller_impl(); | 2291 NavigationControllerImpl& controller = controller_impl(); |
2210 TestNotificationTracker notifications; | 2292 TestNotificationTracker notifications; |
2211 RegisterForAllNavNotifications(¬ifications, &controller); | 2293 RegisterForAllNavNotifications(¬ifications, &controller); |
2212 | 2294 |
2213 const GURL url1("http://foo1"); | 2295 const GURL url1("http://foo1"); |
2214 const GURL url2("http://foo2"); | 2296 const GURL url2("http://foo2"); |
2215 | 2297 |
2216 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2298 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
2217 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2299 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2218 navigation_entry_committed_counter_ = 0; | 2300 navigation_entry_committed_counter_ = 0; |
2219 | 2301 |
2220 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2); | 2302 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url2); |
2221 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2303 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2222 navigation_entry_committed_counter_ = 0; | 2304 navigation_entry_committed_counter_ = 0; |
2223 | 2305 |
2224 // Should not have produced a new session history entry. | 2306 // Should have produced a new session history entry. |
2225 EXPECT_EQ(controller.GetEntryCount(), 2); | 2307 EXPECT_EQ(controller.GetEntryCount(), 2); |
2226 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2308 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2227 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2309 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2228 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2310 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2229 EXPECT_FALSE(controller.GetPendingEntry()); | 2311 EXPECT_FALSE(controller.GetPendingEntry()); |
2230 EXPECT_TRUE(controller.CanGoBack()); | 2312 EXPECT_TRUE(controller.CanGoBack()); |
2231 EXPECT_FALSE(controller.CanGoForward()); | 2313 EXPECT_FALSE(controller.CanGoForward()); |
2232 } | 2314 } |
2233 | 2315 |
2234 TEST_F(NavigationControllerTest, InPage) { | 2316 TEST_F(NavigationControllerTest, InPage) { |
2235 NavigationControllerImpl& controller = controller_impl(); | 2317 NavigationControllerImpl& controller = controller_impl(); |
2236 TestNotificationTracker notifications; | 2318 TestNotificationTracker notifications; |
2237 RegisterForAllNavNotifications(¬ifications, &controller); | 2319 RegisterForAllNavNotifications(¬ifications, &controller); |
2238 | 2320 |
2239 // Main page. | 2321 // Main page. |
2240 const GURL url1("http://foo"); | 2322 const GURL url1("http://foo"); |
2241 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2323 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
2242 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2324 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2243 navigation_entry_committed_counter_ = 0; | 2325 navigation_entry_committed_counter_ = 0; |
2244 | 2326 |
2245 // Ensure main page navigation to same url respects the was_within_same_page | 2327 // Ensure main page navigation to same url respects the was_within_same_page |
2246 // hint provided in the params. | 2328 // hint provided in the params. |
2247 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; | 2329 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; |
2248 self_params.page_id = 0; | 2330 self_params.page_id = 0; |
| 2331 self_params.nav_entry_id = 0; |
| 2332 self_params.did_create_new_entry = false; |
2249 self_params.url = url1; | 2333 self_params.url = url1; |
2250 self_params.transition = ui::PAGE_TRANSITION_LINK; | 2334 self_params.transition = ui::PAGE_TRANSITION_LINK; |
2251 self_params.should_update_history = false; | 2335 self_params.should_update_history = false; |
2252 self_params.gesture = NavigationGestureUser; | 2336 self_params.gesture = NavigationGestureUser; |
2253 self_params.is_post = false; | 2337 self_params.is_post = false; |
2254 self_params.page_state = PageState::CreateFromURL(url1); | 2338 self_params.page_state = PageState::CreateFromURL(url1); |
2255 self_params.was_within_same_page = true; | 2339 self_params.was_within_same_page = true; |
2256 | 2340 |
2257 LoadCommittedDetails details; | 2341 LoadCommittedDetails details; |
2258 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, | 2342 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, |
2259 &details)); | 2343 &details)); |
| 2344 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); |
2260 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2345 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2261 navigation_entry_committed_counter_ = 0; | 2346 navigation_entry_committed_counter_ = 0; |
2262 EXPECT_TRUE(details.is_in_page); | 2347 EXPECT_TRUE(details.is_in_page); |
2263 EXPECT_TRUE(details.did_replace_entry); | 2348 EXPECT_TRUE(details.did_replace_entry); |
2264 EXPECT_EQ(1, controller.GetEntryCount()); | 2349 EXPECT_EQ(1, controller.GetEntryCount()); |
2265 | 2350 |
2266 // Fragment navigation to a new page_id. | 2351 // Fragment navigation to a new page_id. |
2267 const GURL url2("http://foo#a"); | 2352 const GURL url2("http://foo#a"); |
2268 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2353 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2269 params.page_id = 1; | 2354 params.page_id = 1; |
| 2355 params.nav_entry_id = 0; |
| 2356 params.did_create_new_entry = true; |
2270 params.url = url2; | 2357 params.url = url2; |
2271 params.transition = ui::PAGE_TRANSITION_LINK; | 2358 params.transition = ui::PAGE_TRANSITION_LINK; |
2272 params.should_update_history = false; | 2359 params.should_update_history = false; |
2273 params.gesture = NavigationGestureUser; | 2360 params.gesture = NavigationGestureUser; |
2274 params.is_post = false; | 2361 params.is_post = false; |
2275 params.page_state = PageState::CreateFromURL(url2); | 2362 params.page_state = PageState::CreateFromURL(url2); |
2276 params.was_within_same_page = true; | 2363 params.was_within_same_page = true; |
2277 | 2364 |
2278 // This should generate a new entry. | 2365 // This should generate a new entry. |
2279 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2366 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2280 &details)); | 2367 &details)); |
| 2368 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); |
2281 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2369 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2282 navigation_entry_committed_counter_ = 0; | 2370 navigation_entry_committed_counter_ = 0; |
2283 EXPECT_TRUE(details.is_in_page); | 2371 EXPECT_TRUE(details.is_in_page); |
2284 EXPECT_FALSE(details.did_replace_entry); | 2372 EXPECT_FALSE(details.did_replace_entry); |
2285 EXPECT_EQ(2, controller.GetEntryCount()); | 2373 EXPECT_EQ(2, controller.GetEntryCount()); |
2286 | 2374 |
2287 // Go back one. | 2375 // Go back one. |
2288 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); | 2376 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); |
2289 controller.GoBack(); | 2377 controller.GoBack(); |
2290 back_params.url = url1; | 2378 back_params.url = url1; |
2291 back_params.page_id = 0; | 2379 back_params.page_id = 0; |
| 2380 back_params.nav_entry_id = entry1->GetUniqueID(); |
| 2381 back_params.did_create_new_entry = false; |
2292 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, | 2382 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, |
2293 &details)); | 2383 &details)); |
2294 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2384 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2295 navigation_entry_committed_counter_ = 0; | 2385 navigation_entry_committed_counter_ = 0; |
2296 EXPECT_TRUE(details.is_in_page); | 2386 EXPECT_TRUE(details.is_in_page); |
2297 EXPECT_EQ(2, controller.GetEntryCount()); | 2387 EXPECT_EQ(2, controller.GetEntryCount()); |
2298 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2388 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
2299 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); | 2389 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
2300 | 2390 |
2301 // Go forward | 2391 // Go forward. |
2302 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); | 2392 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); |
2303 controller.GoForward(); | 2393 controller.GoForward(); |
2304 forward_params.url = url2; | 2394 forward_params.url = url2; |
2305 forward_params.page_id = 1; | 2395 forward_params.page_id = 1; |
| 2396 forward_params.nav_entry_id = entry2->GetUniqueID(); |
| 2397 forward_params.did_create_new_entry = false; |
2306 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, | 2398 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, |
2307 &details)); | 2399 &details)); |
2308 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2400 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2309 navigation_entry_committed_counter_ = 0; | 2401 navigation_entry_committed_counter_ = 0; |
2310 EXPECT_TRUE(details.is_in_page); | 2402 EXPECT_TRUE(details.is_in_page); |
2311 EXPECT_EQ(2, controller.GetEntryCount()); | 2403 EXPECT_EQ(2, controller.GetEntryCount()); |
2312 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2404 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
2313 EXPECT_EQ(forward_params.url, | 2405 EXPECT_EQ(forward_params.url, |
2314 controller.GetVisibleEntry()->GetURL()); | 2406 controller.GetVisibleEntry()->GetURL()); |
2315 | 2407 |
2316 // Now go back and forward again. This is to work around a bug where we would | 2408 // Now go back and forward again. This is to work around a bug where we would |
2317 // compare the incoming URL with the last committed entry rather than the | 2409 // compare the incoming URL with the last committed entry rather than the |
2318 // one identified by an existing page ID. This would result in the second URL | 2410 // one identified by an existing page ID. This would result in the second URL |
2319 // losing the reference fragment when you navigate away from it and then back. | 2411 // losing the reference fragment when you navigate away from it and then back. |
2320 controller.GoBack(); | 2412 controller.GoBack(); |
2321 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, | 2413 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, |
2322 &details)); | 2414 &details)); |
2323 controller.GoForward(); | 2415 controller.GoForward(); |
2324 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, | 2416 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, |
2325 &details)); | 2417 &details)); |
2326 EXPECT_EQ(forward_params.url, | 2418 EXPECT_EQ(forward_params.url, |
2327 controller.GetVisibleEntry()->GetURL()); | 2419 controller.GetVisibleEntry()->GetURL()); |
2328 | 2420 |
2329 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 2421 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
2330 const GURL url3("http://bar"); | 2422 const GURL url3("http://bar"); |
2331 params.page_id = 2; | 2423 params.page_id = 2; |
| 2424 params.nav_entry_id = 0; |
| 2425 params.did_create_new_entry = true; |
2332 params.url = url3; | 2426 params.url = url3; |
2333 navigation_entry_committed_counter_ = 0; | 2427 navigation_entry_committed_counter_ = 0; |
2334 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2428 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2335 &details)); | 2429 &details)); |
2336 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2430 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2337 navigation_entry_committed_counter_ = 0; | 2431 navigation_entry_committed_counter_ = 0; |
2338 EXPECT_FALSE(details.is_in_page); | 2432 EXPECT_FALSE(details.is_in_page); |
2339 EXPECT_EQ(3, controller.GetEntryCount()); | 2433 EXPECT_EQ(3, controller.GetEntryCount()); |
2340 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2434 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2341 } | 2435 } |
2342 | 2436 |
2343 TEST_F(NavigationControllerTest, InPage_Replace) { | 2437 TEST_F(NavigationControllerTest, InPage_Replace) { |
2344 NavigationControllerImpl& controller = controller_impl(); | 2438 NavigationControllerImpl& controller = controller_impl(); |
2345 TestNotificationTracker notifications; | 2439 TestNotificationTracker notifications; |
2346 RegisterForAllNavNotifications(¬ifications, &controller); | 2440 RegisterForAllNavNotifications(¬ifications, &controller); |
2347 | 2441 |
2348 // Main page. | 2442 // Main page. |
2349 const GURL url1("http://foo"); | 2443 const GURL url1("http://foo"); |
2350 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 2444 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
2351 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2445 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2352 navigation_entry_committed_counter_ = 0; | 2446 navigation_entry_committed_counter_ = 0; |
2353 | 2447 |
2354 // First navigation. | 2448 // First navigation. |
2355 const GURL url2("http://foo#a"); | 2449 const GURL url2("http://foo#a"); |
2356 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2450 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2357 params.page_id = 0; // Same page_id | 2451 params.page_id = 0; // Same page_id |
| 2452 params.nav_entry_id = 0; |
| 2453 params.did_create_new_entry = false; |
2358 params.url = url2; | 2454 params.url = url2; |
2359 params.transition = ui::PAGE_TRANSITION_LINK; | 2455 params.transition = ui::PAGE_TRANSITION_LINK; |
2360 params.should_update_history = false; | 2456 params.should_update_history = false; |
2361 params.gesture = NavigationGestureUser; | 2457 params.gesture = NavigationGestureUser; |
2362 params.is_post = false; | 2458 params.is_post = false; |
2363 params.page_state = PageState::CreateFromURL(url2); | 2459 params.page_state = PageState::CreateFromURL(url2); |
2364 params.was_within_same_page = true; | 2460 params.was_within_same_page = true; |
2365 | 2461 |
2366 // This should NOT generate a new entry, nor prune the list. | 2462 // This should NOT generate a new entry, nor prune the list. |
2367 LoadCommittedDetails details; | 2463 LoadCommittedDetails details; |
(...skipping 13 matching lines...) Expand all Loading... |
2381 // window.location='http://foo3/'; | 2477 // window.location='http://foo3/'; |
2382 // </script> | 2478 // </script> |
2383 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 2479 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
2384 NavigationControllerImpl& controller = controller_impl(); | 2480 NavigationControllerImpl& controller = controller_impl(); |
2385 TestNotificationTracker notifications; | 2481 TestNotificationTracker notifications; |
2386 RegisterForAllNavNotifications(¬ifications, &controller); | 2482 RegisterForAllNavNotifications(¬ifications, &controller); |
2387 | 2483 |
2388 // Load an initial page. | 2484 // Load an initial page. |
2389 { | 2485 { |
2390 const GURL url("http://foo/"); | 2486 const GURL url("http://foo/"); |
2391 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 2487 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); |
2392 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2488 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2393 navigation_entry_committed_counter_ = 0; | 2489 navigation_entry_committed_counter_ = 0; |
2394 } | 2490 } |
2395 | 2491 |
2396 // Navigate to a new page. | 2492 // Navigate to a new page. |
2397 { | 2493 { |
2398 const GURL url("http://foo2/"); | 2494 const GURL url("http://foo2/"); |
2399 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url); | 2495 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url); |
2400 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2496 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2401 navigation_entry_committed_counter_ = 0; | 2497 navigation_entry_committed_counter_ = 0; |
2402 } | 2498 } |
2403 | 2499 |
2404 // Navigate within the page. | 2500 // Navigate within the page. |
2405 { | 2501 { |
2406 const GURL url("http://foo2/#a"); | 2502 const GURL url("http://foo2/#a"); |
2407 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2503 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2408 params.page_id = 1; // Same page_id | 2504 params.page_id = 1; // Same page_id |
| 2505 params.nav_entry_id = 0; |
| 2506 params.did_create_new_entry = false; |
2409 params.url = url; | 2507 params.url = url; |
2410 params.transition = ui::PAGE_TRANSITION_LINK; | 2508 params.transition = ui::PAGE_TRANSITION_LINK; |
2411 params.redirects.push_back(url); | 2509 params.redirects.push_back(url); |
2412 params.should_update_history = true; | 2510 params.should_update_history = true; |
2413 params.gesture = NavigationGestureUnknown; | 2511 params.gesture = NavigationGestureUnknown; |
2414 params.is_post = false; | 2512 params.is_post = false; |
2415 params.page_state = PageState::CreateFromURL(url); | 2513 params.page_state = PageState::CreateFromURL(url); |
2416 params.was_within_same_page = true; | 2514 params.was_within_same_page = true; |
2417 | 2515 |
2418 // This should NOT generate a new entry, nor prune the list. | 2516 // This should NOT generate a new entry, nor prune the list. |
2419 LoadCommittedDetails details; | 2517 LoadCommittedDetails details; |
2420 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2518 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2421 &details)); | 2519 &details)); |
2422 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2520 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2423 navigation_entry_committed_counter_ = 0; | 2521 navigation_entry_committed_counter_ = 0; |
2424 EXPECT_TRUE(details.is_in_page); | 2522 EXPECT_TRUE(details.is_in_page); |
2425 EXPECT_TRUE(details.did_replace_entry); | 2523 EXPECT_TRUE(details.did_replace_entry); |
2426 EXPECT_EQ(2, controller.GetEntryCount()); | 2524 EXPECT_EQ(2, controller.GetEntryCount()); |
2427 } | 2525 } |
2428 | 2526 |
2429 // Perform a client redirect to a new page. | 2527 // Perform a client redirect to a new page. |
2430 { | 2528 { |
2431 const GURL url("http://foo3/"); | 2529 const GURL url("http://foo3/"); |
2432 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2530 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2433 params.page_id = 2; // New page_id | 2531 params.page_id = 2; // New page_id |
| 2532 params.nav_entry_id = 0; |
| 2533 params.did_create_new_entry = true; |
2434 params.url = url; | 2534 params.url = url; |
2435 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 2535 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
2436 params.redirects.push_back(GURL("http://foo2/#a")); | 2536 params.redirects.push_back(GURL("http://foo2/#a")); |
2437 params.redirects.push_back(url); | 2537 params.redirects.push_back(url); |
2438 params.should_update_history = true; | 2538 params.should_update_history = true; |
2439 params.gesture = NavigationGestureUnknown; | 2539 params.gesture = NavigationGestureUnknown; |
2440 params.is_post = false; | 2540 params.is_post = false; |
2441 params.page_state = PageState::CreateFromURL(url); | 2541 params.page_state = PageState::CreateFromURL(url); |
2442 | 2542 |
2443 // This SHOULD generate a new entry. | 2543 // This SHOULD generate a new entry. |
2444 LoadCommittedDetails details; | 2544 LoadCommittedDetails details; |
2445 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2545 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2446 &details)); | 2546 &details)); |
2447 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2547 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2448 navigation_entry_committed_counter_ = 0; | 2548 navigation_entry_committed_counter_ = 0; |
2449 EXPECT_FALSE(details.is_in_page); | 2549 EXPECT_FALSE(details.is_in_page); |
2450 EXPECT_EQ(3, controller.GetEntryCount()); | 2550 EXPECT_EQ(3, controller.GetEntryCount()); |
2451 } | 2551 } |
2452 | 2552 |
2453 // Verify that BACK brings us back to http://foo2/. | 2553 // Verify that BACK brings us back to http://foo2/. |
2454 { | 2554 { |
2455 const GURL url("http://foo2/"); | 2555 const GURL url("http://foo2/"); |
2456 controller.GoBack(); | 2556 controller.GoBack(); |
| 2557 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2457 main_test_rfh()->PrepareForCommit(); | 2558 main_test_rfh()->PrepareForCommit(); |
2458 main_test_rfh()->SendNavigate(1, url); | 2559 main_test_rfh()->SendNavigate(1, entry_id, false, url); |
2459 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2560 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2460 navigation_entry_committed_counter_ = 0; | 2561 navigation_entry_committed_counter_ = 0; |
2461 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2562 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
2462 } | 2563 } |
2463 } | 2564 } |
2464 | 2565 |
2465 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) | 2566 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) |
2466 { | 2567 { |
2467 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); | 2568 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); |
2468 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2569 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2469 GURL url("http://foo"); | 2570 GURL url("http://foo"); |
2470 params.page_id = 1; | 2571 params.page_id = 1; |
| 2572 params.nav_entry_id = 0; |
| 2573 params.did_create_new_entry = true; |
2471 params.url = url; | 2574 params.url = url; |
2472 params.page_state = PageState::CreateFromURL(url); | 2575 params.page_state = PageState::CreateFromURL(url); |
2473 params.was_within_same_page = true; | 2576 params.was_within_same_page = true; |
2474 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 2577 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
2475 main_test_rfh()->PrepareForCommit(); | 2578 main_test_rfh()->PrepareForCommit(); |
2476 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 2579 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
2477 // We pass if we don't crash. | 2580 // We pass if we don't crash. |
2478 } | 2581 } |
2479 | 2582 |
2480 // NotificationObserver implementation used in verifying we've received the | 2583 // NotificationObserver implementation used in verifying we've received the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 const int kMaxEntryCount = 5; | 2618 const int kMaxEntryCount = 5; |
2516 | 2619 |
2517 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2620 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
2518 | 2621 |
2519 int url_index; | 2622 int url_index; |
2520 // Load up to the max count, all entries should be there. | 2623 // Load up to the max count, all entries should be there. |
2521 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2624 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
2522 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2625 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2523 controller.LoadURL( | 2626 controller.LoadURL( |
2524 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2627 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2628 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2525 main_test_rfh()->PrepareForCommit(); | 2629 main_test_rfh()->PrepareForCommit(); |
2526 main_test_rfh()->SendNavigate(url_index, url); | 2630 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); |
2527 } | 2631 } |
2528 | 2632 |
2529 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2633 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2530 | 2634 |
2531 // Created a PrunedListener to observe prune notifications. | 2635 // Created a PrunedListener to observe prune notifications. |
2532 PrunedListener listener(&controller); | 2636 PrunedListener listener(&controller); |
2533 | 2637 |
2534 // Navigate some more. | 2638 // Navigate some more. |
2535 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2639 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2536 controller.LoadURL( | 2640 controller.LoadURL( |
2537 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2641 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2642 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2538 main_test_rfh()->PrepareForCommit(); | 2643 main_test_rfh()->PrepareForCommit(); |
2539 main_test_rfh()->SendNavigate(url_index, url); | 2644 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); |
2540 url_index++; | 2645 url_index++; |
2541 | 2646 |
2542 // We should have got a pruned navigation. | 2647 // We should have got a pruned navigation. |
2543 EXPECT_EQ(1, listener.notification_count_); | 2648 EXPECT_EQ(1, listener.notification_count_); |
2544 EXPECT_TRUE(listener.details_.from_front); | 2649 EXPECT_TRUE(listener.details_.from_front); |
2545 EXPECT_EQ(1, listener.details_.count); | 2650 EXPECT_EQ(1, listener.details_.count); |
2546 | 2651 |
2547 // We expect http://www.a.com/0 to be gone. | 2652 // We expect http://www.a.com/0 to be gone. |
2548 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2653 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2549 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2654 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2550 GURL("http:////www.a.com/1")); | 2655 GURL("http://www.a.com/1")); |
2551 | 2656 |
2552 // More navigations. | 2657 // More navigations. |
2553 for (int i = 0; i < 3; i++) { | 2658 for (int i = 0; i < 3; i++) { |
2554 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); | 2659 url = GURL(base::StringPrintf("http://www.a.com/%d", url_index)); |
2555 controller.LoadURL( | 2660 controller.LoadURL( |
2556 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2661 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2662 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2557 main_test_rfh()->PrepareForCommit(); | 2663 main_test_rfh()->PrepareForCommit(); |
2558 main_test_rfh()->SendNavigate(url_index, url); | 2664 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); |
2559 url_index++; | 2665 url_index++; |
2560 } | 2666 } |
2561 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2667 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2562 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2668 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2563 GURL("http:////www.a.com/4")); | 2669 GURL("http://www.a.com/4")); |
2564 | 2670 |
2565 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2671 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
2566 } | 2672 } |
2567 | 2673 |
2568 // Tests that we can do a restore and navigate to the restored entries and | 2674 // Tests that we can do a restore and navigate to the restored entries and |
2569 // everything is updated properly. This can be tricky since there is no | 2675 // everything is updated properly. This can be tricky since there is no |
2570 // SiteInstance for the entries created initially. | 2676 // SiteInstance for the entries created initially. |
2571 TEST_F(NavigationControllerTest, RestoreNavigate) { | 2677 TEST_F(NavigationControllerTest, RestoreNavigate) { |
2572 // Create a NavigationController with a restored set of tabs. | 2678 // Create a NavigationController with a restored set of tabs. |
2573 GURL url("http://foo"); | 2679 GURL url("http://foo"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2713 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2608 our_controller.GetEntryAtIndex(0)->restore_type()); | 2714 our_controller.GetEntryAtIndex(0)->restore_type()); |
2609 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2715 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2610 | 2716 |
2611 // Timestamp should remain the same before the navigation finishes. | 2717 // Timestamp should remain the same before the navigation finishes. |
2612 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); | 2718 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); |
2613 | 2719 |
2614 // Say we navigated to that entry. | 2720 // Say we navigated to that entry. |
2615 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2721 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2616 params.page_id = 0; | 2722 params.page_id = 0; |
| 2723 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID(); |
| 2724 params.did_create_new_entry = false; |
2617 params.url = url; | 2725 params.url = url; |
2618 params.transition = ui::PAGE_TRANSITION_LINK; | 2726 params.transition = ui::PAGE_TRANSITION_LINK; |
2619 params.should_update_history = false; | 2727 params.should_update_history = false; |
2620 params.gesture = NavigationGestureUser; | 2728 params.gesture = NavigationGestureUser; |
2621 params.is_post = false; | 2729 params.is_post = false; |
2622 params.page_state = PageState::CreateFromURL(url); | 2730 params.page_state = PageState::CreateFromURL(url); |
2623 LoadCommittedDetails details; | 2731 LoadCommittedDetails details; |
2624 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2732 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
2625 &details); | 2733 &details); |
2626 | 2734 |
(...skipping 28 matching lines...) Expand all Loading... |
2655 entries.push_back(entry); | 2763 entries.push_back(entry); |
2656 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 2764 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
2657 WebContents::Create(WebContents::CreateParams(browser_context())))); | 2765 WebContents::Create(WebContents::CreateParams(browser_context())))); |
2658 NavigationControllerImpl& our_controller = our_contents->GetController(); | 2766 NavigationControllerImpl& our_controller = our_contents->GetController(); |
2659 our_controller.Restore( | 2767 our_controller.Restore( |
2660 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | 2768 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
2661 ASSERT_EQ(0u, entries.size()); | 2769 ASSERT_EQ(0u, entries.size()); |
2662 | 2770 |
2663 // Before navigating to the restored entry, it should have a restore_type | 2771 // Before navigating to the restored entry, it should have a restore_type |
2664 // and no SiteInstance. | 2772 // and no SiteInstance. |
| 2773 entry = our_controller.GetEntryAtIndex(0); |
2665 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2774 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
2666 our_controller.GetEntryAtIndex(0)->restore_type()); | 2775 our_controller.GetEntryAtIndex(0)->restore_type()); |
2667 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2776 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2668 | 2777 |
2669 // After navigating, we should have one entry, and it should be "pending". | 2778 // After navigating, we should have one entry, and it should be "pending". |
2670 // It should now have a SiteInstance and no restore_type. | 2779 // It should now have a SiteInstance and no restore_type. |
2671 our_controller.GoToIndex(0); | 2780 our_controller.GoToIndex(0); |
2672 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2781 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2673 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 2782 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
2674 our_controller.GetPendingEntry()); | 2783 our_controller.GetPendingEntry()); |
2675 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 2784 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
2676 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2785 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2677 our_controller.GetEntryAtIndex(0)->restore_type()); | 2786 our_controller.GetEntryAtIndex(0)->restore_type()); |
2678 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2787 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2679 | 2788 |
2680 // This pending navigation may have caused a different navigation to fail, | 2789 // This pending navigation may have caused a different navigation to fail, |
2681 // which causes the pending entry to be cleared. | 2790 // which causes the pending entry to be cleared. |
2682 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; | 2791 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; |
2683 fail_load_params.error_code = net::ERR_ABORTED; | 2792 fail_load_params.error_code = net::ERR_ABORTED; |
2684 fail_load_params.error_description = base::string16(); | 2793 fail_load_params.error_description = base::string16(); |
2685 fail_load_params.url = url; | 2794 fail_load_params.url = url; |
2686 fail_load_params.showing_repost_interstitial = false; | 2795 fail_load_params.showing_repost_interstitial = false; |
2687 main_test_rfh()->OnMessageReceived( | 2796 main_test_rfh()->OnMessageReceived( |
2688 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 2797 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
2689 fail_load_params)); | 2798 fail_load_params)); |
2690 | 2799 |
2691 // Now the pending restored entry commits. | 2800 // Now the pending restored entry commits. |
2692 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2801 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2693 params.page_id = 0; | 2802 params.page_id = 0; |
| 2803 params.nav_entry_id = entry->GetUniqueID(); |
| 2804 params.did_create_new_entry = false; |
2694 params.url = url; | 2805 params.url = url; |
2695 params.transition = ui::PAGE_TRANSITION_LINK; | 2806 params.transition = ui::PAGE_TRANSITION_LINK; |
2696 params.should_update_history = false; | 2807 params.should_update_history = false; |
2697 params.gesture = NavigationGestureUser; | 2808 params.gesture = NavigationGestureUser; |
2698 params.is_post = false; | 2809 params.is_post = false; |
2699 params.page_state = PageState::CreateFromURL(url); | 2810 params.page_state = PageState::CreateFromURL(url); |
2700 LoadCommittedDetails details; | 2811 LoadCommittedDetails details; |
2701 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2812 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
2702 &details); | 2813 &details); |
2703 | 2814 |
2704 // There should be no pending entry and one committed one. | 2815 // There should be no pending entry and one committed one. |
2705 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2816 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2706 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 2817 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
2707 EXPECT_FALSE(our_controller.GetPendingEntry()); | 2818 EXPECT_FALSE(our_controller.GetPendingEntry()); |
2708 EXPECT_EQ( | 2819 EXPECT_EQ( |
2709 url, | 2820 url, |
2710 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 2821 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
2711 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2822 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2712 our_controller.GetEntryAtIndex(0)->restore_type()); | 2823 our_controller.GetEntryAtIndex(0)->restore_type()); |
2713 } | 2824 } |
2714 | 2825 |
2715 // Make sure that the page type and stuff is correct after an interstitial. | 2826 // Make sure that the page type and stuff is correct after an interstitial. |
2716 TEST_F(NavigationControllerTest, Interstitial) { | 2827 TEST_F(NavigationControllerTest, Interstitial) { |
2717 NavigationControllerImpl& controller = controller_impl(); | 2828 NavigationControllerImpl& controller = controller_impl(); |
2718 // First navigate somewhere normal. | 2829 // First navigate somewhere normal. |
2719 const GURL url1("http://foo"); | 2830 const GURL url1("http://foo"); |
2720 controller.LoadURL( | 2831 controller.LoadURL( |
2721 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2832 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2833 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2722 main_test_rfh()->PrepareForCommit(); | 2834 main_test_rfh()->PrepareForCommit(); |
2723 main_test_rfh()->SendNavigate(0, url1); | 2835 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
2724 | 2836 |
2725 // Now navigate somewhere with an interstitial. | 2837 // Now navigate somewhere with an interstitial. |
2726 const GURL url2("http://bar"); | 2838 const GURL url2("http://bar"); |
2727 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, | 2839 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
2728 std::string()); | 2840 std::string()); |
| 2841 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2729 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); | 2842 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); |
2730 | 2843 |
2731 // At this point the interstitial will be displayed and the load will still | 2844 // At this point the interstitial will be displayed and the load will still |
2732 // be pending. If the user continues, the load will commit. | 2845 // be pending. If the user continues, the load will commit. |
2733 main_test_rfh()->PrepareForCommit(); | 2846 main_test_rfh()->PrepareForCommit(); |
2734 main_test_rfh()->SendNavigate(1, url2); | 2847 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
2735 | 2848 |
2736 // The page should be a normal page again. | 2849 // The page should be a normal page again. |
2737 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2850 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2738 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2851 EXPECT_EQ(PAGE_TYPE_NORMAL, |
2739 controller.GetLastCommittedEntry()->GetPageType()); | 2852 controller.GetLastCommittedEntry()->GetPageType()); |
2740 } | 2853 } |
2741 | 2854 |
2742 TEST_F(NavigationControllerTest, RemoveEntry) { | 2855 TEST_F(NavigationControllerTest, RemoveEntry) { |
2743 NavigationControllerImpl& controller = controller_impl(); | 2856 NavigationControllerImpl& controller = controller_impl(); |
2744 const GURL url1("http://foo/1"); | 2857 const GURL url1("http://foo/1"); |
2745 const GURL url2("http://foo/2"); | 2858 const GURL url2("http://foo/2"); |
2746 const GURL url3("http://foo/3"); | 2859 const GURL url3("http://foo/3"); |
2747 const GURL url4("http://foo/4"); | 2860 const GURL url4("http://foo/4"); |
2748 const GURL url5("http://foo/5"); | 2861 const GURL url5("http://foo/5"); |
2749 const GURL pending_url("http://foo/pending"); | 2862 const GURL pending_url("http://foo/pending"); |
2750 const GURL default_url("http://foo/default"); | 2863 const GURL default_url("http://foo/default"); |
2751 | 2864 |
2752 controller.LoadURL( | 2865 controller.LoadURL( |
2753 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2866 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2867 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2754 main_test_rfh()->PrepareForCommit(); | 2868 main_test_rfh()->PrepareForCommit(); |
2755 main_test_rfh()->SendNavigate(0, url1); | 2869 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
2756 controller.LoadURL( | 2870 controller.LoadURL( |
2757 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2871 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2872 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2758 main_test_rfh()->PrepareForCommit(); | 2873 main_test_rfh()->PrepareForCommit(); |
2759 main_test_rfh()->SendNavigate(1, url2); | 2874 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
2760 controller.LoadURL( | 2875 controller.LoadURL( |
2761 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2876 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2877 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2762 main_test_rfh()->PrepareForCommit(); | 2878 main_test_rfh()->PrepareForCommit(); |
2763 main_test_rfh()->SendNavigate(2, url3); | 2879 main_test_rfh()->SendNavigate(2, entry_id, true, url3); |
2764 controller.LoadURL( | 2880 controller.LoadURL( |
2765 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2881 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2882 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2766 main_test_rfh()->PrepareForCommit(); | 2883 main_test_rfh()->PrepareForCommit(); |
2767 main_test_rfh()->SendNavigate(3, url4); | 2884 main_test_rfh()->SendNavigate(3, entry_id, true, url4); |
2768 controller.LoadURL( | 2885 controller.LoadURL( |
2769 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2886 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2887 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2770 main_test_rfh()->PrepareForCommit(); | 2888 main_test_rfh()->PrepareForCommit(); |
2771 main_test_rfh()->SendNavigate(4, url5); | 2889 main_test_rfh()->SendNavigate(4, entry_id, true, url5); |
2772 | 2890 |
2773 // Try to remove the last entry. Will fail because it is the current entry. | 2891 // Try to remove the last entry. Will fail because it is the current entry. |
2774 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2892 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2775 EXPECT_EQ(5, controller.GetEntryCount()); | 2893 EXPECT_EQ(5, controller.GetEntryCount()); |
2776 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2894 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
2777 | 2895 |
2778 // Go back, but don't commit yet. Check that we can't delete the current | 2896 // Go back, but don't commit yet. Check that we can't delete the current |
2779 // and pending entries. | 2897 // and pending entries. |
2780 controller.GoBack(); | 2898 controller.GoBack(); |
| 2899 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2781 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2900 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2782 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2901 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
2783 | 2902 |
2784 // Now commit and delete the last entry. | 2903 // Now commit and delete the last entry. |
2785 main_test_rfh()->PrepareForCommit(); | 2904 main_test_rfh()->PrepareForCommit(); |
2786 main_test_rfh()->SendNavigate(3, url4); | 2905 main_test_rfh()->SendNavigate(3, entry_id, false, url4); |
2787 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2906 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2788 EXPECT_EQ(4, controller.GetEntryCount()); | 2907 EXPECT_EQ(4, controller.GetEntryCount()); |
2789 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2908 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
2790 EXPECT_FALSE(controller.GetPendingEntry()); | 2909 EXPECT_FALSE(controller.GetPendingEntry()); |
2791 | 2910 |
2792 // Remove an entry which is not the last committed one. | 2911 // Remove an entry which is not the last committed one. |
2793 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2912 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2794 EXPECT_EQ(3, controller.GetEntryCount()); | 2913 EXPECT_EQ(3, controller.GetEntryCount()); |
2795 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2914 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
2796 EXPECT_FALSE(controller.GetPendingEntry()); | 2915 EXPECT_FALSE(controller.GetPendingEntry()); |
2797 | 2916 |
2798 // Remove the 2 remaining entries. | 2917 // Remove the 2 remaining entries. |
2799 controller.RemoveEntryAtIndex(1); | 2918 controller.RemoveEntryAtIndex(1); |
2800 controller.RemoveEntryAtIndex(0); | 2919 controller.RemoveEntryAtIndex(0); |
2801 | 2920 |
2802 // This should leave us with only the last committed entry. | 2921 // This should leave us with only the last committed entry. |
2803 EXPECT_EQ(1, controller.GetEntryCount()); | 2922 EXPECT_EQ(1, controller.GetEntryCount()); |
2804 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2923 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
2805 } | 2924 } |
2806 | 2925 |
2807 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { | 2926 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { |
2808 NavigationControllerImpl& controller = controller_impl(); | 2927 NavigationControllerImpl& controller = controller_impl(); |
2809 const GURL url1("http://foo/1"); | 2928 const GURL url1("http://foo/1"); |
2810 const GURL url2("http://foo/2"); | 2929 const GURL url2("http://foo/2"); |
2811 const GURL url3("http://foo/3"); | 2930 const GURL url3("http://foo/3"); |
2812 const GURL default_url("http://foo/default"); | 2931 const GURL default_url("http://foo/default"); |
2813 | 2932 |
2814 controller.LoadURL( | 2933 controller.LoadURL( |
2815 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2934 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2935 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2816 main_test_rfh()->PrepareForCommit(); | 2936 main_test_rfh()->PrepareForCommit(); |
2817 main_test_rfh()->SendNavigate(0, url1); | 2937 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
2818 controller.LoadURL( | 2938 controller.LoadURL( |
2819 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2939 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2940 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2820 main_test_rfh()->PrepareForCommit(); | 2941 main_test_rfh()->PrepareForCommit(); |
2821 main_test_rfh()->SendNavigate(1, url2); | 2942 main_test_rfh()->SendNavigate(1, entry_id, true, url2); |
2822 controller.LoadURL( | 2943 controller.LoadURL( |
2823 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2944 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2945 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2824 main_test_rfh()->PrepareForCommit(); | 2946 main_test_rfh()->PrepareForCommit(); |
2825 main_test_rfh()->SendNavigate(2, url3); | 2947 main_test_rfh()->SendNavigate(2, entry_id, true, url3); |
2826 | 2948 |
2827 // Go back, but don't commit yet. Check that we can't delete the current | 2949 // Go back, but don't commit yet. Check that we can't delete the current |
2828 // and pending entries. | 2950 // and pending entries. |
2829 controller.GoBack(); | 2951 controller.GoBack(); |
| 2952 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2830 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); | 2953 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); |
2831 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); | 2954 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); |
2832 | 2955 |
2833 // Remove the first entry, while there is a pending entry. This is expected | 2956 // Remove the first entry, while there is a pending entry. This is expected |
2834 // to discard the pending entry. | 2957 // to discard the pending entry. |
2835 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2958 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2836 EXPECT_FALSE(controller.GetPendingEntry()); | 2959 EXPECT_FALSE(controller.GetPendingEntry()); |
2837 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2960 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2838 | 2961 |
2839 // We should update the last committed entry index. | 2962 // We should update the last committed entry index. |
2840 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2963 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
2841 | 2964 |
2842 // Now commit and ensure we land on the right entry. | 2965 // Now commit and ensure we land on the right entry. |
2843 main_test_rfh()->PrepareForCommit(); | 2966 main_test_rfh()->PrepareForCommit(); |
2844 main_test_rfh()->SendNavigate(1, url2); | 2967 main_test_rfh()->SendNavigate(1, entry_id, false, url2); |
2845 EXPECT_EQ(2, controller.GetEntryCount()); | 2968 EXPECT_EQ(2, controller.GetEntryCount()); |
2846 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2969 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
2847 EXPECT_FALSE(controller.GetPendingEntry()); | 2970 EXPECT_FALSE(controller.GetPendingEntry()); |
2848 } | 2971 } |
2849 | 2972 |
2850 // Tests the transient entry, making sure it goes away with all navigations. | 2973 // Tests the transient entry, making sure it goes away with all navigations. |
2851 TEST_F(NavigationControllerTest, TransientEntry) { | 2974 TEST_F(NavigationControllerTest, TransientEntry) { |
2852 NavigationControllerImpl& controller = controller_impl(); | 2975 NavigationControllerImpl& controller = controller_impl(); |
2853 TestNotificationTracker notifications; | 2976 TestNotificationTracker notifications; |
2854 RegisterForAllNavNotifications(¬ifications, &controller); | 2977 RegisterForAllNavNotifications(¬ifications, &controller); |
2855 | 2978 |
2856 const GURL url0("http://foo/0"); | 2979 const GURL url0("http://foo/0"); |
2857 const GURL url1("http://foo/1"); | 2980 const GURL url1("http://foo/1"); |
2858 const GURL url2("http://foo/2"); | 2981 const GURL url2("http://foo/2"); |
2859 const GURL url3("http://foo/3"); | 2982 const GURL url3("http://foo/3"); |
2860 const GURL url3_ref("http://foo/3#bar"); | 2983 const GURL url3_ref("http://foo/3#bar"); |
2861 const GURL url4("http://foo/4"); | 2984 const GURL url4("http://foo/4"); |
2862 const GURL transient_url("http://foo/transient"); | 2985 const GURL transient_url("http://foo/transient"); |
2863 | 2986 |
2864 controller.LoadURL( | 2987 controller.LoadURL( |
2865 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2988 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2989 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2866 main_test_rfh()->PrepareForCommit(); | 2990 main_test_rfh()->PrepareForCommit(); |
2867 main_test_rfh()->SendNavigate(0, url0); | 2991 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
2868 controller.LoadURL( | 2992 controller.LoadURL( |
2869 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2993 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 2994 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2870 main_test_rfh()->PrepareForCommit(); | 2995 main_test_rfh()->PrepareForCommit(); |
2871 main_test_rfh()->SendNavigate(1, url1); | 2996 main_test_rfh()->SendNavigate(1, entry_id, true, url1); |
2872 | 2997 |
2873 notifications.Reset(); | 2998 notifications.Reset(); |
2874 | 2999 |
2875 // Adding a transient with no pending entry. | 3000 // Adding a transient with no pending entry. |
2876 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 3001 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2877 transient_entry->SetURL(transient_url); | 3002 transient_entry->SetURL(transient_url); |
2878 controller.SetTransientEntry(transient_entry); | 3003 controller.SetTransientEntry(transient_entry); |
2879 | 3004 |
2880 // We should not have received any notifications. | 3005 // We should not have received any notifications. |
2881 EXPECT_EQ(0U, notifications.size()); | 3006 EXPECT_EQ(0U, notifications.size()); |
2882 | 3007 |
2883 // Check our state. | 3008 // Check our state. |
2884 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3009 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2885 EXPECT_EQ(controller.GetEntryCount(), 3); | 3010 EXPECT_EQ(controller.GetEntryCount(), 3); |
2886 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 3011 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2887 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 3012 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2888 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 3013 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2889 EXPECT_FALSE(controller.GetPendingEntry()); | 3014 EXPECT_FALSE(controller.GetPendingEntry()); |
2890 EXPECT_TRUE(controller.CanGoBack()); | 3015 EXPECT_TRUE(controller.CanGoBack()); |
2891 EXPECT_FALSE(controller.CanGoForward()); | 3016 EXPECT_FALSE(controller.CanGoForward()); |
2892 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 3017 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
2893 | 3018 |
2894 // Navigate. | 3019 // Navigate. |
2895 controller.LoadURL( | 3020 controller.LoadURL( |
2896 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3021 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3022 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2897 main_test_rfh()->PrepareForCommit(); | 3023 main_test_rfh()->PrepareForCommit(); |
2898 main_test_rfh()->SendNavigate(2, url2); | 3024 main_test_rfh()->SendNavigate(2, entry_id, true, url2); |
2899 | 3025 |
2900 // We should have navigated, transient entry should be gone. | 3026 // We should have navigated, transient entry should be gone. |
2901 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 3027 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2902 EXPECT_EQ(controller.GetEntryCount(), 3); | 3028 EXPECT_EQ(controller.GetEntryCount(), 3); |
2903 | 3029 |
2904 // Add a transient again, then navigate with no pending entry this time. | 3030 // Add a transient again, then navigate with no pending entry this time. |
2905 transient_entry = new NavigationEntryImpl; | 3031 transient_entry = new NavigationEntryImpl; |
2906 transient_entry->SetURL(transient_url); | 3032 transient_entry->SetURL(transient_url); |
2907 controller.SetTransientEntry(transient_entry); | 3033 controller.SetTransientEntry(transient_entry); |
2908 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3034 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2909 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); | 3035 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); |
2910 main_test_rfh()->PrepareForCommit(); | 3036 main_test_rfh()->PrepareForCommit(); |
2911 main_test_rfh()->SendNavigate(3, url3); | 3037 main_test_rfh()->SendNavigate(3, 0, true, url3); |
2912 // Transient entry should be gone. | 3038 // Transient entry should be gone. |
2913 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 3039 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2914 EXPECT_EQ(controller.GetEntryCount(), 4); | 3040 EXPECT_EQ(controller.GetEntryCount(), 4); |
2915 | 3041 |
2916 // Initiate a navigation, add a transient then commit navigation. | 3042 // Initiate a navigation, add a transient then commit navigation. |
2917 controller.LoadURL( | 3043 controller.LoadURL( |
2918 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3044 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3045 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2919 transient_entry = new NavigationEntryImpl; | 3046 transient_entry = new NavigationEntryImpl; |
2920 transient_entry->SetURL(transient_url); | 3047 transient_entry->SetURL(transient_url); |
2921 controller.SetTransientEntry(transient_entry); | 3048 controller.SetTransientEntry(transient_entry); |
2922 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3049 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2923 main_test_rfh()->PrepareForCommit(); | 3050 main_test_rfh()->PrepareForCommit(); |
2924 main_test_rfh()->SendNavigate(4, url4); | 3051 main_test_rfh()->SendNavigate(4, entry_id, true, url4); |
2925 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 3052 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
2926 EXPECT_EQ(controller.GetEntryCount(), 5); | 3053 EXPECT_EQ(controller.GetEntryCount(), 5); |
2927 | 3054 |
2928 // Add a transient and go back. This should simply remove the transient. | 3055 // Add a transient and go back. This should simply remove the transient. |
2929 transient_entry = new NavigationEntryImpl; | 3056 transient_entry = new NavigationEntryImpl; |
2930 transient_entry->SetURL(transient_url); | 3057 transient_entry->SetURL(transient_url); |
2931 controller.SetTransientEntry(transient_entry); | 3058 controller.SetTransientEntry(transient_entry); |
2932 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3059 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2933 EXPECT_TRUE(controller.CanGoBack()); | 3060 EXPECT_TRUE(controller.CanGoBack()); |
2934 EXPECT_FALSE(controller.CanGoForward()); | 3061 EXPECT_FALSE(controller.CanGoForward()); |
2935 controller.GoBack(); | 3062 controller.GoBack(); |
2936 // Transient entry should be gone. | 3063 // Transient entry should be gone. |
2937 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 3064 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
2938 EXPECT_EQ(controller.GetEntryCount(), 5); | 3065 EXPECT_EQ(controller.GetEntryCount(), 5); |
2939 | 3066 |
2940 // Suppose the page requested a history navigation backward. | 3067 // Suppose the page requested a history navigation backward. |
2941 controller.GoToOffset(-1); | 3068 controller.GoToOffset(-1); |
| 3069 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2942 main_test_rfh()->PrepareForCommit(); | 3070 main_test_rfh()->PrepareForCommit(); |
2943 main_test_rfh()->SendNavigate(3, url3); | 3071 main_test_rfh()->SendNavigate(3, entry_id, false, url3); |
2944 | 3072 |
2945 // Add a transient and go to an entry before the current one. | 3073 // Add a transient and go to an entry before the current one. |
2946 transient_entry = new NavigationEntryImpl; | 3074 transient_entry = new NavigationEntryImpl; |
2947 transient_entry->SetURL(transient_url); | 3075 transient_entry->SetURL(transient_url); |
2948 controller.SetTransientEntry(transient_entry); | 3076 controller.SetTransientEntry(transient_entry); |
2949 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3077 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2950 controller.GoToIndex(1); | 3078 controller.GoToIndex(1); |
| 3079 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2951 // The navigation should have been initiated, transient entry should be gone. | 3080 // The navigation should have been initiated, transient entry should be gone. |
2952 EXPECT_FALSE(controller.GetTransientEntry()); | 3081 EXPECT_FALSE(controller.GetTransientEntry()); |
2953 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3082 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2954 // Visible entry does not update for history navigations until commit. | 3083 // Visible entry does not update for history navigations until commit. |
2955 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 3084 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2956 main_test_rfh()->PrepareForCommit(); | 3085 main_test_rfh()->PrepareForCommit(); |
2957 main_test_rfh()->SendNavigate(1, url1); | 3086 main_test_rfh()->SendNavigate(1, entry_id, false, url1); |
2958 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3087 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2959 | 3088 |
2960 // Add a transient and go to an entry after the current one. | 3089 // Add a transient and go to an entry after the current one. |
2961 transient_entry = new NavigationEntryImpl; | 3090 transient_entry = new NavigationEntryImpl; |
2962 transient_entry->SetURL(transient_url); | 3091 transient_entry->SetURL(transient_url); |
2963 controller.SetTransientEntry(transient_entry); | 3092 controller.SetTransientEntry(transient_entry); |
2964 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3093 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2965 controller.GoToIndex(3); | 3094 controller.GoToIndex(3); |
| 3095 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2966 // The navigation should have been initiated, transient entry should be gone. | 3096 // The navigation should have been initiated, transient entry should be gone. |
2967 // Because of the transient entry that is removed, going to index 3 makes us | 3097 // Because of the transient entry that is removed, going to index 3 makes us |
2968 // land on url2 (which is visible after the commit). | 3098 // land on url2 (which is visible after the commit). |
2969 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3099 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
2970 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3100 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2971 main_test_rfh()->PrepareForCommit(); | 3101 main_test_rfh()->PrepareForCommit(); |
2972 main_test_rfh()->SendNavigate(2, url2); | 3102 main_test_rfh()->SendNavigate(2, entry_id, false, url2); |
2973 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 3103 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2974 | 3104 |
2975 // Add a transient and go forward. | 3105 // Add a transient and go forward. |
2976 transient_entry = new NavigationEntryImpl; | 3106 transient_entry = new NavigationEntryImpl; |
2977 transient_entry->SetURL(transient_url); | 3107 transient_entry->SetURL(transient_url); |
2978 controller.SetTransientEntry(transient_entry); | 3108 controller.SetTransientEntry(transient_entry); |
2979 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3109 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2980 EXPECT_TRUE(controller.CanGoForward()); | 3110 EXPECT_TRUE(controller.CanGoForward()); |
2981 controller.GoForward(); | 3111 controller.GoForward(); |
| 3112 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
2982 // We should have navigated, transient entry should be gone. | 3113 // We should have navigated, transient entry should be gone. |
2983 EXPECT_FALSE(controller.GetTransientEntry()); | 3114 EXPECT_FALSE(controller.GetTransientEntry()); |
2984 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 3115 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
2985 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 3116 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2986 main_test_rfh()->PrepareForCommit(); | 3117 main_test_rfh()->PrepareForCommit(); |
2987 main_test_rfh()->SendNavigate(3, url3); | 3118 main_test_rfh()->SendNavigate(3, entry_id, false, url3); |
2988 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 3119 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2989 | 3120 |
2990 // Add a transient and do an in-page navigation, replacing the current entry. | 3121 // Add a transient and do an in-page navigation, replacing the current entry. |
2991 transient_entry = new NavigationEntryImpl; | 3122 transient_entry = new NavigationEntryImpl; |
2992 transient_entry->SetURL(transient_url); | 3123 transient_entry->SetURL(transient_url); |
2993 controller.SetTransientEntry(transient_entry); | 3124 controller.SetTransientEntry(transient_entry); |
2994 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3125 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2995 | 3126 |
2996 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); | 3127 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); |
2997 main_test_rfh()->PrepareForCommit(); | 3128 main_test_rfh()->PrepareForCommit(); |
2998 main_test_rfh()->SendNavigate(3, url3_ref); | 3129 main_test_rfh()->SendNavigate(3, 0, false, url3_ref); |
2999 // Transient entry should be gone. | 3130 // Transient entry should be gone. |
3000 EXPECT_FALSE(controller.GetTransientEntry()); | 3131 EXPECT_FALSE(controller.GetTransientEntry()); |
3001 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 3132 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
3002 | 3133 |
3003 // Ensure the URLs are correct. | 3134 // Ensure the URLs are correct. |
3004 EXPECT_EQ(controller.GetEntryCount(), 5); | 3135 EXPECT_EQ(controller.GetEntryCount(), 5); |
3005 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3136 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
3006 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 3137 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
3007 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 3138 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
3008 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 3139 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
3009 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 3140 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
3010 } | 3141 } |
3011 | 3142 |
3012 // Test that Reload initiates a new navigation to a transient entry's URL. | 3143 // Test that Reload initiates a new navigation to a transient entry's URL. |
3013 TEST_F(NavigationControllerTest, ReloadTransient) { | 3144 TEST_F(NavigationControllerTest, ReloadTransient) { |
3014 NavigationControllerImpl& controller = controller_impl(); | 3145 NavigationControllerImpl& controller = controller_impl(); |
3015 const GURL url0("http://foo/0"); | 3146 const GURL url0("http://foo/0"); |
3016 const GURL url1("http://foo/1"); | 3147 const GURL url1("http://foo/1"); |
3017 const GURL transient_url("http://foo/transient"); | 3148 const GURL transient_url("http://foo/transient"); |
3018 | 3149 |
3019 // Load |url0|, and start a pending navigation to |url1|. | 3150 // Load |url0|, and start a pending navigation to |url1|. |
3020 controller.LoadURL( | 3151 controller.LoadURL( |
3021 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3152 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3153 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
3022 main_test_rfh()->PrepareForCommit(); | 3154 main_test_rfh()->PrepareForCommit(); |
3023 main_test_rfh()->SendNavigate(0, url0); | 3155 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
3024 controller.LoadURL( | 3156 controller.LoadURL( |
3025 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3157 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
3026 | 3158 |
3027 // A transient entry is added, interrupting the navigation. | 3159 // A transient entry is added, interrupting the navigation. |
3028 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 3160 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
3029 transient_entry->SetURL(transient_url); | 3161 transient_entry->SetURL(transient_url); |
3030 controller.SetTransientEntry(transient_entry); | 3162 controller.SetTransientEntry(transient_entry); |
3031 EXPECT_TRUE(controller.GetTransientEntry()); | 3163 EXPECT_TRUE(controller.GetTransientEntry()); |
3032 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3164 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3033 | 3165 |
3034 // The page is reloaded, which should remove the pending entry for |url1| and | 3166 // The page is reloaded, which should remove the pending entry for |url1| and |
3035 // the transient entry for |transient_url|, and start a navigation to | 3167 // the transient entry for |transient_url|, and start a navigation to |
3036 // |transient_url|. | 3168 // |transient_url|. |
3037 controller.Reload(true); | 3169 controller.Reload(true); |
| 3170 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
3038 EXPECT_FALSE(controller.GetTransientEntry()); | 3171 EXPECT_FALSE(controller.GetTransientEntry()); |
3039 EXPECT_TRUE(controller.GetPendingEntry()); | 3172 EXPECT_TRUE(controller.GetPendingEntry()); |
3040 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 3173 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3041 ASSERT_EQ(controller.GetEntryCount(), 1); | 3174 ASSERT_EQ(controller.GetEntryCount(), 1); |
3042 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3175 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
3043 | 3176 |
3044 // Load of |transient_url| completes. | 3177 // Load of |transient_url| completes. |
3045 main_test_rfh()->PrepareForCommit(); | 3178 main_test_rfh()->PrepareForCommit(); |
3046 main_test_rfh()->SendNavigate(1, transient_url); | 3179 main_test_rfh()->SendNavigate(1, entry_id, true, transient_url); |
3047 ASSERT_EQ(controller.GetEntryCount(), 2); | 3180 ASSERT_EQ(controller.GetEntryCount(), 2); |
3048 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 3181 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
3049 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 3182 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
3050 } | 3183 } |
3051 | 3184 |
3052 // Ensure that renderer initiated pending entries get replaced, so that we | 3185 // Ensure that renderer initiated pending entries get replaced, so that we |
3053 // don't show a stale virtual URL when a navigation commits. | 3186 // don't show a stale virtual URL when a navigation commits. |
3054 // See http://crbug.com/266922. | 3187 // See http://crbug.com/266922. |
3055 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 3188 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
3056 NavigationControllerImpl& controller = controller_impl(); | 3189 NavigationControllerImpl& controller = controller_impl(); |
(...skipping 18 matching lines...) Expand all Loading... |
3075 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3208 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3076 | 3209 |
3077 // If the user clicks another link, we should replace the pending entry. | 3210 // If the user clicks another link, we should replace the pending entry. |
3078 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3211 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
3079 main_test_rfh()->PrepareForCommit(); | 3212 main_test_rfh()->PrepareForCommit(); |
3080 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3213 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
3081 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3214 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
3082 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 3215 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
3083 | 3216 |
3084 // Once it commits, the URL and virtual URL should reflect the actual page. | 3217 // Once it commits, the URL and virtual URL should reflect the actual page. |
3085 main_test_rfh()->SendNavigate(0, url2); | 3218 main_test_rfh()->SendNavigate(0, 0, true, url2); |
3086 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3219 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3087 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 3220 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
3088 | 3221 |
3089 // We should not replace the pending entry for an error URL. | 3222 // We should not replace the pending entry for an error URL. |
3090 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3223 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
3091 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3224 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3092 navigator->DidStartProvisionalLoad(main_test_rfh(), | 3225 navigator->DidStartProvisionalLoad(main_test_rfh(), |
3093 GURL(kUnreachableWebDataURL), false); | 3226 GURL(kUnreachableWebDataURL), false); |
3094 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3227 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3095 | 3228 |
3096 // We should remember if the pending entry will replace the current one. | 3229 // We should remember if the pending entry will replace the current one. |
3097 // http://crbug.com/308444. | 3230 // http://crbug.com/308444. |
3098 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3231 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
3099 controller.GetPendingEntry()->set_should_replace_entry(true); | 3232 controller.GetPendingEntry()->set_should_replace_entry(true); |
3100 | 3233 |
3101 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3234 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
3102 main_test_rfh()->PrepareForCommit(); | 3235 main_test_rfh()->PrepareForCommit(); |
3103 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3236 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
3104 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); | 3237 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
3105 main_test_rfh()->SendNavigate(0, url2); | 3238 main_test_rfh()->SendNavigate(0, 0, false, url2); |
3106 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3239 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3107 } | 3240 } |
3108 | 3241 |
3109 // Tests that the URLs for renderer-initiated navigations are not displayed to | 3242 // Tests that the URLs for renderer-initiated navigations are not displayed to |
3110 // the user until the navigation commits, to prevent URL spoof attacks. | 3243 // the user until the navigation commits, to prevent URL spoof attacks. |
3111 // See http://crbug.com/99016. | 3244 // See http://crbug.com/99016. |
3112 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 3245 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
3113 NavigationControllerImpl& controller = controller_impl(); | 3246 NavigationControllerImpl& controller = controller_impl(); |
3114 TestNotificationTracker notifications; | 3247 TestNotificationTracker notifications; |
3115 RegisterForAllNavNotifications(¬ifications, &controller); | 3248 RegisterForAllNavNotifications(¬ifications, &controller); |
3116 | 3249 |
3117 const GURL url0("http://foo/0"); | 3250 const GURL url0("http://foo/0"); |
3118 const GURL url1("http://foo/1"); | 3251 const GURL url1("http://foo/1"); |
3119 | 3252 |
3120 // For typed navigations (browser-initiated), both pending and visible entries | 3253 // For typed navigations (browser-initiated), both pending and visible entries |
3121 // should update before commit. | 3254 // should update before commit. |
3122 controller.LoadURL( | 3255 controller.LoadURL( |
3123 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3256 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 3257 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
3124 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 3258 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
3125 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3259 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
3126 main_test_rfh()->PrepareForCommit(); | 3260 main_test_rfh()->PrepareForCommit(); |
3127 main_test_rfh()->SendNavigate(0, url0); | 3261 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
3128 | 3262 |
3129 // For link clicks (renderer-initiated navigations), the pending entry should | 3263 // For link clicks (renderer-initiated navigations), the pending entry should |
3130 // update before commit but the visible should not. | 3264 // update before commit but the visible should not. |
3131 NavigationController::LoadURLParams load_url_params(url1); | 3265 NavigationController::LoadURLParams load_url_params(url1); |
3132 load_url_params.is_renderer_initiated = true; | 3266 load_url_params.is_renderer_initiated = true; |
3133 controller.LoadURLWithParams(load_url_params); | 3267 controller.LoadURLWithParams(load_url_params); |
| 3268 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
3134 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3269 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
3135 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3270 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3136 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3271 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3137 | 3272 |
3138 // After commit, both visible should be updated, there should be no pending | 3273 // After commit, both visible should be updated, there should be no pending |
3139 // entry, and we should no longer treat the entry as renderer-initiated. | 3274 // entry, and we should no longer treat the entry as renderer-initiated. |
3140 main_test_rfh()->PrepareForCommit(); | 3275 main_test_rfh()->PrepareForCommit(); |
3141 main_test_rfh()->SendNavigate(1, url1); | 3276 main_test_rfh()->SendNavigate(1, entry_id, true, url1); |
3142 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3277 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3143 EXPECT_FALSE(controller.GetPendingEntry()); | 3278 EXPECT_FALSE(controller.GetPendingEntry()); |
3144 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); | 3279 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); |
3145 | 3280 |
3146 notifications.Reset(); | 3281 notifications.Reset(); |
3147 } | 3282 } |
3148 | 3283 |
3149 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3284 // Tests that the URLs for renderer-initiated navigations in new tabs are |
3150 // displayed to the user before commit, as long as the initial about:blank | 3285 // displayed to the user before commit, as long as the initial about:blank |
3151 // page has not been modified. If so, we must revert to showing about:blank. | 3286 // page has not been modified. If so, we must revert to showing about:blank. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3289 const GURL url1("http://foo/eh"); | 3424 const GURL url1("http://foo/eh"); |
3290 const GURL url2("http://foo/bee"); | 3425 const GURL url2("http://foo/bee"); |
3291 | 3426 |
3292 // For renderer-initiated navigations in new tabs (with no committed entries), | 3427 // For renderer-initiated navigations in new tabs (with no committed entries), |
3293 // we show the pending entry's URL as long as the about:blank page is not | 3428 // we show the pending entry's URL as long as the about:blank page is not |
3294 // modified. | 3429 // modified. |
3295 NavigationController::LoadURLParams load_url_params(url1); | 3430 NavigationController::LoadURLParams load_url_params(url1); |
3296 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3431 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3297 load_url_params.is_renderer_initiated = true; | 3432 load_url_params.is_renderer_initiated = true; |
3298 controller.LoadURLWithParams(load_url_params); | 3433 controller.LoadURLWithParams(load_url_params); |
| 3434 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
3299 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3435 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3300 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3436 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3301 EXPECT_TRUE(controller.IsInitialNavigation()); | 3437 EXPECT_TRUE(controller.IsInitialNavigation()); |
3302 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3438 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3303 | 3439 |
3304 // Simulate a commit and then starting a new pending navigation. | 3440 // Simulate a commit and then starting a new pending navigation. |
3305 main_test_rfh()->PrepareForCommit(); | 3441 main_test_rfh()->PrepareForCommit(); |
3306 main_test_rfh()->SendNavigate(0, url1); | 3442 main_test_rfh()->SendNavigate(0, entry_id, true, url1); |
3307 NavigationController::LoadURLParams load_url2_params(url2); | 3443 NavigationController::LoadURLParams load_url2_params(url2); |
3308 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3444 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3309 load_url2_params.is_renderer_initiated = true; | 3445 load_url2_params.is_renderer_initiated = true; |
3310 controller.LoadURLWithParams(load_url2_params); | 3446 controller.LoadURLWithParams(load_url2_params); |
3311 | 3447 |
3312 // We should not consider this an initial navigation, and thus should | 3448 // We should not consider this an initial navigation, and thus should |
3313 // not show the pending URL. | 3449 // not show the pending URL. |
3314 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3450 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3315 EXPECT_FALSE(controller.IsInitialNavigation()); | 3451 EXPECT_FALSE(controller.IsInitialNavigation()); |
3316 EXPECT_TRUE(controller.GetVisibleEntry()); | 3452 EXPECT_TRUE(controller.GetVisibleEntry()); |
3317 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3453 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3318 | 3454 |
3319 notifications.Reset(); | 3455 notifications.Reset(); |
3320 } | 3456 } |
3321 | 3457 |
3322 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3458 // Tests that IsInPageNavigation returns appropriate results. Prevents |
3323 // regression for bug 1126349. | 3459 // regression for bug 1126349. |
3324 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3460 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
3325 NavigationControllerImpl& controller = controller_impl(); | 3461 NavigationControllerImpl& controller = controller_impl(); |
3326 const GURL url("http://www.google.com/home.html"); | 3462 const GURL url("http://www.google.com/home.html"); |
3327 | 3463 |
3328 // If the renderer claims it performed an in-page navigation from | 3464 // If the renderer claims it performed an in-page navigation from |
3329 // about:blank, trust the renderer. | 3465 // about:blank, trust the renderer. |
3330 // This can happen when an iframe is created and populated via | 3466 // This can happen when an iframe is created and populated via |
3331 // document.write(), then tries to perform a fragment navigation. | 3467 // document.write(), then tries to perform a fragment navigation. |
3332 // TODO(japhet): We should only trust the renderer if the about:blank | 3468 // TODO(japhet): We should only trust the renderer if the about:blank |
3333 // was the first document in the given frame, but we don't have enough | 3469 // was the first document in the given frame, but we don't have enough |
3334 // information to identify that case currently. | 3470 // information to identify that case currently. |
3335 const GURL blank_url(url::kAboutBlankURL); | 3471 const GURL blank_url(url::kAboutBlankURL); |
3336 main_test_rfh()->NavigateAndCommitRendererInitiated(0, blank_url); | 3472 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url); |
3337 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3473 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3338 main_test_rfh())); | 3474 main_test_rfh())); |
3339 | 3475 |
3340 // Navigate to URL with no refs. | 3476 // Navigate to URL with no refs. |
3341 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 3477 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); |
3342 | 3478 |
3343 // Reloading the page is not an in-page navigation. | 3479 // Reloading the page is not an in-page navigation. |
3344 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3480 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, main_test_rfh())); |
3345 main_test_rfh())); | |
3346 const GURL other_url("http://www.google.com/add.html"); | 3481 const GURL other_url("http://www.google.com/add.html"); |
3347 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3482 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3348 main_test_rfh())); | 3483 main_test_rfh())); |
3349 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3484 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3350 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3485 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3351 main_test_rfh())); | 3486 main_test_rfh())); |
3352 | 3487 |
3353 // Navigate to URL with refs. | 3488 // Navigate to URL with refs. |
3354 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url_with_ref); | 3489 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url_with_ref); |
3355 | 3490 |
3356 // Reloading the page is not an in-page navigation. | 3491 // Reloading the page is not an in-page navigation. |
3357 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, | 3492 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
3358 main_test_rfh())); | 3493 main_test_rfh())); |
3359 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3494 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
3360 main_test_rfh())); | 3495 main_test_rfh())); |
3361 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3496 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3362 main_test_rfh())); | 3497 main_test_rfh())); |
3363 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3498 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
3364 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, | 3499 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
(...skipping 17 matching lines...) Expand all Loading... |
3382 // Test allow_universal_access_from_file_urls flag. | 3517 // Test allow_universal_access_from_file_urls flag. |
3383 const GURL different_origin_url("http://www.example.com"); | 3518 const GURL different_origin_url("http://www.example.com"); |
3384 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); | 3519 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); |
3385 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); | 3520 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); |
3386 prefs.allow_universal_access_from_file_urls = true; | 3521 prefs.allow_universal_access_from_file_urls = true; |
3387 test_rvh()->UpdateWebkitPreferences(prefs); | 3522 test_rvh()->UpdateWebkitPreferences(prefs); |
3388 prefs = test_rvh()->GetWebkitPreferences(); | 3523 prefs = test_rvh()->GetWebkitPreferences(); |
3389 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); | 3524 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); |
3390 // Allow in page navigation if existing URL is file scheme. | 3525 // Allow in page navigation if existing URL is file scheme. |
3391 const GURL file_url("file:///foo/index.html"); | 3526 const GURL file_url("file:///foo/index.html"); |
3392 main_test_rfh()->NavigateAndCommitRendererInitiated(0, file_url); | 3527 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, file_url); |
3393 EXPECT_EQ(0, rph->bad_msg_count()); | 3528 EXPECT_EQ(0, rph->bad_msg_count()); |
3394 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, | 3529 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, |
3395 main_test_rfh())); | 3530 main_test_rfh())); |
3396 EXPECT_EQ(0, rph->bad_msg_count()); | 3531 EXPECT_EQ(0, rph->bad_msg_count()); |
3397 // Don't honor allow_universal_access_from_file_urls if existing URL is | 3532 // Don't honor allow_universal_access_from_file_urls if existing URL is |
3398 // not file scheme. | 3533 // not file scheme. |
3399 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 3534 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); |
3400 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3535 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3401 main_test_rfh())); | 3536 main_test_rfh())); |
3402 EXPECT_EQ(1, rph->bad_msg_count()); | 3537 EXPECT_EQ(1, rph->bad_msg_count()); |
3403 | 3538 |
3404 // Remove allow_universal_access_from_file_urls flag. | 3539 // Remove allow_universal_access_from_file_urls flag. |
3405 prefs.allow_universal_access_from_file_urls = false; | 3540 prefs.allow_universal_access_from_file_urls = false; |
3406 test_rvh()->UpdateWebkitPreferences(prefs); | 3541 test_rvh()->UpdateWebkitPreferences(prefs); |
3407 prefs = test_rvh()->GetWebkitPreferences(); | 3542 prefs = test_rvh()->GetWebkitPreferences(); |
3408 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); | 3543 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); |
3409 | 3544 |
3410 // Don't believe the renderer if it claims a cross-origin navigation is | 3545 // Don't believe the renderer if it claims a cross-origin navigation is |
3411 // in-page. | 3546 // in-page. |
3412 EXPECT_EQ(1, rph->bad_msg_count()); | 3547 EXPECT_EQ(1, rph->bad_msg_count()); |
3413 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3548 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3414 main_test_rfh())); | 3549 main_test_rfh())); |
3415 EXPECT_EQ(2, rph->bad_msg_count()); | 3550 EXPECT_EQ(2, rph->bad_msg_count()); |
3416 } | 3551 } |
3417 | 3552 |
3418 // Some pages can have subframes with the same base URL (minus the reference) as | 3553 // Some pages can have subframes with the same base URL (minus the reference) as |
3419 // the main page. Even though this is hard, it can happen, and we don't want | 3554 // the main page. Even though this is hard, it can happen, and we don't want |
3420 // these subframe navigations to affect the toplevel document. They should | 3555 // these subframe navigations to affect the toplevel document. They should |
3421 // instead be ignored. http://crbug.com/5585 | 3556 // instead be ignored. http://crbug.com/5585 |
3422 TEST_F(NavigationControllerTest, SameSubframe) { | 3557 TEST_F(NavigationControllerTest, SameSubframe) { |
3423 NavigationControllerImpl& controller = controller_impl(); | 3558 NavigationControllerImpl& controller = controller_impl(); |
3424 // Navigate the main frame. | 3559 // Navigate the main frame. |
3425 const GURL url("http://www.google.com/"); | 3560 const GURL url("http://www.google.com/"); |
3426 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); | 3561 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); |
3427 | 3562 |
3428 // We should be at the first navigation entry. | 3563 // We should be at the first navigation entry. |
3429 EXPECT_EQ(controller.GetEntryCount(), 1); | 3564 EXPECT_EQ(controller.GetEntryCount(), 1); |
3430 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 3565 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
3431 | 3566 |
3432 // Navigate a subframe that would normally count as in-page. | 3567 // Navigate a subframe that would normally count as in-page. |
3433 const GURL subframe("http://www.google.com/#"); | 3568 const GURL subframe("http://www.google.com/#"); |
3434 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3569 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
3435 params.page_id = 0; | 3570 params.page_id = 0; |
| 3571 params.nav_entry_id = 0; |
| 3572 params.did_create_new_entry = false; |
3436 params.url = subframe; | 3573 params.url = subframe; |
3437 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3574 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
3438 params.should_update_history = false; | 3575 params.should_update_history = false; |
3439 params.gesture = NavigationGestureAuto; | 3576 params.gesture = NavigationGestureAuto; |
3440 params.is_post = false; | 3577 params.is_post = false; |
3441 params.page_state = PageState::CreateFromURL(subframe); | 3578 params.page_state = PageState::CreateFromURL(subframe); |
3442 LoadCommittedDetails details; | 3579 LoadCommittedDetails details; |
3443 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, | 3580 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
3444 &details)); | 3581 &details)); |
3445 | 3582 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3571 // Now start a pending load to a totally different page, but don't commit it. | 3708 // Now start a pending load to a totally different page, but don't commit it. |
3572 const GURL url2("http://bar/"); | 3709 const GURL url2("http://bar/"); |
3573 controller.LoadURL( | 3710 controller.LoadURL( |
3574 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3711 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
3575 | 3712 |
3576 // Send a subframe update from the first page, as if one had just | 3713 // Send a subframe update from the first page, as if one had just |
3577 // automatically loaded. Auto subframes don't increment the page ID. | 3714 // automatically loaded. Auto subframes don't increment the page ID. |
3578 const GURL url1_sub("http://foo/subframe"); | 3715 const GURL url1_sub("http://foo/subframe"); |
3579 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3716 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
3580 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); | 3717 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); |
| 3718 params.nav_entry_id = 0; |
| 3719 params.did_create_new_entry = false; |
3581 params.url = url1_sub; | 3720 params.url = url1_sub; |
3582 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3721 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
3583 params.should_update_history = false; | 3722 params.should_update_history = false; |
3584 params.gesture = NavigationGestureAuto; | 3723 params.gesture = NavigationGestureAuto; |
3585 params.is_post = false; | 3724 params.is_post = false; |
3586 params.page_state = PageState::CreateFromURL(url1_sub); | 3725 params.page_state = PageState::CreateFromURL(url1_sub); |
3587 LoadCommittedDetails details; | 3726 LoadCommittedDetails details; |
3588 | 3727 |
3589 // This should return false meaning that nothing was actually updated. | 3728 // This should return false meaning that nothing was actually updated. |
3590 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, | 3729 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3868 | 4007 |
3869 NavigateAndCommit(url1); | 4008 NavigateAndCommit(url1); |
3870 | 4009 |
3871 scoped_ptr<TestWebContents> other_contents( | 4010 scoped_ptr<TestWebContents> other_contents( |
3872 static_cast<TestWebContents*>(CreateTestWebContents())); | 4011 static_cast<TestWebContents*>(CreateTestWebContents())); |
3873 NavigationControllerImpl& other_controller = other_contents->GetController(); | 4012 NavigationControllerImpl& other_controller = other_contents->GetController(); |
3874 other_contents->NavigateAndCommit(url2a); | 4013 other_contents->NavigateAndCommit(url2a); |
3875 // Simulate a client redirect, which has the same page ID as entry 2a. | 4014 // Simulate a client redirect, which has the same page ID as entry 2a. |
3876 other_controller.LoadURL( | 4015 other_controller.LoadURL( |
3877 url2b, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 4016 url2b, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
3878 other_controller.GetPendingEntry()->SetPageID( | 4017 NavigationEntry* entry = other_controller.GetPendingEntry(); |
3879 other_controller.GetLastCommittedEntry()->GetPageID()); | 4018 entry->SetPageID(other_controller.GetLastCommittedEntry()->GetPageID()); |
3880 | 4019 |
3881 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); | 4020 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); |
3882 other_controller.CopyStateFromAndPrune(&controller, false); | 4021 other_controller.CopyStateFromAndPrune(&controller, false); |
3883 | 4022 |
3884 // other_controller should now contain url1, url2a, and a pending entry | 4023 // other_controller should now contain url1, url2a, and a pending entry |
3885 // for url2b. | 4024 // for url2b. |
3886 | 4025 |
3887 ASSERT_EQ(2, other_controller.GetEntryCount()); | 4026 ASSERT_EQ(2, other_controller.GetEntryCount()); |
3888 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); | 4027 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
3889 | 4028 |
3890 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 4029 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3891 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); | 4030 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); |
3892 | 4031 |
3893 // And there should be a pending entry for url4. | 4032 // And there should be a pending entry for url4. |
3894 ASSERT_TRUE(other_controller.GetPendingEntry()); | 4033 ASSERT_TRUE(other_controller.GetPendingEntry()); |
3895 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); | 4034 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); |
3896 | 4035 |
3897 // Let the pending entry commit. | 4036 // Let the pending entry commit. |
3898 other_contents->CommitPendingNavigation(); | 4037 other_contents->TestDidNavigate(other_contents->GetMainFrame(), |
| 4038 entry->GetPageID(), 0, false, url2b, |
| 4039 ui::PAGE_TRANSITION_LINK); |
3899 | 4040 |
3900 // The max page ID map should be copied over and updated with the max page ID | 4041 // The max page ID map should be copied over and updated with the max page ID |
3901 // from the current tab. | 4042 // from the current tab. |
3902 SiteInstance* instance1 = | 4043 SiteInstance* instance1 = |
3903 other_controller.GetEntryAtIndex(1)->site_instance(); | 4044 other_controller.GetEntryAtIndex(1)->site_instance(); |
3904 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 4045 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3905 } | 4046 } |
3906 | 4047 |
3907 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the | 4048 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the |
3908 // source, and 1 entry in the target. The back pending entry should be ignored. | 4049 // source, and 1 entry in the target. The back pending entry should be ignored. |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4249 const GURL url1("http://foo/1"); | 4390 const GURL url1("http://foo/1"); |
4250 const GURL url2("http://foo/2"); | 4391 const GURL url2("http://foo/2"); |
4251 const GURL url3("http://foo/3"); | 4392 const GURL url3("http://foo/3"); |
4252 | 4393 |
4253 NavigateAndCommit(url1); | 4394 NavigateAndCommit(url1); |
4254 NavigateAndCommit(url2); | 4395 NavigateAndCommit(url2); |
4255 | 4396 |
4256 // Create a pending entry that is not in the entry list. | 4397 // Create a pending entry that is not in the entry list. |
4257 controller.LoadURL( | 4398 controller.LoadURL( |
4258 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4399 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 4400 int entry_id = controller.GetPendingEntry()->GetUniqueID(); |
4259 EXPECT_TRUE(controller.GetPendingEntry()); | 4401 EXPECT_TRUE(controller.GetPendingEntry()); |
4260 EXPECT_EQ(2, controller.GetEntryCount()); | 4402 EXPECT_EQ(2, controller.GetEntryCount()); |
4261 | 4403 |
4262 contents()->ExpectSetHistoryOffsetAndLength(0, 1); | 4404 contents()->ExpectSetHistoryOffsetAndLength(0, 1); |
4263 controller.PruneAllButLastCommitted(); | 4405 controller.PruneAllButLastCommitted(); |
4264 | 4406 |
4265 // We should only have the last committed and pending entries at this point, | 4407 // We should only have the last committed and pending entries at this point, |
4266 // and the pending entry should still not be in the entry list. | 4408 // and the pending entry should still not be in the entry list. |
4267 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4409 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4268 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 4410 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
4269 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4411 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4270 EXPECT_TRUE(controller.GetPendingEntry()); | 4412 EXPECT_TRUE(controller.GetPendingEntry()); |
4271 EXPECT_EQ(1, controller.GetEntryCount()); | 4413 EXPECT_EQ(1, controller.GetEntryCount()); |
4272 | 4414 |
4273 // Try to commit the pending entry. | 4415 // Try to commit the pending entry. |
4274 main_test_rfh()->PrepareForCommit(); | 4416 main_test_rfh()->PrepareForCommit(); |
4275 main_test_rfh()->SendNavigate(2, url3); | 4417 main_test_rfh()->SendNavigate(2, entry_id, true, url3); |
4276 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4418 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4277 EXPECT_FALSE(controller.GetPendingEntry()); | 4419 EXPECT_FALSE(controller.GetPendingEntry()); |
4278 EXPECT_EQ(2, controller.GetEntryCount()); | 4420 EXPECT_EQ(2, controller.GetEntryCount()); |
4279 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 4421 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
4280 } | 4422 } |
4281 | 4423 |
4282 // Test to ensure that when we do a history navigation back to the current | 4424 // Test to ensure that when we do a history navigation back to the current |
4283 // committed page (e.g., going forward to a slow-loading page, then pressing | 4425 // committed page (e.g., going forward to a slow-loading page, then pressing |
4284 // the back button), we just stop the navigation to prevent the throbber from | 4426 // the back button), we just stop the navigation to prevent the throbber from |
4285 // running continuously. Otherwise, the RenderViewHost forces the throbber to | 4427 // running continuously. Otherwise, the RenderViewHost forces the throbber to |
(...skipping 21 matching lines...) Expand all Loading... |
4307 TEST_F(NavigationControllerTest, IsInitialNavigation) { | 4449 TEST_F(NavigationControllerTest, IsInitialNavigation) { |
4308 NavigationControllerImpl& controller = controller_impl(); | 4450 NavigationControllerImpl& controller = controller_impl(); |
4309 TestNotificationTracker notifications; | 4451 TestNotificationTracker notifications; |
4310 RegisterForAllNavNotifications(¬ifications, &controller); | 4452 RegisterForAllNavNotifications(¬ifications, &controller); |
4311 | 4453 |
4312 // Initial state. | 4454 // Initial state. |
4313 EXPECT_TRUE(controller.IsInitialNavigation()); | 4455 EXPECT_TRUE(controller.IsInitialNavigation()); |
4314 | 4456 |
4315 // After commit, it stays false. | 4457 // After commit, it stays false. |
4316 const GURL url1("http://foo1"); | 4458 const GURL url1("http://foo1"); |
4317 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); | 4459 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); |
4318 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4460 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4319 navigation_entry_committed_counter_ = 0; | 4461 navigation_entry_committed_counter_ = 0; |
4320 EXPECT_FALSE(controller.IsInitialNavigation()); | 4462 EXPECT_FALSE(controller.IsInitialNavigation()); |
4321 | 4463 |
4322 // After starting a new navigation, it stays false. | 4464 // After starting a new navigation, it stays false. |
4323 const GURL url2("http://foo2"); | 4465 const GURL url2("http://foo2"); |
4324 controller.LoadURL( | 4466 controller.LoadURL( |
4325 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4467 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
4326 } | 4468 } |
4327 | 4469 |
4328 // Check that the favicon is not reused across a client redirect. | 4470 // Check that the favicon is not reused across a client redirect. |
4329 // (crbug.com/28515) | 4471 // (crbug.com/28515) |
4330 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 4472 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
4331 const GURL kPageWithFavicon("http://withfavicon.html"); | 4473 const GURL kPageWithFavicon("http://withfavicon.html"); |
4332 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 4474 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
4333 const GURL kIconURL("http://withfavicon.ico"); | 4475 const GURL kIconURL("http://withfavicon.ico"); |
4334 const gfx::Image kDefaultFavicon = FaviconStatus().image; | 4476 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
4335 | 4477 |
4336 NavigationControllerImpl& controller = controller_impl(); | 4478 NavigationControllerImpl& controller = controller_impl(); |
4337 TestNotificationTracker notifications; | 4479 TestNotificationTracker notifications; |
4338 RegisterForAllNavNotifications(¬ifications, &controller); | 4480 RegisterForAllNavNotifications(¬ifications, &controller); |
4339 | 4481 |
4340 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kPageWithFavicon); | 4482 main_test_rfh()->NavigateAndCommitRendererInitiated( |
| 4483 0, true, kPageWithFavicon); |
4341 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4484 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4342 navigation_entry_committed_counter_ = 0; | 4485 navigation_entry_committed_counter_ = 0; |
4343 | 4486 |
4344 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4487 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
4345 EXPECT_TRUE(entry); | 4488 EXPECT_TRUE(entry); |
4346 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 4489 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
4347 | 4490 |
4348 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 4491 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
4349 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4492 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
4350 favicon_status.image = CreateImage(SK_ColorWHITE); | 4493 favicon_status.image = CreateImage(SK_ColorWHITE); |
4351 favicon_status.url = kIconURL; | 4494 favicon_status.url = kIconURL; |
4352 favicon_status.valid = true; | 4495 favicon_status.valid = true; |
4353 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4496 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
4354 | 4497 |
4355 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, | 4498 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, |
4356 false); | 4499 false); |
4357 main_test_rfh()->PrepareForCommit(); | 4500 main_test_rfh()->PrepareForCommit(); |
4358 main_test_rfh()->SendNavigateWithTransition( | 4501 main_test_rfh()->SendNavigateWithTransition( |
4359 0, // same page ID. | 4502 0, // same page ID. |
4360 kPageWithoutFavicon, | 4503 0, // nav_entry_id |
4361 ui::PAGE_TRANSITION_CLIENT_REDIRECT); | 4504 false, // no new entry |
| 4505 kPageWithoutFavicon, ui::PAGE_TRANSITION_CLIENT_REDIRECT); |
4362 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4506 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4363 navigation_entry_committed_counter_ = 0; | 4507 navigation_entry_committed_counter_ = 0; |
4364 | 4508 |
4365 entry = controller.GetLastCommittedEntry(); | 4509 entry = controller.GetLastCommittedEntry(); |
4366 EXPECT_TRUE(entry); | 4510 EXPECT_TRUE(entry); |
4367 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 4511 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
4368 | 4512 |
4369 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4513 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
4370 } | 4514 } |
4371 | 4515 |
4372 // Check that the favicon is not cleared for NavigationEntries which were | 4516 // Check that the favicon is not cleared for NavigationEntries which were |
4373 // previously navigated to. | 4517 // previously navigated to. |
4374 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { | 4518 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
4375 const GURL kUrl1("http://www.a.com/1"); | 4519 const GURL kUrl1("http://www.a.com/1"); |
4376 const GURL kUrl2("http://www.a.com/2"); | 4520 const GURL kUrl2("http://www.a.com/2"); |
4377 const GURL kIconURL("http://www.a.com/1/favicon.ico"); | 4521 const GURL kIconURL("http://www.a.com/1/favicon.ico"); |
4378 | 4522 |
4379 NavigationControllerImpl& controller = controller_impl(); | 4523 NavigationControllerImpl& controller = controller_impl(); |
4380 TestNotificationTracker notifications; | 4524 TestNotificationTracker notifications; |
4381 RegisterForAllNavNotifications(¬ifications, &controller); | 4525 RegisterForAllNavNotifications(¬ifications, &controller); |
4382 | 4526 |
4383 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1); | 4527 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, kUrl1); |
4384 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4528 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4385 navigation_entry_committed_counter_ = 0; | 4529 navigation_entry_committed_counter_ = 0; |
4386 | 4530 |
4387 // Simulate Chromium having set the favicon for |kUrl1|. | 4531 // Simulate Chromium having set the favicon for |kUrl1|. |
4388 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); | 4532 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); |
4389 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4533 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
4390 EXPECT_TRUE(entry); | 4534 EXPECT_TRUE(entry); |
4391 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4535 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
4392 favicon_status.image = favicon_image; | 4536 favicon_status.image = favicon_image; |
4393 favicon_status.url = kIconURL; | 4537 favicon_status.url = kIconURL; |
4394 favicon_status.valid = true; | 4538 favicon_status.valid = true; |
4395 | 4539 |
4396 // Navigate to another page and go back to the original page. | 4540 // Navigate to another page and go back to the original page. |
4397 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2); | 4541 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, kUrl2); |
4398 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4542 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4399 navigation_entry_committed_counter_ = 0; | 4543 navigation_entry_committed_counter_ = 0; |
4400 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); | 4544 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); |
4401 main_test_rfh()->PrepareForCommit(); | 4545 main_test_rfh()->PrepareForCommit(); |
4402 main_test_rfh()->SendNavigateWithTransition( | 4546 main_test_rfh()->SendNavigateWithTransition( |
4403 0, | 4547 0, controller.GetEntryAtIndex(0)->GetUniqueID(), false, kUrl1, |
4404 kUrl1, | |
4405 ui::PAGE_TRANSITION_FORWARD_BACK); | 4548 ui::PAGE_TRANSITION_FORWARD_BACK); |
4406 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4549 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4407 navigation_entry_committed_counter_ = 0; | 4550 navigation_entry_committed_counter_ = 0; |
4408 | 4551 |
4409 // Verify that the favicon for the page at |kUrl1| was not cleared. | 4552 // Verify that the favicon for the page at |kUrl1| was not cleared. |
4410 entry = controller.GetEntryAtIndex(0); | 4553 entry = controller.GetEntryAtIndex(0); |
4411 EXPECT_TRUE(entry); | 4554 EXPECT_TRUE(entry); |
4412 EXPECT_EQ(kUrl1, entry->GetURL()); | 4555 EXPECT_EQ(kUrl1, entry->GetURL()); |
4413 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); | 4556 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); |
4414 } | 4557 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4495 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); | 4638 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); |
4496 for (int i = 0; i < controller.GetEntryCount(); ++i) { | 4639 for (int i = 0; i < controller.GetEntryCount(); ++i) { |
4497 entry = controller.GetEntryAtIndex(i); | 4640 entry = controller.GetEntryAtIndex(i); |
4498 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4641 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4499 << " not cleared"; | 4642 << " not cleared"; |
4500 } | 4643 } |
4501 } | 4644 } |
4502 | 4645 |
4503 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { | 4646 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { |
4504 // Navigate. | 4647 // Navigate. |
4505 main_test_rfh()->NavigateAndCommitRendererInitiated(1, GURL("http://foo")); | 4648 main_test_rfh()->NavigateAndCommitRendererInitiated( |
| 4649 1, true, GURL("http://foo")); |
4506 | 4650 |
4507 // Set title and favicon. | 4651 // Set title and favicon. |
4508 base::string16 title(base::ASCIIToUTF16("Title")); | 4652 base::string16 title(base::ASCIIToUTF16("Title")); |
4509 FaviconStatus favicon; | 4653 FaviconStatus favicon; |
4510 favicon.valid = true; | 4654 favicon.valid = true; |
4511 favicon.url = GURL("http://foo/favicon.ico"); | 4655 favicon.url = GURL("http://foo/favicon.ico"); |
4512 controller().GetLastCommittedEntry()->SetTitle(title); | 4656 controller().GetLastCommittedEntry()->SetTitle(title); |
4513 controller().GetLastCommittedEntry()->GetFavicon() = favicon; | 4657 controller().GetLastCommittedEntry()->GetFavicon() = favicon; |
4514 | 4658 |
4515 // history.pushState() is called. | 4659 // history.pushState() is called. |
4516 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4660 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4517 GURL kUrl2("http://foo#foo"); | 4661 GURL kUrl2("http://foo#foo"); |
4518 params.page_id = 2; | 4662 params.page_id = 2; |
| 4663 params.nav_entry_id = 0; |
| 4664 params.did_create_new_entry = true; |
4519 params.url = kUrl2; | 4665 params.url = kUrl2; |
4520 params.page_state = PageState::CreateFromURL(kUrl2); | 4666 params.page_state = PageState::CreateFromURL(kUrl2); |
4521 params.was_within_same_page = true; | 4667 params.was_within_same_page = true; |
4522 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); | 4668 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); |
4523 main_test_rfh()->PrepareForCommit(); | 4669 main_test_rfh()->PrepareForCommit(); |
4524 main_test_rfh()->SendNavigateWithParams(¶ms); | 4670 main_test_rfh()->SendNavigateWithParams(¶ms); |
4525 | 4671 |
4526 // The title should immediately be visible on the new NavigationEntry. | 4672 // The title should immediately be visible on the new NavigationEntry. |
4527 base::string16 new_title = | 4673 base::string16 new_title = |
4528 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); | 4674 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4587 | 4733 |
4588 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { | 4734 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { |
4589 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 4735 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
4590 EXPECT_FALSE(contents()->GetDelegate()); | 4736 EXPECT_FALSE(contents()->GetDelegate()); |
4591 contents()->SetDelegate(delegate.get()); | 4737 contents()->SetDelegate(delegate.get()); |
4592 | 4738 |
4593 // Submit a form. | 4739 // Submit a form. |
4594 GURL url("http://foo"); | 4740 GURL url("http://foo"); |
4595 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4741 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4596 params.page_id = 1; | 4742 params.page_id = 1; |
| 4743 params.nav_entry_id = 0; |
| 4744 params.did_create_new_entry = true; |
4597 params.url = url; | 4745 params.url = url; |
4598 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; | 4746 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; |
4599 params.gesture = NavigationGestureUser; | 4747 params.gesture = NavigationGestureUser; |
4600 params.page_state = PageState::CreateFromURL(url); | 4748 params.page_state = PageState::CreateFromURL(url); |
4601 params.was_within_same_page = false; | 4749 params.was_within_same_page = false; |
4602 params.is_post = true; | 4750 params.is_post = true; |
4603 params.post_id = 2; | 4751 params.post_id = 2; |
4604 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 4752 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
4605 main_test_rfh()->PrepareForCommit(); | 4753 main_test_rfh()->PrepareForCommit(); |
4606 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4754 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4607 | 4755 |
4608 // history.replaceState() is called. | 4756 // history.replaceState() is called. |
4609 GURL replace_url("http://foo#foo"); | 4757 GURL replace_url("http://foo#foo"); |
4610 params.page_id = 1; | 4758 params.page_id = 1; |
| 4759 params.nav_entry_id = 0; |
| 4760 params.did_create_new_entry = false; |
4611 params.url = replace_url; | 4761 params.url = replace_url; |
4612 params.transition = ui::PAGE_TRANSITION_LINK; | 4762 params.transition = ui::PAGE_TRANSITION_LINK; |
4613 params.gesture = NavigationGestureUser; | 4763 params.gesture = NavigationGestureUser; |
4614 params.page_state = PageState::CreateFromURL(replace_url); | 4764 params.page_state = PageState::CreateFromURL(replace_url); |
4615 params.was_within_same_page = true; | 4765 params.was_within_same_page = true; |
4616 params.is_post = false; | 4766 params.is_post = false; |
4617 params.post_id = -1; | 4767 params.post_id = -1; |
4618 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); | 4768 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); |
4619 main_test_rfh()->PrepareForCommit(); | 4769 main_test_rfh()->PrepareForCommit(); |
4620 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4770 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4621 | 4771 |
4622 // Now reload. replaceState overrides the POST, so we should not show a | 4772 // Now reload. replaceState overrides the POST, so we should not show a |
4623 // repost warning dialog. | 4773 // repost warning dialog. |
4624 controller_impl().Reload(true); | 4774 controller_impl().Reload(true); |
4625 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4775 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
4626 } | 4776 } |
4627 | 4777 |
4628 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { | 4778 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
4629 GURL url("http://foo"); | 4779 GURL url("http://foo"); |
4630 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4780 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4631 params.page_id = 1; | 4781 params.page_id = 1; |
| 4782 params.nav_entry_id = 0; |
| 4783 params.did_create_new_entry = true; |
4632 params.url = url; | 4784 params.url = url; |
4633 params.transition = ui::PAGE_TRANSITION_LINK; | 4785 params.transition = ui::PAGE_TRANSITION_LINK; |
4634 params.gesture = NavigationGestureUser; | 4786 params.gesture = NavigationGestureUser; |
4635 params.page_state = PageState::CreateFromURL(url); | 4787 params.page_state = PageState::CreateFromURL(url); |
4636 params.was_within_same_page = false; | 4788 params.was_within_same_page = false; |
4637 params.is_post = true; | 4789 params.is_post = true; |
4638 params.post_id = 2; | 4790 params.post_id = 2; |
4639 params.url_is_unreachable = true; | 4791 params.url_is_unreachable = true; |
4640 // Navigate to new page | 4792 |
| 4793 // Navigate to new page. |
4641 { | 4794 { |
4642 LoadCommittedDetails details; | 4795 LoadCommittedDetails details; |
4643 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4796 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4644 EXPECT_EQ(PAGE_TYPE_ERROR, | 4797 EXPECT_EQ(PAGE_TYPE_ERROR, |
4645 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4798 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4646 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); | 4799 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); |
4647 } | 4800 } |
4648 | 4801 |
4649 // Navigate to existing page. | 4802 // Navigate to existing page. |
4650 { | 4803 { |
| 4804 params.did_create_new_entry = false; |
4651 LoadCommittedDetails details; | 4805 LoadCommittedDetails details; |
4652 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4806 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4653 EXPECT_EQ(PAGE_TYPE_ERROR, | 4807 EXPECT_EQ(PAGE_TYPE_ERROR, |
4654 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4808 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4655 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); | 4809 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); |
4656 } | 4810 } |
4657 | 4811 |
4658 // Navigate to same page. | 4812 // Navigate to same page. |
4659 // Note: The call to LoadURL() creates a pending entry in order to trigger the | 4813 // Note: The call to LoadURL() creates a pending entry in order to trigger the |
4660 // same-page transition. | 4814 // same-page transition. |
4661 controller_impl().LoadURL( | 4815 controller_impl().LoadURL( |
4662 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4816 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 4817 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID(); |
4663 params.transition = ui::PAGE_TRANSITION_TYPED; | 4818 params.transition = ui::PAGE_TRANSITION_TYPED; |
4664 { | 4819 { |
4665 LoadCommittedDetails details; | 4820 LoadCommittedDetails details; |
4666 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4821 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4667 EXPECT_EQ(PAGE_TYPE_ERROR, | 4822 EXPECT_EQ(PAGE_TYPE_ERROR, |
4668 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4823 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4669 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); | 4824 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); |
4670 } | 4825 } |
4671 | 4826 |
4672 // Navigate in page. | 4827 // Navigate in page. |
4673 params.url = GURL("http://foo#foo"); | 4828 params.url = GURL("http://foo#foo"); |
4674 params.transition = ui::PAGE_TRANSITION_LINK; | 4829 params.transition = ui::PAGE_TRANSITION_LINK; |
4675 params.was_within_same_page = true; | 4830 params.was_within_same_page = true; |
4676 { | 4831 { |
4677 LoadCommittedDetails details; | 4832 LoadCommittedDetails details; |
4678 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4833 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4679 EXPECT_EQ(PAGE_TYPE_ERROR, | 4834 EXPECT_EQ(PAGE_TYPE_ERROR, |
4680 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4835 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4681 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4836 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
4682 } | 4837 } |
4683 } | 4838 } |
4684 | 4839 |
4685 } // namespace content | 4840 } // namespace content |
OLD | NEW |