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

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

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

Powered by Google App Engine
This is Rietveld 408576698