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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698