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