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 17 matching lines...) Expand all Loading... |
2008 } | 1941 } |
2009 | 1942 |
2010 // Tests navigation via link click within a subframe. A new navigation entry | 1943 // Tests navigation via link click within a subframe. A new navigation entry |
2011 // should be created. | 1944 // should be created. |
2012 TEST_F(NavigationControllerTest, NewSubframe) { | 1945 TEST_F(NavigationControllerTest, NewSubframe) { |
2013 NavigationControllerImpl& controller = controller_impl(); | 1946 NavigationControllerImpl& controller = controller_impl(); |
2014 TestNotificationTracker notifications; | 1947 TestNotificationTracker notifications; |
2015 RegisterForAllNavNotifications(¬ifications, &controller); | 1948 RegisterForAllNavNotifications(¬ifications, &controller); |
2016 | 1949 |
2017 const GURL url1("http://foo1"); | 1950 const GURL url1("http://foo1"); |
2018 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 1951 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2019 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1952 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2020 navigation_entry_committed_counter_ = 0; | 1953 navigation_entry_committed_counter_ = 0; |
2021 | 1954 |
2022 const GURL url2("http://foo2"); | 1955 const GURL url2("http://foo2"); |
2023 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 1956 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2024 params.page_id = 1; | 1957 params.page_id = 1; |
2025 params.nav_entry_id = 0; | |
2026 params.did_create_new_entry = true; | |
2027 params.url = url2; | 1958 params.url = url2; |
2028 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 1959 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2029 params.should_update_history = false; | 1960 params.should_update_history = false; |
2030 params.gesture = NavigationGestureUser; | 1961 params.gesture = NavigationGestureUser; |
2031 params.is_post = false; | 1962 params.is_post = false; |
2032 params.page_state = PageState::CreateFromURL(url2); | 1963 params.page_state = PageState::CreateFromURL(url2); |
2033 | 1964 |
2034 LoadCommittedDetails details; | 1965 LoadCommittedDetails details; |
2035 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 1966 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2036 &details)); | 1967 &details)); |
(...skipping 15 matching lines...) Expand all Loading... |
2052 // Auto subframes are ones the page loads automatically like ads. They should | 1983 // Auto subframes are ones the page loads automatically like ads. They should |
2053 // not create new navigation entries. | 1984 // not create new navigation entries. |
2054 // TODO(creis): Test cross-site and nested iframes. | 1985 // TODO(creis): Test cross-site and nested iframes. |
2055 // TODO(creis): Test updating entries for history auto subframe navigations. | 1986 // TODO(creis): Test updating entries for history auto subframe navigations. |
2056 TEST_F(NavigationControllerTest, AutoSubframe) { | 1987 TEST_F(NavigationControllerTest, AutoSubframe) { |
2057 NavigationControllerImpl& controller = controller_impl(); | 1988 NavigationControllerImpl& controller = controller_impl(); |
2058 TestNotificationTracker notifications; | 1989 TestNotificationTracker notifications; |
2059 RegisterForAllNavNotifications(¬ifications, &controller); | 1990 RegisterForAllNavNotifications(¬ifications, &controller); |
2060 | 1991 |
2061 const GURL url1("http://foo/1"); | 1992 const GURL url1("http://foo/1"); |
2062 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); | 1993 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url1); |
2063 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1994 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2064 navigation_entry_committed_counter_ = 0; | 1995 navigation_entry_committed_counter_ = 0; |
2065 | 1996 |
2066 // Add a subframe and navigate it. | 1997 // Add a subframe and navigate it. |
2067 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), | 1998 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), |
2068 SandboxFlags::NONE); | 1999 SandboxFlags::NONE); |
2069 RenderFrameHostImpl* subframe = | 2000 RenderFrameHostImpl* subframe = |
2070 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); | 2001 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host(); |
2071 const GURL url2("http://foo/2"); | 2002 const GURL url2("http://foo/2"); |
2072 { | 2003 { |
2073 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2004 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2074 params.page_id = 1; | 2005 params.page_id = 1; |
2075 params.nav_entry_id = 0; | |
2076 params.did_create_new_entry = false; | |
2077 params.url = url2; | 2006 params.url = url2; |
2078 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2007 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
2079 params.should_update_history = false; | 2008 params.should_update_history = false; |
2080 params.gesture = NavigationGestureUser; | 2009 params.gesture = NavigationGestureUser; |
2081 params.is_post = false; | 2010 params.is_post = false; |
2082 params.page_state = PageState::CreateFromURL(url2); | 2011 params.page_state = PageState::CreateFromURL(url2); |
2083 | 2012 |
2084 // Navigating should do nothing. | 2013 // Navigating should do nothing. |
2085 LoadCommittedDetails details; | 2014 LoadCommittedDetails details; |
2086 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); | 2015 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 } | 2082 } |
2154 | 2083 |
2155 // Tests navigation and then going back to a subframe navigation. | 2084 // Tests navigation and then going back to a subframe navigation. |
2156 TEST_F(NavigationControllerTest, BackSubframe) { | 2085 TEST_F(NavigationControllerTest, BackSubframe) { |
2157 NavigationControllerImpl& controller = controller_impl(); | 2086 NavigationControllerImpl& controller = controller_impl(); |
2158 TestNotificationTracker notifications; | 2087 TestNotificationTracker notifications; |
2159 RegisterForAllNavNotifications(¬ifications, &controller); | 2088 RegisterForAllNavNotifications(¬ifications, &controller); |
2160 | 2089 |
2161 // Main page. | 2090 // Main page. |
2162 const GURL url1("http://foo1"); | 2091 const GURL url1("http://foo1"); |
2163 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 2092 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2164 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2093 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2165 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); | |
2166 navigation_entry_committed_counter_ = 0; | 2094 navigation_entry_committed_counter_ = 0; |
2167 | 2095 |
2168 // First manual subframe navigation. | 2096 // First manual subframe navigation. |
2169 const GURL url2("http://foo2"); | 2097 const GURL url2("http://foo2"); |
2170 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2098 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2171 params.page_id = 1; | 2099 params.page_id = 1; |
2172 params.nav_entry_id = 0; | |
2173 params.did_create_new_entry = true; | |
2174 params.url = url2; | 2100 params.url = url2; |
2175 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2101 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2176 params.should_update_history = false; | 2102 params.should_update_history = false; |
2177 params.gesture = NavigationGestureUser; | 2103 params.gesture = NavigationGestureUser; |
2178 params.is_post = false; | 2104 params.is_post = false; |
2179 params.page_state = PageState::CreateFromURL(url2); | 2105 params.page_state = PageState::CreateFromURL(url2); |
2180 | 2106 |
2181 // This should generate a new entry. | 2107 // This should generate a new entry. |
2182 LoadCommittedDetails details; | 2108 LoadCommittedDetails details; |
2183 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2109 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2184 &details)); | 2110 &details)); |
2185 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); | |
2186 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2111 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2187 navigation_entry_committed_counter_ = 0; | 2112 navigation_entry_committed_counter_ = 0; |
2188 EXPECT_EQ(2, controller.GetEntryCount()); | 2113 EXPECT_EQ(2, controller.GetEntryCount()); |
2189 | 2114 |
2190 // Second manual subframe navigation should also make a new entry. | 2115 // Second manual subframe navigation should also make a new entry. |
2191 const GURL url3("http://foo3"); | 2116 const GURL url3("http://foo3"); |
2192 params.page_id = 2; | 2117 params.page_id = 2; |
2193 params.nav_entry_id = 0; | |
2194 params.did_create_new_entry = true; | |
2195 params.url = url3; | 2118 params.url = url3; |
2196 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; | 2119 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; |
2197 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2120 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2198 &details)); | 2121 &details)); |
2199 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2122 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2200 navigation_entry_committed_counter_ = 0; | 2123 navigation_entry_committed_counter_ = 0; |
2201 EXPECT_EQ(3, controller.GetEntryCount()); | 2124 EXPECT_EQ(3, controller.GetEntryCount()); |
2202 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2125 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2203 | 2126 |
2204 // Go back one. | 2127 // Go back one. |
2205 controller.GoBack(); | 2128 controller.GoBack(); |
2206 params.page_id = 1; | 2129 params.page_id = 1; |
2207 params.nav_entry_id = entry2->GetUniqueID(); | |
2208 params.did_create_new_entry = false; | |
2209 params.url = url2; | 2130 params.url = url2; |
2210 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2131 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
2211 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2132 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2212 &details)); | 2133 &details)); |
2213 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2134 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2214 navigation_entry_committed_counter_ = 0; | 2135 navigation_entry_committed_counter_ = 0; |
2215 EXPECT_EQ(3, controller.GetEntryCount()); | 2136 EXPECT_EQ(3, controller.GetEntryCount()); |
2216 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2137 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
2217 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2138 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2218 EXPECT_FALSE(controller.GetPendingEntry()); | 2139 EXPECT_FALSE(controller.GetPendingEntry()); |
2219 | 2140 |
2220 // Go back one more. | 2141 // Go back one more. |
2221 controller.GoBack(); | 2142 controller.GoBack(); |
2222 params.page_id = 0; | 2143 params.page_id = 0; |
2223 params.nav_entry_id = entry1->GetUniqueID(); | |
2224 params.did_create_new_entry = false; | |
2225 params.url = url1; | 2144 params.url = url1; |
2226 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 2145 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
2227 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2146 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2228 &details)); | 2147 &details)); |
2229 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2148 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2230 navigation_entry_committed_counter_ = 0; | 2149 navigation_entry_committed_counter_ = 0; |
2231 EXPECT_EQ(3, controller.GetEntryCount()); | 2150 EXPECT_EQ(3, controller.GetEntryCount()); |
2232 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2151 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
2233 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2152 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2234 EXPECT_FALSE(controller.GetPendingEntry()); | 2153 EXPECT_FALSE(controller.GetPendingEntry()); |
2235 } | 2154 } |
2236 | 2155 |
2237 TEST_F(NavigationControllerTest, LinkClick) { | 2156 TEST_F(NavigationControllerTest, LinkClick) { |
2238 NavigationControllerImpl& controller = controller_impl(); | 2157 NavigationControllerImpl& controller = controller_impl(); |
2239 TestNotificationTracker notifications; | 2158 TestNotificationTracker notifications; |
2240 RegisterForAllNavNotifications(¬ifications, &controller); | 2159 RegisterForAllNavNotifications(¬ifications, &controller); |
2241 | 2160 |
2242 const GURL url1("http://foo1"); | 2161 const GURL url1("http://foo1"); |
2243 const GURL url2("http://foo2"); | 2162 const GURL url2("http://foo2"); |
2244 | 2163 |
2245 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 2164 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2246 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2165 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2247 navigation_entry_committed_counter_ = 0; | 2166 navigation_entry_committed_counter_ = 0; |
2248 | 2167 |
2249 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url2); | 2168 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url2); |
2250 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2169 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2251 navigation_entry_committed_counter_ = 0; | 2170 navigation_entry_committed_counter_ = 0; |
2252 | 2171 |
2253 // Should have produced a new session history entry. | 2172 // Should not have produced a new session history entry. |
2254 EXPECT_EQ(controller.GetEntryCount(), 2); | 2173 EXPECT_EQ(controller.GetEntryCount(), 2); |
2255 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2174 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2256 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2175 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2257 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2176 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2258 EXPECT_FALSE(controller.GetPendingEntry()); | 2177 EXPECT_FALSE(controller.GetPendingEntry()); |
2259 EXPECT_TRUE(controller.CanGoBack()); | 2178 EXPECT_TRUE(controller.CanGoBack()); |
2260 EXPECT_FALSE(controller.CanGoForward()); | 2179 EXPECT_FALSE(controller.CanGoForward()); |
2261 } | 2180 } |
2262 | 2181 |
2263 TEST_F(NavigationControllerTest, InPage) { | 2182 TEST_F(NavigationControllerTest, InPage) { |
2264 NavigationControllerImpl& controller = controller_impl(); | 2183 NavigationControllerImpl& controller = controller_impl(); |
2265 TestNotificationTracker notifications; | 2184 TestNotificationTracker notifications; |
2266 RegisterForAllNavNotifications(¬ifications, &controller); | 2185 RegisterForAllNavNotifications(¬ifications, &controller); |
2267 | 2186 |
2268 // Main page. | 2187 // Main page. |
2269 const GURL url1("http://foo"); | 2188 const GURL url1("http://foo"); |
2270 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 2189 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2271 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2190 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2272 navigation_entry_committed_counter_ = 0; | 2191 navigation_entry_committed_counter_ = 0; |
2273 | 2192 |
2274 // Ensure main page navigation to same url respects the was_within_same_page | 2193 // Ensure main page navigation to same url respects the was_within_same_page |
2275 // hint provided in the params. | 2194 // hint provided in the params. |
2276 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; | 2195 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; |
2277 self_params.page_id = 0; | 2196 self_params.page_id = 0; |
2278 self_params.nav_entry_id = 0; | |
2279 self_params.did_create_new_entry = false; | |
2280 self_params.url = url1; | 2197 self_params.url = url1; |
2281 self_params.transition = ui::PAGE_TRANSITION_LINK; | 2198 self_params.transition = ui::PAGE_TRANSITION_LINK; |
2282 self_params.should_update_history = false; | 2199 self_params.should_update_history = false; |
2283 self_params.gesture = NavigationGestureUser; | 2200 self_params.gesture = NavigationGestureUser; |
2284 self_params.is_post = false; | 2201 self_params.is_post = false; |
2285 self_params.page_state = PageState::CreateFromURL(url1); | 2202 self_params.page_state = PageState::CreateFromURL(url1); |
2286 self_params.was_within_same_page = true; | 2203 self_params.was_within_same_page = true; |
2287 | 2204 |
2288 LoadCommittedDetails details; | 2205 LoadCommittedDetails details; |
2289 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, | 2206 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, |
2290 &details)); | 2207 &details)); |
2291 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); | |
2292 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2208 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2293 navigation_entry_committed_counter_ = 0; | 2209 navigation_entry_committed_counter_ = 0; |
2294 EXPECT_TRUE(details.is_in_page); | 2210 EXPECT_TRUE(details.is_in_page); |
2295 EXPECT_TRUE(details.did_replace_entry); | 2211 EXPECT_TRUE(details.did_replace_entry); |
2296 EXPECT_EQ(1, controller.GetEntryCount()); | 2212 EXPECT_EQ(1, controller.GetEntryCount()); |
2297 | 2213 |
2298 // Fragment navigation to a new page_id. | 2214 // Fragment navigation to a new page_id. |
2299 const GURL url2("http://foo#a"); | 2215 const GURL url2("http://foo#a"); |
2300 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2216 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2301 params.page_id = 1; | 2217 params.page_id = 1; |
2302 params.nav_entry_id = 0; | |
2303 params.did_create_new_entry = true; | |
2304 params.url = url2; | 2218 params.url = url2; |
2305 params.transition = ui::PAGE_TRANSITION_LINK; | 2219 params.transition = ui::PAGE_TRANSITION_LINK; |
2306 params.should_update_history = false; | 2220 params.should_update_history = false; |
2307 params.gesture = NavigationGestureUser; | 2221 params.gesture = NavigationGestureUser; |
2308 params.is_post = false; | 2222 params.is_post = false; |
2309 params.page_state = PageState::CreateFromURL(url2); | 2223 params.page_state = PageState::CreateFromURL(url2); |
2310 params.was_within_same_page = true; | 2224 params.was_within_same_page = true; |
2311 | 2225 |
2312 // This should generate a new entry. | 2226 // This should generate a new entry. |
2313 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2227 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2314 &details)); | 2228 &details)); |
2315 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); | |
2316 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2229 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2317 navigation_entry_committed_counter_ = 0; | 2230 navigation_entry_committed_counter_ = 0; |
2318 EXPECT_TRUE(details.is_in_page); | 2231 EXPECT_TRUE(details.is_in_page); |
2319 EXPECT_FALSE(details.did_replace_entry); | 2232 EXPECT_FALSE(details.did_replace_entry); |
2320 EXPECT_EQ(2, controller.GetEntryCount()); | 2233 EXPECT_EQ(2, controller.GetEntryCount()); |
2321 | 2234 |
2322 // Go back one. | 2235 // Go back one. |
2323 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); | 2236 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); |
2324 controller.GoBack(); | 2237 controller.GoBack(); |
2325 back_params.url = url1; | 2238 back_params.url = url1; |
2326 back_params.page_id = 0; | 2239 back_params.page_id = 0; |
2327 back_params.nav_entry_id = entry1->GetUniqueID(); | |
2328 back_params.did_create_new_entry = false; | |
2329 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, | 2240 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, |
2330 &details)); | 2241 &details)); |
2331 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2242 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2332 navigation_entry_committed_counter_ = 0; | 2243 navigation_entry_committed_counter_ = 0; |
2333 EXPECT_TRUE(details.is_in_page); | 2244 EXPECT_TRUE(details.is_in_page); |
2334 EXPECT_EQ(2, controller.GetEntryCount()); | 2245 EXPECT_EQ(2, controller.GetEntryCount()); |
2335 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2246 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
2336 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); | 2247 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
2337 | 2248 |
2338 // Go forward. | 2249 // Go forward |
2339 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); | 2250 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); |
2340 controller.GoForward(); | 2251 controller.GoForward(); |
2341 forward_params.url = url2; | 2252 forward_params.url = url2; |
2342 forward_params.page_id = 1; | 2253 forward_params.page_id = 1; |
2343 forward_params.nav_entry_id = entry2->GetUniqueID(); | |
2344 forward_params.did_create_new_entry = false; | |
2345 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, | 2254 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, |
2346 &details)); | 2255 &details)); |
2347 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2256 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2348 navigation_entry_committed_counter_ = 0; | 2257 navigation_entry_committed_counter_ = 0; |
2349 EXPECT_TRUE(details.is_in_page); | 2258 EXPECT_TRUE(details.is_in_page); |
2350 EXPECT_EQ(2, controller.GetEntryCount()); | 2259 EXPECT_EQ(2, controller.GetEntryCount()); |
2351 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2260 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
2352 EXPECT_EQ(forward_params.url, | 2261 EXPECT_EQ(forward_params.url, |
2353 controller.GetVisibleEntry()->GetURL()); | 2262 controller.GetVisibleEntry()->GetURL()); |
2354 | 2263 |
2355 // Now go back and forward again. This is to work around a bug where we would | 2264 // Now go back and forward again. This is to work around a bug where we would |
2356 // compare the incoming URL with the last committed entry rather than the | 2265 // compare the incoming URL with the last committed entry rather than the |
2357 // one identified by an existing page ID. This would result in the second URL | 2266 // one identified by an existing page ID. This would result in the second URL |
2358 // losing the reference fragment when you navigate away from it and then back. | 2267 // losing the reference fragment when you navigate away from it and then back. |
2359 controller.GoBack(); | 2268 controller.GoBack(); |
2360 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, | 2269 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, |
2361 &details)); | 2270 &details)); |
2362 controller.GoForward(); | 2271 controller.GoForward(); |
2363 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, | 2272 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, |
2364 &details)); | 2273 &details)); |
2365 EXPECT_EQ(forward_params.url, | 2274 EXPECT_EQ(forward_params.url, |
2366 controller.GetVisibleEntry()->GetURL()); | 2275 controller.GetVisibleEntry()->GetURL()); |
2367 | 2276 |
2368 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. | 2277 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. |
2369 const GURL url3("http://bar"); | 2278 const GURL url3("http://bar"); |
2370 params.page_id = 2; | 2279 params.page_id = 2; |
2371 params.nav_entry_id = 0; | |
2372 params.did_create_new_entry = true; | |
2373 params.url = url3; | 2280 params.url = url3; |
2374 navigation_entry_committed_counter_ = 0; | 2281 navigation_entry_committed_counter_ = 0; |
2375 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2282 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2376 &details)); | 2283 &details)); |
2377 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2284 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2378 navigation_entry_committed_counter_ = 0; | 2285 navigation_entry_committed_counter_ = 0; |
2379 EXPECT_FALSE(details.is_in_page); | 2286 EXPECT_FALSE(details.is_in_page); |
2380 EXPECT_EQ(3, controller.GetEntryCount()); | 2287 EXPECT_EQ(3, controller.GetEntryCount()); |
2381 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2288 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2382 } | 2289 } |
2383 | 2290 |
2384 TEST_F(NavigationControllerTest, InPage_Replace) { | 2291 TEST_F(NavigationControllerTest, InPage_Replace) { |
2385 NavigationControllerImpl& controller = controller_impl(); | 2292 NavigationControllerImpl& controller = controller_impl(); |
2386 TestNotificationTracker notifications; | 2293 TestNotificationTracker notifications; |
2387 RegisterForAllNavNotifications(¬ifications, &controller); | 2294 RegisterForAllNavNotifications(¬ifications, &controller); |
2388 | 2295 |
2389 // Main page. | 2296 // Main page. |
2390 const GURL url1("http://foo"); | 2297 const GURL url1("http://foo"); |
2391 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 2298 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
2392 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2299 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2393 navigation_entry_committed_counter_ = 0; | 2300 navigation_entry_committed_counter_ = 0; |
2394 | 2301 |
2395 // First navigation. | 2302 // First navigation. |
2396 const GURL url2("http://foo#a"); | 2303 const GURL url2("http://foo#a"); |
2397 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2304 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2398 params.page_id = 0; // Same page_id | 2305 params.page_id = 0; // Same page_id |
2399 params.nav_entry_id = 0; | |
2400 params.did_create_new_entry = false; | |
2401 params.url = url2; | 2306 params.url = url2; |
2402 params.transition = ui::PAGE_TRANSITION_LINK; | 2307 params.transition = ui::PAGE_TRANSITION_LINK; |
2403 params.should_update_history = false; | 2308 params.should_update_history = false; |
2404 params.gesture = NavigationGestureUser; | 2309 params.gesture = NavigationGestureUser; |
2405 params.is_post = false; | 2310 params.is_post = false; |
2406 params.page_state = PageState::CreateFromURL(url2); | 2311 params.page_state = PageState::CreateFromURL(url2); |
2407 params.was_within_same_page = true; | 2312 params.was_within_same_page = true; |
2408 | 2313 |
2409 // This should NOT generate a new entry, nor prune the list. | 2314 // This should NOT generate a new entry, nor prune the list. |
2410 LoadCommittedDetails details; | 2315 LoadCommittedDetails details; |
(...skipping 13 matching lines...) Expand all Loading... |
2424 // window.location='http://foo3/'; | 2329 // window.location='http://foo3/'; |
2425 // </script> | 2330 // </script> |
2426 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 2331 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
2427 NavigationControllerImpl& controller = controller_impl(); | 2332 NavigationControllerImpl& controller = controller_impl(); |
2428 TestNotificationTracker notifications; | 2333 TestNotificationTracker notifications; |
2429 RegisterForAllNavNotifications(¬ifications, &controller); | 2334 RegisterForAllNavNotifications(¬ifications, &controller); |
2430 | 2335 |
2431 // Load an initial page. | 2336 // Load an initial page. |
2432 { | 2337 { |
2433 const GURL url("http://foo/"); | 2338 const GURL url("http://foo/"); |
2434 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); | 2339 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
2435 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2340 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2436 navigation_entry_committed_counter_ = 0; | 2341 navigation_entry_committed_counter_ = 0; |
2437 } | 2342 } |
2438 | 2343 |
2439 // Navigate to a new page. | 2344 // Navigate to a new page. |
2440 { | 2345 { |
2441 const GURL url("http://foo2/"); | 2346 const GURL url("http://foo2/"); |
2442 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url); | 2347 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url); |
2443 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2348 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2444 navigation_entry_committed_counter_ = 0; | 2349 navigation_entry_committed_counter_ = 0; |
2445 } | 2350 } |
2446 | 2351 |
2447 // Navigate within the page. | 2352 // Navigate within the page. |
2448 { | 2353 { |
2449 const GURL url("http://foo2/#a"); | 2354 const GURL url("http://foo2/#a"); |
2450 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2355 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2451 params.page_id = 1; // Same page_id | 2356 params.page_id = 1; // Same page_id |
2452 params.nav_entry_id = 0; | |
2453 params.did_create_new_entry = false; | |
2454 params.url = url; | 2357 params.url = url; |
2455 params.transition = ui::PAGE_TRANSITION_LINK; | 2358 params.transition = ui::PAGE_TRANSITION_LINK; |
2456 params.redirects.push_back(url); | 2359 params.redirects.push_back(url); |
2457 params.should_update_history = true; | 2360 params.should_update_history = true; |
2458 params.gesture = NavigationGestureUnknown; | 2361 params.gesture = NavigationGestureUnknown; |
2459 params.is_post = false; | 2362 params.is_post = false; |
2460 params.page_state = PageState::CreateFromURL(url); | 2363 params.page_state = PageState::CreateFromURL(url); |
2461 params.was_within_same_page = true; | 2364 params.was_within_same_page = true; |
2462 | 2365 |
2463 // This should NOT generate a new entry, nor prune the list. | 2366 // This should NOT generate a new entry, nor prune the list. |
2464 LoadCommittedDetails details; | 2367 LoadCommittedDetails details; |
2465 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2368 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2466 &details)); | 2369 &details)); |
2467 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2370 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2468 navigation_entry_committed_counter_ = 0; | 2371 navigation_entry_committed_counter_ = 0; |
2469 EXPECT_TRUE(details.is_in_page); | 2372 EXPECT_TRUE(details.is_in_page); |
2470 EXPECT_TRUE(details.did_replace_entry); | 2373 EXPECT_TRUE(details.did_replace_entry); |
2471 EXPECT_EQ(2, controller.GetEntryCount()); | 2374 EXPECT_EQ(2, controller.GetEntryCount()); |
2472 } | 2375 } |
2473 | 2376 |
2474 // Perform a client redirect to a new page. | 2377 // Perform a client redirect to a new page. |
2475 { | 2378 { |
2476 const GURL url("http://foo3/"); | 2379 const GURL url("http://foo3/"); |
2477 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2380 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2478 params.page_id = 2; // New page_id | 2381 params.page_id = 2; // New page_id |
2479 params.nav_entry_id = 0; | |
2480 params.did_create_new_entry = true; | |
2481 params.url = url; | 2382 params.url = url; |
2482 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 2383 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
2483 params.redirects.push_back(GURL("http://foo2/#a")); | 2384 params.redirects.push_back(GURL("http://foo2/#a")); |
2484 params.redirects.push_back(url); | 2385 params.redirects.push_back(url); |
2485 params.should_update_history = true; | 2386 params.should_update_history = true; |
2486 params.gesture = NavigationGestureUnknown; | 2387 params.gesture = NavigationGestureUnknown; |
2487 params.is_post = false; | 2388 params.is_post = false; |
2488 params.page_state = PageState::CreateFromURL(url); | 2389 params.page_state = PageState::CreateFromURL(url); |
2489 | 2390 |
2490 // This SHOULD generate a new entry. | 2391 // This SHOULD generate a new entry. |
2491 LoadCommittedDetails details; | 2392 LoadCommittedDetails details; |
2492 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, | 2393 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, |
2493 &details)); | 2394 &details)); |
2494 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2395 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2495 navigation_entry_committed_counter_ = 0; | 2396 navigation_entry_committed_counter_ = 0; |
2496 EXPECT_FALSE(details.is_in_page); | 2397 EXPECT_FALSE(details.is_in_page); |
2497 EXPECT_EQ(3, controller.GetEntryCount()); | 2398 EXPECT_EQ(3, controller.GetEntryCount()); |
2498 } | 2399 } |
2499 | 2400 |
2500 // Verify that BACK brings us back to http://foo2/. | 2401 // Verify that BACK brings us back to http://foo2/. |
2501 { | 2402 { |
2502 const GURL url("http://foo2/"); | 2403 const GURL url("http://foo2/"); |
2503 controller.GoBack(); | 2404 controller.GoBack(); |
2504 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2505 main_test_rfh()->PrepareForCommit(); | 2405 main_test_rfh()->PrepareForCommit(); |
2506 main_test_rfh()->SendNavigate(1, entry_id, false, url); | 2406 main_test_rfh()->SendNavigate(1, url); |
2507 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2407 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2508 navigation_entry_committed_counter_ = 0; | 2408 navigation_entry_committed_counter_ = 0; |
2509 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2409 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
2510 } | 2410 } |
2511 } | 2411 } |
2512 | 2412 |
2513 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) | 2413 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) |
2514 { | 2414 { |
2515 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); | 2415 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); |
2516 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2416 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2517 GURL url("http://foo"); | 2417 GURL url("http://foo"); |
2518 params.page_id = 1; | 2418 params.page_id = 1; |
2519 params.nav_entry_id = 0; | |
2520 params.did_create_new_entry = true; | |
2521 params.url = url; | 2419 params.url = url; |
2522 params.page_state = PageState::CreateFromURL(url); | 2420 params.page_state = PageState::CreateFromURL(url); |
2523 params.was_within_same_page = true; | 2421 params.was_within_same_page = true; |
2524 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 2422 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
2525 main_test_rfh()->PrepareForCommit(); | 2423 main_test_rfh()->PrepareForCommit(); |
2526 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 2424 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
2527 // We pass if we don't crash. | 2425 // We pass if we don't crash. |
2528 } | 2426 } |
2529 | 2427 |
2530 // NotificationObserver implementation used in verifying we've received the | 2428 // NotificationObserver implementation used in verifying we've received the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 const int kMaxEntryCount = 5; | 2463 const int kMaxEntryCount = 5; |
2566 | 2464 |
2567 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2465 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
2568 | 2466 |
2569 int url_index; | 2467 int url_index; |
2570 // Load up to the max count, all entries should be there. | 2468 // Load up to the max count, all entries should be there. |
2571 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2469 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
2572 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2470 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2573 controller.LoadURL( | 2471 controller.LoadURL( |
2574 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2472 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2575 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2576 main_test_rfh()->PrepareForCommit(); | 2473 main_test_rfh()->PrepareForCommit(); |
2577 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); | 2474 main_test_rfh()->SendNavigate(url_index, url); |
2578 } | 2475 } |
2579 | 2476 |
2580 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2477 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2581 | 2478 |
2582 // Created a PrunedListener to observe prune notifications. | 2479 // Created a PrunedListener to observe prune notifications. |
2583 PrunedListener listener(&controller); | 2480 PrunedListener listener(&controller); |
2584 | 2481 |
2585 // Navigate some more. | 2482 // Navigate some more. |
2586 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2483 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2587 controller.LoadURL( | 2484 controller.LoadURL( |
2588 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2485 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2589 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2590 main_test_rfh()->PrepareForCommit(); | 2486 main_test_rfh()->PrepareForCommit(); |
2591 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); | 2487 main_test_rfh()->SendNavigate(url_index, url); |
2592 url_index++; | 2488 url_index++; |
2593 | 2489 |
2594 // We should have got a pruned navigation. | 2490 // We should have got a pruned navigation. |
2595 EXPECT_EQ(1, listener.notification_count_); | 2491 EXPECT_EQ(1, listener.notification_count_); |
2596 EXPECT_TRUE(listener.details_.from_front); | 2492 EXPECT_TRUE(listener.details_.from_front); |
2597 EXPECT_EQ(1, listener.details_.count); | 2493 EXPECT_EQ(1, listener.details_.count); |
2598 | 2494 |
2599 // We expect http://www.a.com/0 to be gone. | 2495 // We expect http://www.a.com/0 to be gone. |
2600 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2496 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2601 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2497 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2602 GURL("http://www.a.com/1")); | 2498 GURL("http:////www.a.com/1")); |
2603 | 2499 |
2604 // More navigations. | 2500 // More navigations. |
2605 for (int i = 0; i < 3; i++) { | 2501 for (int i = 0; i < 3; i++) { |
2606 url = GURL(base::StringPrintf("http://www.a.com/%d", url_index)); | 2502 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); |
2607 controller.LoadURL( | 2503 controller.LoadURL( |
2608 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2504 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2609 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2610 main_test_rfh()->PrepareForCommit(); | 2505 main_test_rfh()->PrepareForCommit(); |
2611 main_test_rfh()->SendNavigate(url_index, entry_id, true, url); | 2506 main_test_rfh()->SendNavigate(url_index, url); |
2612 url_index++; | 2507 url_index++; |
2613 } | 2508 } |
2614 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2509 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2615 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2510 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2616 GURL("http://www.a.com/4")); | 2511 GURL("http:////www.a.com/4")); |
2617 | 2512 |
2618 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2513 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
2619 } | 2514 } |
2620 | 2515 |
2621 // Tests that we can do a restore and navigate to the restored entries and | 2516 // Tests that we can do a restore and navigate to the restored entries and |
2622 // everything is updated properly. This can be tricky since there is no | 2517 // everything is updated properly. This can be tricky since there is no |
2623 // SiteInstance for the entries created initially. | 2518 // SiteInstance for the entries created initially. |
2624 TEST_F(NavigationControllerTest, RestoreNavigate) { | 2519 TEST_F(NavigationControllerTest, RestoreNavigate) { |
2625 // Create a NavigationController with a restored set of tabs. | 2520 // Create a NavigationController with a restored set of tabs. |
2626 GURL url("http://foo"); | 2521 GURL url("http://foo"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2660 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2555 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2661 our_controller.GetEntryAtIndex(0)->restore_type()); | 2556 our_controller.GetEntryAtIndex(0)->restore_type()); |
2662 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2557 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2663 | 2558 |
2664 // Timestamp should remain the same before the navigation finishes. | 2559 // Timestamp should remain the same before the navigation finishes. |
2665 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); | 2560 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); |
2666 | 2561 |
2667 // Say we navigated to that entry. | 2562 // Say we navigated to that entry. |
2668 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2563 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2669 params.page_id = 0; | 2564 params.page_id = 0; |
2670 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID(); | |
2671 params.did_create_new_entry = false; | |
2672 params.url = url; | 2565 params.url = url; |
2673 params.transition = ui::PAGE_TRANSITION_LINK; | 2566 params.transition = ui::PAGE_TRANSITION_LINK; |
2674 params.should_update_history = false; | 2567 params.should_update_history = false; |
2675 params.gesture = NavigationGestureUser; | 2568 params.gesture = NavigationGestureUser; |
2676 params.is_post = false; | 2569 params.is_post = false; |
2677 params.page_state = PageState::CreateFromURL(url); | 2570 params.page_state = PageState::CreateFromURL(url); |
2678 LoadCommittedDetails details; | 2571 LoadCommittedDetails details; |
2679 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2572 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
2680 &details); | 2573 &details); |
2681 | 2574 |
(...skipping 28 matching lines...) Expand all Loading... |
2710 entries.push_back(entry); | 2603 entries.push_back(entry); |
2711 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 2604 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
2712 WebContents::Create(WebContents::CreateParams(browser_context())))); | 2605 WebContents::Create(WebContents::CreateParams(browser_context())))); |
2713 NavigationControllerImpl& our_controller = our_contents->GetController(); | 2606 NavigationControllerImpl& our_controller = our_contents->GetController(); |
2714 our_controller.Restore( | 2607 our_controller.Restore( |
2715 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | 2608 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
2716 ASSERT_EQ(0u, entries.size()); | 2609 ASSERT_EQ(0u, entries.size()); |
2717 | 2610 |
2718 // Before navigating to the restored entry, it should have a restore_type | 2611 // Before navigating to the restored entry, it should have a restore_type |
2719 // and no SiteInstance. | 2612 // and no SiteInstance. |
2720 entry = our_controller.GetEntryAtIndex(0); | |
2721 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2613 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
2722 our_controller.GetEntryAtIndex(0)->restore_type()); | 2614 our_controller.GetEntryAtIndex(0)->restore_type()); |
2723 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2615 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2724 | 2616 |
2725 // After navigating, we should have one entry, and it should be "pending". | 2617 // After navigating, we should have one entry, and it should be "pending". |
2726 // It should now have a SiteInstance and no restore_type. | 2618 // It should now have a SiteInstance and no restore_type. |
2727 our_controller.GoToIndex(0); | 2619 our_controller.GoToIndex(0); |
2728 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2620 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2729 EXPECT_EQ(our_controller.GetEntryAtIndex(0), | 2621 EXPECT_EQ(our_controller.GetEntryAtIndex(0), |
2730 our_controller.GetPendingEntry()); | 2622 our_controller.GetPendingEntry()); |
2731 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); | 2623 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); |
2732 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2624 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2733 our_controller.GetEntryAtIndex(0)->restore_type()); | 2625 our_controller.GetEntryAtIndex(0)->restore_type()); |
2734 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); | 2626 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); |
2735 | 2627 |
2736 // This pending navigation may have caused a different navigation to fail, | 2628 // This pending navigation may have caused a different navigation to fail, |
2737 // which causes the pending entry to be cleared. | 2629 // which causes the pending entry to be cleared. |
2738 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; | 2630 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; |
2739 fail_load_params.error_code = net::ERR_ABORTED; | 2631 fail_load_params.error_code = net::ERR_ABORTED; |
2740 fail_load_params.error_description = base::string16(); | 2632 fail_load_params.error_description = base::string16(); |
2741 fail_load_params.url = url; | 2633 fail_load_params.url = url; |
2742 fail_load_params.showing_repost_interstitial = false; | 2634 fail_load_params.showing_repost_interstitial = false; |
2743 main_test_rfh()->OnMessageReceived( | 2635 main_test_rfh()->OnMessageReceived( |
2744 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 2636 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
2745 fail_load_params)); | 2637 fail_load_params)); |
2746 | 2638 |
2747 // Now the pending restored entry commits. | 2639 // Now the pending restored entry commits. |
2748 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 2640 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2749 params.page_id = 0; | 2641 params.page_id = 0; |
2750 params.nav_entry_id = entry->GetUniqueID(); | |
2751 params.did_create_new_entry = false; | |
2752 params.url = url; | 2642 params.url = url; |
2753 params.transition = ui::PAGE_TRANSITION_LINK; | 2643 params.transition = ui::PAGE_TRANSITION_LINK; |
2754 params.should_update_history = false; | 2644 params.should_update_history = false; |
2755 params.gesture = NavigationGestureUser; | 2645 params.gesture = NavigationGestureUser; |
2756 params.is_post = false; | 2646 params.is_post = false; |
2757 params.page_state = PageState::CreateFromURL(url); | 2647 params.page_state = PageState::CreateFromURL(url); |
2758 LoadCommittedDetails details; | 2648 LoadCommittedDetails details; |
2759 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, | 2649 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, |
2760 &details); | 2650 &details); |
2761 | 2651 |
2762 // There should be no pending entry and one committed one. | 2652 // There should be no pending entry and one committed one. |
2763 EXPECT_EQ(1, our_controller.GetEntryCount()); | 2653 EXPECT_EQ(1, our_controller.GetEntryCount()); |
2764 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); | 2654 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); |
2765 EXPECT_FALSE(our_controller.GetPendingEntry()); | 2655 EXPECT_FALSE(our_controller.GetPendingEntry()); |
2766 EXPECT_EQ( | 2656 EXPECT_EQ( |
2767 url, | 2657 url, |
2768 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); | 2658 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); |
2769 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2659 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2770 our_controller.GetEntryAtIndex(0)->restore_type()); | 2660 our_controller.GetEntryAtIndex(0)->restore_type()); |
2771 } | 2661 } |
2772 | 2662 |
2773 // Make sure that the page type and stuff is correct after an interstitial. | 2663 // Make sure that the page type and stuff is correct after an interstitial. |
2774 TEST_F(NavigationControllerTest, Interstitial) { | 2664 TEST_F(NavigationControllerTest, Interstitial) { |
2775 NavigationControllerImpl& controller = controller_impl(); | 2665 NavigationControllerImpl& controller = controller_impl(); |
2776 // First navigate somewhere normal. | 2666 // First navigate somewhere normal. |
2777 const GURL url1("http://foo"); | 2667 const GURL url1("http://foo"); |
2778 controller.LoadURL( | 2668 controller.LoadURL( |
2779 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2669 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2780 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2781 main_test_rfh()->PrepareForCommit(); | 2670 main_test_rfh()->PrepareForCommit(); |
2782 main_test_rfh()->SendNavigate(0, entry_id, true, url1); | 2671 main_test_rfh()->SendNavigate(0, url1); |
2783 | 2672 |
2784 // Now navigate somewhere with an interstitial. | 2673 // Now navigate somewhere with an interstitial. |
2785 const GURL url2("http://bar"); | 2674 const GURL url2("http://bar"); |
2786 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, | 2675 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
2787 std::string()); | 2676 std::string()); |
2788 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2789 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); | 2677 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); |
2790 | 2678 |
2791 // At this point the interstitial will be displayed and the load will still | 2679 // At this point the interstitial will be displayed and the load will still |
2792 // be pending. If the user continues, the load will commit. | 2680 // be pending. If the user continues, the load will commit. |
2793 main_test_rfh()->PrepareForCommit(); | 2681 main_test_rfh()->PrepareForCommit(); |
2794 main_test_rfh()->SendNavigate(1, entry_id, true, url2); | 2682 main_test_rfh()->SendNavigate(1, url2); |
2795 | 2683 |
2796 // The page should be a normal page again. | 2684 // The page should be a normal page again. |
2797 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2685 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2798 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2686 EXPECT_EQ(PAGE_TYPE_NORMAL, |
2799 controller.GetLastCommittedEntry()->GetPageType()); | 2687 controller.GetLastCommittedEntry()->GetPageType()); |
2800 } | 2688 } |
2801 | 2689 |
2802 TEST_F(NavigationControllerTest, RemoveEntry) { | 2690 TEST_F(NavigationControllerTest, RemoveEntry) { |
2803 NavigationControllerImpl& controller = controller_impl(); | 2691 NavigationControllerImpl& controller = controller_impl(); |
2804 const GURL url1("http://foo/1"); | 2692 const GURL url1("http://foo/1"); |
2805 const GURL url2("http://foo/2"); | 2693 const GURL url2("http://foo/2"); |
2806 const GURL url3("http://foo/3"); | 2694 const GURL url3("http://foo/3"); |
2807 const GURL url4("http://foo/4"); | 2695 const GURL url4("http://foo/4"); |
2808 const GURL url5("http://foo/5"); | 2696 const GURL url5("http://foo/5"); |
2809 const GURL pending_url("http://foo/pending"); | 2697 const GURL pending_url("http://foo/pending"); |
2810 const GURL default_url("http://foo/default"); | 2698 const GURL default_url("http://foo/default"); |
2811 | 2699 |
2812 controller.LoadURL( | 2700 controller.LoadURL( |
2813 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2701 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2814 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2815 main_test_rfh()->PrepareForCommit(); | 2702 main_test_rfh()->PrepareForCommit(); |
2816 main_test_rfh()->SendNavigate(0, entry_id, true, url1); | 2703 main_test_rfh()->SendNavigate(0, url1); |
2817 controller.LoadURL( | 2704 controller.LoadURL( |
2818 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2705 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2819 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2820 main_test_rfh()->PrepareForCommit(); | 2706 main_test_rfh()->PrepareForCommit(); |
2821 main_test_rfh()->SendNavigate(1, entry_id, true, url2); | 2707 main_test_rfh()->SendNavigate(1, url2); |
2822 controller.LoadURL( | 2708 controller.LoadURL( |
2823 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2709 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2824 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2825 main_test_rfh()->PrepareForCommit(); | 2710 main_test_rfh()->PrepareForCommit(); |
2826 main_test_rfh()->SendNavigate(2, entry_id, true, url3); | 2711 main_test_rfh()->SendNavigate(2, url3); |
2827 controller.LoadURL( | 2712 controller.LoadURL( |
2828 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2713 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2829 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2830 main_test_rfh()->PrepareForCommit(); | 2714 main_test_rfh()->PrepareForCommit(); |
2831 main_test_rfh()->SendNavigate(3, entry_id, true, url4); | 2715 main_test_rfh()->SendNavigate(3, url4); |
2832 controller.LoadURL( | 2716 controller.LoadURL( |
2833 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2717 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2834 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2835 main_test_rfh()->PrepareForCommit(); | 2718 main_test_rfh()->PrepareForCommit(); |
2836 main_test_rfh()->SendNavigate(4, entry_id, true, url5); | 2719 main_test_rfh()->SendNavigate(4, url5); |
2837 | 2720 |
2838 // Try to remove the last entry. Will fail because it is the current entry. | 2721 // Try to remove the last entry. Will fail because it is the current entry. |
2839 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2722 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2840 EXPECT_EQ(5, controller.GetEntryCount()); | 2723 EXPECT_EQ(5, controller.GetEntryCount()); |
2841 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2724 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
2842 | 2725 |
2843 // Go back, but don't commit yet. Check that we can't delete the current | 2726 // Go back, but don't commit yet. Check that we can't delete the current |
2844 // and pending entries. | 2727 // and pending entries. |
2845 controller.GoBack(); | 2728 controller.GoBack(); |
2846 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2847 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2729 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2848 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2730 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
2849 | 2731 |
2850 // Now commit and delete the last entry. | 2732 // Now commit and delete the last entry. |
2851 main_test_rfh()->PrepareForCommit(); | 2733 main_test_rfh()->PrepareForCommit(); |
2852 main_test_rfh()->SendNavigate(3, entry_id, false, url4); | 2734 main_test_rfh()->SendNavigate(3, url4); |
2853 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2735 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2854 EXPECT_EQ(4, controller.GetEntryCount()); | 2736 EXPECT_EQ(4, controller.GetEntryCount()); |
2855 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2737 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
2856 EXPECT_FALSE(controller.GetPendingEntry()); | 2738 EXPECT_FALSE(controller.GetPendingEntry()); |
2857 | 2739 |
2858 // Remove an entry which is not the last committed one. | 2740 // Remove an entry which is not the last committed one. |
2859 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2741 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2860 EXPECT_EQ(3, controller.GetEntryCount()); | 2742 EXPECT_EQ(3, controller.GetEntryCount()); |
2861 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2743 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
2862 EXPECT_FALSE(controller.GetPendingEntry()); | 2744 EXPECT_FALSE(controller.GetPendingEntry()); |
2863 | 2745 |
2864 // Remove the 2 remaining entries. | 2746 // Remove the 2 remaining entries. |
2865 controller.RemoveEntryAtIndex(1); | 2747 controller.RemoveEntryAtIndex(1); |
2866 controller.RemoveEntryAtIndex(0); | 2748 controller.RemoveEntryAtIndex(0); |
2867 | 2749 |
2868 // This should leave us with only the last committed entry. | 2750 // This should leave us with only the last committed entry. |
2869 EXPECT_EQ(1, controller.GetEntryCount()); | 2751 EXPECT_EQ(1, controller.GetEntryCount()); |
2870 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2752 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
2871 } | 2753 } |
2872 | 2754 |
2873 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { | 2755 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { |
2874 NavigationControllerImpl& controller = controller_impl(); | 2756 NavigationControllerImpl& controller = controller_impl(); |
2875 const GURL url1("http://foo/1"); | 2757 const GURL url1("http://foo/1"); |
2876 const GURL url2("http://foo/2"); | 2758 const GURL url2("http://foo/2"); |
2877 const GURL url3("http://foo/3"); | 2759 const GURL url3("http://foo/3"); |
2878 const GURL default_url("http://foo/default"); | 2760 const GURL default_url("http://foo/default"); |
2879 | 2761 |
2880 controller.LoadURL( | 2762 controller.LoadURL( |
2881 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2763 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2882 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2883 main_test_rfh()->PrepareForCommit(); | 2764 main_test_rfh()->PrepareForCommit(); |
2884 main_test_rfh()->SendNavigate(0, entry_id, true, url1); | 2765 main_test_rfh()->SendNavigate(0, url1); |
2885 controller.LoadURL( | 2766 controller.LoadURL( |
2886 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2767 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2887 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2888 main_test_rfh()->PrepareForCommit(); | 2768 main_test_rfh()->PrepareForCommit(); |
2889 main_test_rfh()->SendNavigate(1, entry_id, true, url2); | 2769 main_test_rfh()->SendNavigate(1, url2); |
2890 controller.LoadURL( | 2770 controller.LoadURL( |
2891 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2771 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2892 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2893 main_test_rfh()->PrepareForCommit(); | 2772 main_test_rfh()->PrepareForCommit(); |
2894 main_test_rfh()->SendNavigate(2, entry_id, true, url3); | 2773 main_test_rfh()->SendNavigate(2, url3); |
2895 | 2774 |
2896 // Go back, but don't commit yet. Check that we can't delete the current | 2775 // Go back, but don't commit yet. Check that we can't delete the current |
2897 // and pending entries. | 2776 // and pending entries. |
2898 controller.GoBack(); | 2777 controller.GoBack(); |
2899 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2900 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); | 2778 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); |
2901 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); | 2779 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); |
2902 | 2780 |
2903 // Remove the first entry, while there is a pending entry. This is expected | 2781 // Remove the first entry, while there is a pending entry. This is expected |
2904 // to discard the pending entry. | 2782 // to discard the pending entry. |
2905 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2783 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2906 EXPECT_FALSE(controller.GetPendingEntry()); | 2784 EXPECT_FALSE(controller.GetPendingEntry()); |
2907 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2785 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2908 | 2786 |
2909 // We should update the last committed entry index. | 2787 // We should update the last committed entry index. |
2910 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2788 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
2911 | 2789 |
2912 // Now commit and ensure we land on the right entry. | 2790 // Now commit and ensure we land on the right entry. |
2913 main_test_rfh()->PrepareForCommit(); | 2791 main_test_rfh()->PrepareForCommit(); |
2914 main_test_rfh()->SendNavigate(1, entry_id, false, url2); | 2792 main_test_rfh()->SendNavigate(1, url2); |
2915 EXPECT_EQ(2, controller.GetEntryCount()); | 2793 EXPECT_EQ(2, controller.GetEntryCount()); |
2916 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2794 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
2917 EXPECT_FALSE(controller.GetPendingEntry()); | 2795 EXPECT_FALSE(controller.GetPendingEntry()); |
2918 } | 2796 } |
2919 | 2797 |
2920 // Tests the transient entry, making sure it goes away with all navigations. | 2798 // Tests the transient entry, making sure it goes away with all navigations. |
2921 TEST_F(NavigationControllerTest, TransientEntry) { | 2799 TEST_F(NavigationControllerTest, TransientEntry) { |
2922 NavigationControllerImpl& controller = controller_impl(); | 2800 NavigationControllerImpl& controller = controller_impl(); |
2923 TestNotificationTracker notifications; | 2801 TestNotificationTracker notifications; |
2924 RegisterForAllNavNotifications(¬ifications, &controller); | 2802 RegisterForAllNavNotifications(¬ifications, &controller); |
2925 | 2803 |
2926 const GURL url0("http://foo/0"); | 2804 const GURL url0("http://foo/0"); |
2927 const GURL url1("http://foo/1"); | 2805 const GURL url1("http://foo/1"); |
2928 const GURL url2("http://foo/2"); | 2806 const GURL url2("http://foo/2"); |
2929 const GURL url3("http://foo/3"); | 2807 const GURL url3("http://foo/3"); |
2930 const GURL url3_ref("http://foo/3#bar"); | 2808 const GURL url3_ref("http://foo/3#bar"); |
2931 const GURL url4("http://foo/4"); | 2809 const GURL url4("http://foo/4"); |
2932 const GURL transient_url("http://foo/transient"); | 2810 const GURL transient_url("http://foo/transient"); |
2933 | 2811 |
2934 controller.LoadURL( | 2812 controller.LoadURL( |
2935 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2813 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2936 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2937 main_test_rfh()->PrepareForCommit(); | 2814 main_test_rfh()->PrepareForCommit(); |
2938 main_test_rfh()->SendNavigate(0, entry_id, true, url0); | 2815 main_test_rfh()->SendNavigate(0, url0); |
2939 controller.LoadURL( | 2816 controller.LoadURL( |
2940 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2817 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2941 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2942 main_test_rfh()->PrepareForCommit(); | 2818 main_test_rfh()->PrepareForCommit(); |
2943 main_test_rfh()->SendNavigate(1, entry_id, true, url1); | 2819 main_test_rfh()->SendNavigate(1, url1); |
2944 | 2820 |
2945 notifications.Reset(); | 2821 notifications.Reset(); |
2946 | 2822 |
2947 // Adding a transient with no pending entry. | 2823 // Adding a transient with no pending entry. |
2948 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2824 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2949 transient_entry->SetURL(transient_url); | 2825 transient_entry->SetURL(transient_url); |
2950 controller.SetTransientEntry(transient_entry); | 2826 controller.SetTransientEntry(transient_entry); |
2951 | 2827 |
2952 // We should not have received any notifications. | 2828 // We should not have received any notifications. |
2953 EXPECT_EQ(0U, notifications.size()); | 2829 EXPECT_EQ(0U, notifications.size()); |
2954 | 2830 |
2955 // Check our state. | 2831 // Check our state. |
2956 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2832 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2957 EXPECT_EQ(controller.GetEntryCount(), 3); | 2833 EXPECT_EQ(controller.GetEntryCount(), 3); |
2958 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2834 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2959 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2835 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2960 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2836 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2961 EXPECT_FALSE(controller.GetPendingEntry()); | 2837 EXPECT_FALSE(controller.GetPendingEntry()); |
2962 EXPECT_TRUE(controller.CanGoBack()); | 2838 EXPECT_TRUE(controller.CanGoBack()); |
2963 EXPECT_FALSE(controller.CanGoForward()); | 2839 EXPECT_FALSE(controller.CanGoForward()); |
2964 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2840 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
2965 | 2841 |
2966 // Navigate. | 2842 // Navigate. |
2967 controller.LoadURL( | 2843 controller.LoadURL( |
2968 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2844 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2969 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2970 main_test_rfh()->PrepareForCommit(); | 2845 main_test_rfh()->PrepareForCommit(); |
2971 main_test_rfh()->SendNavigate(2, entry_id, true, url2); | 2846 main_test_rfh()->SendNavigate(2, url2); |
2972 | 2847 |
2973 // We should have navigated, transient entry should be gone. | 2848 // We should have navigated, transient entry should be gone. |
2974 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2849 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2975 EXPECT_EQ(controller.GetEntryCount(), 3); | 2850 EXPECT_EQ(controller.GetEntryCount(), 3); |
2976 | 2851 |
2977 // Add a transient again, then navigate with no pending entry this time. | 2852 // Add a transient again, then navigate with no pending entry this time. |
2978 transient_entry = new NavigationEntryImpl; | 2853 transient_entry = new NavigationEntryImpl; |
2979 transient_entry->SetURL(transient_url); | 2854 transient_entry->SetURL(transient_url); |
2980 controller.SetTransientEntry(transient_entry); | 2855 controller.SetTransientEntry(transient_entry); |
2981 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2856 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2982 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); | 2857 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); |
2983 main_test_rfh()->PrepareForCommit(); | 2858 main_test_rfh()->PrepareForCommit(); |
2984 main_test_rfh()->SendNavigate(3, 0, true, url3); | 2859 main_test_rfh()->SendNavigate(3, url3); |
2985 // Transient entry should be gone. | 2860 // Transient entry should be gone. |
2986 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2861 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2987 EXPECT_EQ(controller.GetEntryCount(), 4); | 2862 EXPECT_EQ(controller.GetEntryCount(), 4); |
2988 | 2863 |
2989 // Initiate a navigation, add a transient then commit navigation. | 2864 // Initiate a navigation, add a transient then commit navigation. |
2990 controller.LoadURL( | 2865 controller.LoadURL( |
2991 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2866 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2992 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
2993 transient_entry = new NavigationEntryImpl; | 2867 transient_entry = new NavigationEntryImpl; |
2994 transient_entry->SetURL(transient_url); | 2868 transient_entry->SetURL(transient_url); |
2995 controller.SetTransientEntry(transient_entry); | 2869 controller.SetTransientEntry(transient_entry); |
2996 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2870 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2997 main_test_rfh()->PrepareForCommit(); | 2871 main_test_rfh()->PrepareForCommit(); |
2998 main_test_rfh()->SendNavigate(4, entry_id, true, url4); | 2872 main_test_rfh()->SendNavigate(4, url4); |
2999 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2873 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
3000 EXPECT_EQ(controller.GetEntryCount(), 5); | 2874 EXPECT_EQ(controller.GetEntryCount(), 5); |
3001 | 2875 |
3002 // Add a transient and go back. This should simply remove the transient. | 2876 // Add a transient and go back. This should simply remove the transient. |
3003 transient_entry = new NavigationEntryImpl; | 2877 transient_entry = new NavigationEntryImpl; |
3004 transient_entry->SetURL(transient_url); | 2878 transient_entry->SetURL(transient_url); |
3005 controller.SetTransientEntry(transient_entry); | 2879 controller.SetTransientEntry(transient_entry); |
3006 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2880 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3007 EXPECT_TRUE(controller.CanGoBack()); | 2881 EXPECT_TRUE(controller.CanGoBack()); |
3008 EXPECT_FALSE(controller.CanGoForward()); | 2882 EXPECT_FALSE(controller.CanGoForward()); |
3009 controller.GoBack(); | 2883 controller.GoBack(); |
3010 // Transient entry should be gone. | 2884 // Transient entry should be gone. |
3011 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2885 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
3012 EXPECT_EQ(controller.GetEntryCount(), 5); | 2886 EXPECT_EQ(controller.GetEntryCount(), 5); |
3013 | 2887 |
3014 // Suppose the page requested a history navigation backward. | 2888 // Suppose the page requested a history navigation backward. |
3015 controller.GoToOffset(-1); | 2889 controller.GoToOffset(-1); |
3016 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3017 main_test_rfh()->PrepareForCommit(); | 2890 main_test_rfh()->PrepareForCommit(); |
3018 main_test_rfh()->SendNavigate(3, entry_id, false, url3); | 2891 main_test_rfh()->SendNavigate(3, url3); |
3019 | 2892 |
3020 // Add a transient and go to an entry before the current one. | 2893 // Add a transient and go to an entry before the current one. |
3021 transient_entry = new NavigationEntryImpl; | 2894 transient_entry = new NavigationEntryImpl; |
3022 transient_entry->SetURL(transient_url); | 2895 transient_entry->SetURL(transient_url); |
3023 controller.SetTransientEntry(transient_entry); | 2896 controller.SetTransientEntry(transient_entry); |
3024 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2897 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3025 controller.GoToIndex(1); | 2898 controller.GoToIndex(1); |
3026 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3027 // The navigation should have been initiated, transient entry should be gone. | 2899 // The navigation should have been initiated, transient entry should be gone. |
3028 EXPECT_FALSE(controller.GetTransientEntry()); | 2900 EXPECT_FALSE(controller.GetTransientEntry()); |
3029 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2901 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3030 // Visible entry does not update for history navigations until commit. | 2902 // Visible entry does not update for history navigations until commit. |
3031 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2903 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
3032 main_test_rfh()->PrepareForCommit(); | 2904 main_test_rfh()->PrepareForCommit(); |
3033 main_test_rfh()->SendNavigate(1, entry_id, false, url1); | 2905 main_test_rfh()->SendNavigate(1, url1); |
3034 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2906 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3035 | 2907 |
3036 // Add a transient and go to an entry after the current one. | 2908 // Add a transient and go to an entry after the current one. |
3037 transient_entry = new NavigationEntryImpl; | 2909 transient_entry = new NavigationEntryImpl; |
3038 transient_entry->SetURL(transient_url); | 2910 transient_entry->SetURL(transient_url); |
3039 controller.SetTransientEntry(transient_entry); | 2911 controller.SetTransientEntry(transient_entry); |
3040 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2912 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3041 controller.GoToIndex(3); | 2913 controller.GoToIndex(3); |
3042 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3043 // The navigation should have been initiated, transient entry should be gone. | 2914 // The navigation should have been initiated, transient entry should be gone. |
3044 // Because of the transient entry that is removed, going to index 3 makes us | 2915 // Because of the transient entry that is removed, going to index 3 makes us |
3045 // land on url2 (which is visible after the commit). | 2916 // land on url2 (which is visible after the commit). |
3046 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2917 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
3047 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2918 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3048 main_test_rfh()->PrepareForCommit(); | 2919 main_test_rfh()->PrepareForCommit(); |
3049 main_test_rfh()->SendNavigate(2, entry_id, false, url2); | 2920 main_test_rfh()->SendNavigate(2, url2); |
3050 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2921 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
3051 | 2922 |
3052 // Add a transient and go forward. | 2923 // Add a transient and go forward. |
3053 transient_entry = new NavigationEntryImpl; | 2924 transient_entry = new NavigationEntryImpl; |
3054 transient_entry->SetURL(transient_url); | 2925 transient_entry->SetURL(transient_url); |
3055 controller.SetTransientEntry(transient_entry); | 2926 controller.SetTransientEntry(transient_entry); |
3056 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2927 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3057 EXPECT_TRUE(controller.CanGoForward()); | 2928 EXPECT_TRUE(controller.CanGoForward()); |
3058 controller.GoForward(); | 2929 controller.GoForward(); |
3059 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3060 // We should have navigated, transient entry should be gone. | 2930 // We should have navigated, transient entry should be gone. |
3061 EXPECT_FALSE(controller.GetTransientEntry()); | 2931 EXPECT_FALSE(controller.GetTransientEntry()); |
3062 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 2932 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
3063 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2933 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
3064 main_test_rfh()->PrepareForCommit(); | 2934 main_test_rfh()->PrepareForCommit(); |
3065 main_test_rfh()->SendNavigate(3, entry_id, false, url3); | 2935 main_test_rfh()->SendNavigate(3, url3); |
3066 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2936 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
3067 | 2937 |
3068 // Add a transient and do an in-page navigation, replacing the current entry. | 2938 // Add a transient and do an in-page navigation, replacing the current entry. |
3069 transient_entry = new NavigationEntryImpl; | 2939 transient_entry = new NavigationEntryImpl; |
3070 transient_entry->SetURL(transient_url); | 2940 transient_entry->SetURL(transient_url); |
3071 controller.SetTransientEntry(transient_entry); | 2941 controller.SetTransientEntry(transient_entry); |
3072 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2942 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3073 | 2943 |
3074 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); | 2944 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); |
3075 main_test_rfh()->PrepareForCommit(); | 2945 main_test_rfh()->PrepareForCommit(); |
3076 main_test_rfh()->SendNavigate(3, 0, false, url3_ref); | 2946 main_test_rfh()->SendNavigate(3, url3_ref); |
3077 // Transient entry should be gone. | 2947 // Transient entry should be gone. |
3078 EXPECT_FALSE(controller.GetTransientEntry()); | 2948 EXPECT_FALSE(controller.GetTransientEntry()); |
3079 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 2949 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
3080 | 2950 |
3081 // Ensure the URLs are correct. | 2951 // Ensure the URLs are correct. |
3082 EXPECT_EQ(controller.GetEntryCount(), 5); | 2952 EXPECT_EQ(controller.GetEntryCount(), 5); |
3083 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2953 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
3084 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 2954 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
3085 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 2955 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
3086 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 2956 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
3087 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 2957 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
3088 } | 2958 } |
3089 | 2959 |
3090 // Test that Reload initiates a new navigation to a transient entry's URL. | 2960 // Test that Reload initiates a new navigation to a transient entry's URL. |
3091 TEST_F(NavigationControllerTest, ReloadTransient) { | 2961 TEST_F(NavigationControllerTest, ReloadTransient) { |
3092 NavigationControllerImpl& controller = controller_impl(); | 2962 NavigationControllerImpl& controller = controller_impl(); |
3093 const GURL url0("http://foo/0"); | 2963 const GURL url0("http://foo/0"); |
3094 const GURL url1("http://foo/1"); | 2964 const GURL url1("http://foo/1"); |
3095 const GURL transient_url("http://foo/transient"); | 2965 const GURL transient_url("http://foo/transient"); |
3096 | 2966 |
3097 // Load |url0|, and start a pending navigation to |url1|. | 2967 // Load |url0|, and start a pending navigation to |url1|. |
3098 controller.LoadURL( | 2968 controller.LoadURL( |
3099 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2969 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
3100 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3101 main_test_rfh()->PrepareForCommit(); | 2970 main_test_rfh()->PrepareForCommit(); |
3102 main_test_rfh()->SendNavigate(0, entry_id, true, url0); | 2971 main_test_rfh()->SendNavigate(0, url0); |
3103 controller.LoadURL( | 2972 controller.LoadURL( |
3104 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2973 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
3105 | 2974 |
3106 // A transient entry is added, interrupting the navigation. | 2975 // A transient entry is added, interrupting the navigation. |
3107 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2976 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
3108 transient_entry->SetURL(transient_url); | 2977 transient_entry->SetURL(transient_url); |
3109 controller.SetTransientEntry(transient_entry); | 2978 controller.SetTransientEntry(transient_entry); |
3110 EXPECT_TRUE(controller.GetTransientEntry()); | 2979 EXPECT_TRUE(controller.GetTransientEntry()); |
3111 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2980 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3112 | 2981 |
3113 // The page is reloaded, which should remove the pending entry for |url1| and | 2982 // The page is reloaded, which should remove the pending entry for |url1| and |
3114 // the transient entry for |transient_url|, and start a navigation to | 2983 // the transient entry for |transient_url|, and start a navigation to |
3115 // |transient_url|. | 2984 // |transient_url|. |
3116 controller.Reload(true); | 2985 controller.Reload(true); |
3117 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3118 EXPECT_FALSE(controller.GetTransientEntry()); | 2986 EXPECT_FALSE(controller.GetTransientEntry()); |
3119 EXPECT_TRUE(controller.GetPendingEntry()); | 2987 EXPECT_TRUE(controller.GetPendingEntry()); |
3120 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2988 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
3121 ASSERT_EQ(controller.GetEntryCount(), 1); | 2989 ASSERT_EQ(controller.GetEntryCount(), 1); |
3122 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2990 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
3123 | 2991 |
3124 // Load of |transient_url| completes. | 2992 // Load of |transient_url| completes. |
3125 main_test_rfh()->PrepareForCommit(); | 2993 main_test_rfh()->PrepareForCommit(); |
3126 main_test_rfh()->SendNavigate(1, entry_id, true, transient_url); | 2994 main_test_rfh()->SendNavigate(1, transient_url); |
3127 ASSERT_EQ(controller.GetEntryCount(), 2); | 2995 ASSERT_EQ(controller.GetEntryCount(), 2); |
3128 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2996 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
3129 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2997 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
3130 } | 2998 } |
3131 | 2999 |
3132 // Ensure that renderer initiated pending entries get replaced, so that we | 3000 // Ensure that renderer initiated pending entries get replaced, so that we |
3133 // don't show a stale virtual URL when a navigation commits. | 3001 // don't show a stale virtual URL when a navigation commits. |
3134 // See http://crbug.com/266922. | 3002 // See http://crbug.com/266922. |
3135 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 3003 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
3136 NavigationControllerImpl& controller = controller_impl(); | 3004 NavigationControllerImpl& controller = controller_impl(); |
(...skipping 18 matching lines...) Expand all Loading... |
3155 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3023 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3156 | 3024 |
3157 // If the user clicks another link, we should replace the pending entry. | 3025 // If the user clicks another link, we should replace the pending entry. |
3158 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3026 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
3159 main_test_rfh()->PrepareForCommit(); | 3027 main_test_rfh()->PrepareForCommit(); |
3160 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3028 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
3161 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 3029 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
3162 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 3030 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
3163 | 3031 |
3164 // Once it commits, the URL and virtual URL should reflect the actual page. | 3032 // Once it commits, the URL and virtual URL should reflect the actual page. |
3165 main_test_rfh()->SendNavigate(0, 0, true, url2); | 3033 main_test_rfh()->SendNavigate(0, url2); |
3166 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3034 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3167 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 3035 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
3168 | 3036 |
3169 // We should not replace the pending entry for an error URL. | 3037 // We should not replace the pending entry for an error URL. |
3170 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3038 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
3171 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3039 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3172 navigator->DidStartProvisionalLoad(main_test_rfh(), | 3040 navigator->DidStartProvisionalLoad(main_test_rfh(), |
3173 GURL(kUnreachableWebDataURL), false); | 3041 GURL(kUnreachableWebDataURL), false); |
3174 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3042 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3175 | 3043 |
3176 // We should remember if the pending entry will replace the current one. | 3044 // We should remember if the pending entry will replace the current one. |
3177 // http://crbug.com/308444. | 3045 // http://crbug.com/308444. |
3178 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); | 3046 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); |
3179 controller.GetPendingEntry()->set_should_replace_entry(true); | 3047 controller.GetPendingEntry()->set_should_replace_entry(true); |
3180 | 3048 |
3181 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); | 3049 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, false); |
3182 main_test_rfh()->PrepareForCommit(); | 3050 main_test_rfh()->PrepareForCommit(); |
3183 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); | 3051 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); |
3184 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); | 3052 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); |
3185 main_test_rfh()->SendNavigate(0, 0, false, url2); | 3053 main_test_rfh()->SendNavigate(0, url2); |
3186 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 3054 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
3187 } | 3055 } |
3188 | 3056 |
3189 // Tests that the URLs for renderer-initiated navigations are not displayed to | 3057 // Tests that the URLs for renderer-initiated navigations are not displayed to |
3190 // the user until the navigation commits, to prevent URL spoof attacks. | 3058 // the user until the navigation commits, to prevent URL spoof attacks. |
3191 // See http://crbug.com/99016. | 3059 // See http://crbug.com/99016. |
3192 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 3060 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
3193 NavigationControllerImpl& controller = controller_impl(); | 3061 NavigationControllerImpl& controller = controller_impl(); |
3194 TestNotificationTracker notifications; | 3062 TestNotificationTracker notifications; |
3195 RegisterForAllNavNotifications(¬ifications, &controller); | 3063 RegisterForAllNavNotifications(¬ifications, &controller); |
3196 | 3064 |
3197 const GURL url0("http://foo/0"); | 3065 const GURL url0("http://foo/0"); |
3198 const GURL url1("http://foo/1"); | 3066 const GURL url1("http://foo/1"); |
3199 | 3067 |
3200 // For typed navigations (browser-initiated), both pending and visible entries | 3068 // For typed navigations (browser-initiated), both pending and visible entries |
3201 // should update before commit. | 3069 // should update before commit. |
3202 controller.LoadURL( | 3070 controller.LoadURL( |
3203 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3071 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
3204 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3205 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 3072 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
3206 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3073 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
3207 main_test_rfh()->PrepareForCommit(); | 3074 main_test_rfh()->PrepareForCommit(); |
3208 main_test_rfh()->SendNavigate(0, entry_id, true, url0); | 3075 main_test_rfh()->SendNavigate(0, url0); |
3209 | 3076 |
3210 // For link clicks (renderer-initiated navigations), the pending entry should | 3077 // For link clicks (renderer-initiated navigations), the pending entry should |
3211 // update before commit but the visible should not. | 3078 // update before commit but the visible should not. |
3212 NavigationController::LoadURLParams load_url_params(url1); | 3079 NavigationController::LoadURLParams load_url_params(url1); |
3213 load_url_params.is_renderer_initiated = true; | 3080 load_url_params.is_renderer_initiated = true; |
3214 controller.LoadURLWithParams(load_url_params); | 3081 controller.LoadURLWithParams(load_url_params); |
3215 entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3216 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3082 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
3217 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3083 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
3218 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3084 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3219 | 3085 |
3220 // After commit, both visible should be updated, there should be no pending | 3086 // After commit, both visible should be updated, there should be no pending |
3221 // entry, and we should no longer treat the entry as renderer-initiated. | 3087 // entry, and we should no longer treat the entry as renderer-initiated. |
3222 main_test_rfh()->PrepareForCommit(); | 3088 main_test_rfh()->PrepareForCommit(); |
3223 main_test_rfh()->SendNavigate(1, entry_id, true, url1); | 3089 main_test_rfh()->SendNavigate(1, url1); |
3224 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3090 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3225 EXPECT_FALSE(controller.GetPendingEntry()); | 3091 EXPECT_FALSE(controller.GetPendingEntry()); |
3226 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); | 3092 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); |
3227 | 3093 |
3228 notifications.Reset(); | 3094 notifications.Reset(); |
3229 } | 3095 } |
3230 | 3096 |
3231 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3097 // Tests that the URLs for renderer-initiated navigations in new tabs are |
3232 // displayed to the user before commit, as long as the initial about:blank | 3098 // displayed to the user before commit, as long as the initial about:blank |
3233 // page has not been modified. If so, we must revert to showing about:blank. | 3099 // 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... |
3371 const GURL url1("http://foo/eh"); | 3237 const GURL url1("http://foo/eh"); |
3372 const GURL url2("http://foo/bee"); | 3238 const GURL url2("http://foo/bee"); |
3373 | 3239 |
3374 // For renderer-initiated navigations in new tabs (with no committed entries), | 3240 // For renderer-initiated navigations in new tabs (with no committed entries), |
3375 // we show the pending entry's URL as long as the about:blank page is not | 3241 // we show the pending entry's URL as long as the about:blank page is not |
3376 // modified. | 3242 // modified. |
3377 NavigationController::LoadURLParams load_url_params(url1); | 3243 NavigationController::LoadURLParams load_url_params(url1); |
3378 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3244 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3379 load_url_params.is_renderer_initiated = true; | 3245 load_url_params.is_renderer_initiated = true; |
3380 controller.LoadURLWithParams(load_url_params); | 3246 controller.LoadURLWithParams(load_url_params); |
3381 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
3382 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3247 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3383 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3248 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
3384 EXPECT_TRUE(controller.IsInitialNavigation()); | 3249 EXPECT_TRUE(controller.IsInitialNavigation()); |
3385 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3250 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3386 | 3251 |
3387 // Simulate a commit and then starting a new pending navigation. | 3252 // Simulate a commit and then starting a new pending navigation. |
3388 main_test_rfh()->PrepareForCommit(); | 3253 main_test_rfh()->PrepareForCommit(); |
3389 main_test_rfh()->SendNavigate(0, entry_id, true, url1); | 3254 main_test_rfh()->SendNavigate(0, url1); |
3390 NavigationController::LoadURLParams load_url2_params(url2); | 3255 NavigationController::LoadURLParams load_url2_params(url2); |
3391 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; | 3256 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; |
3392 load_url2_params.is_renderer_initiated = true; | 3257 load_url2_params.is_renderer_initiated = true; |
3393 controller.LoadURLWithParams(load_url2_params); | 3258 controller.LoadURLWithParams(load_url2_params); |
3394 | 3259 |
3395 // We should not consider this an initial navigation, and thus should | 3260 // We should not consider this an initial navigation, and thus should |
3396 // not show the pending URL. | 3261 // not show the pending URL. |
3397 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); | 3262 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); |
3398 EXPECT_FALSE(controller.IsInitialNavigation()); | 3263 EXPECT_FALSE(controller.IsInitialNavigation()); |
3399 EXPECT_TRUE(controller.GetVisibleEntry()); | 3264 EXPECT_TRUE(controller.GetVisibleEntry()); |
3400 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3265 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
3401 | 3266 |
3402 notifications.Reset(); | 3267 notifications.Reset(); |
3403 } | 3268 } |
3404 | 3269 |
3405 // Tests that IsInPageNavigation returns appropriate results. Prevents | 3270 // Tests that IsInPageNavigation returns appropriate results. Prevents |
3406 // regression for bug 1126349. | 3271 // regression for bug 1126349. |
3407 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 3272 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
3408 NavigationControllerImpl& controller = controller_impl(); | 3273 NavigationControllerImpl& controller = controller_impl(); |
3409 const GURL url("http://www.google.com/home.html"); | 3274 const GURL url("http://www.google.com/home.html"); |
3410 | 3275 |
3411 // If the renderer claims it performed an in-page navigation from | 3276 // If the renderer claims it performed an in-page navigation from |
3412 // about:blank, trust the renderer. | 3277 // about:blank, trust the renderer. |
3413 // This can happen when an iframe is created and populated via | 3278 // This can happen when an iframe is created and populated via |
3414 // document.write(), then tries to perform a fragment navigation. | 3279 // document.write(), then tries to perform a fragment navigation. |
3415 // TODO(japhet): We should only trust the renderer if the about:blank | 3280 // TODO(japhet): We should only trust the renderer if the about:blank |
3416 // was the first document in the given frame, but we don't have enough | 3281 // was the first document in the given frame, but we don't have enough |
3417 // information to identify that case currently. | 3282 // information to identify that case currently. |
3418 const GURL blank_url(url::kAboutBlankURL); | 3283 const GURL blank_url(url::kAboutBlankURL); |
3419 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, blank_url); | 3284 main_test_rfh()->NavigateAndCommitRendererInitiated(0, blank_url); |
3420 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 3285 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
3421 main_test_rfh())); | 3286 main_test_rfh())); |
3422 | 3287 |
3423 // Navigate to URL with no refs. | 3288 // Navigate to URL with no refs. |
3424 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); | 3289 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
3425 | 3290 |
3426 // Reloading the page is not an in-page navigation. | 3291 // Reloading the page is not an in-page navigation. |
3427 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, main_test_rfh())); | 3292 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
| 3293 main_test_rfh())); |
3428 const GURL other_url("http://www.google.com/add.html"); | 3294 const GURL other_url("http://www.google.com/add.html"); |
3429 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3295 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3430 main_test_rfh())); | 3296 main_test_rfh())); |
3431 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 3297 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
3432 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 3298 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
3433 main_test_rfh())); | 3299 main_test_rfh())); |
3434 | 3300 |
3435 // Navigate to URL with refs. | 3301 // Navigate to URL with refs. |
3436 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url_with_ref); | 3302 main_test_rfh()->NavigateAndCommitRendererInitiated(1, url_with_ref); |
3437 | 3303 |
3438 // Reloading the page is not an in-page navigation. | 3304 // Reloading the page is not an in-page navigation. |
3439 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, | 3305 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, |
3440 main_test_rfh())); | 3306 main_test_rfh())); |
3441 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, | 3307 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, |
3442 main_test_rfh())); | 3308 main_test_rfh())); |
3443 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, | 3309 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, |
3444 main_test_rfh())); | 3310 main_test_rfh())); |
3445 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 3311 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
3446 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, | 3312 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, |
(...skipping 17 matching lines...) Expand all Loading... |
3464 // Test allow_universal_access_from_file_urls flag. | 3330 // Test allow_universal_access_from_file_urls flag. |
3465 const GURL different_origin_url("http://www.example.com"); | 3331 const GURL different_origin_url("http://www.example.com"); |
3466 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); | 3332 MockRenderProcessHost* rph = main_test_rfh()->GetProcess(); |
3467 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); | 3333 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); |
3468 prefs.allow_universal_access_from_file_urls = true; | 3334 prefs.allow_universal_access_from_file_urls = true; |
3469 test_rvh()->UpdateWebkitPreferences(prefs); | 3335 test_rvh()->UpdateWebkitPreferences(prefs); |
3470 prefs = test_rvh()->GetWebkitPreferences(); | 3336 prefs = test_rvh()->GetWebkitPreferences(); |
3471 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); | 3337 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); |
3472 // Allow in page navigation if existing URL is file scheme. | 3338 // Allow in page navigation if existing URL is file scheme. |
3473 const GURL file_url("file:///foo/index.html"); | 3339 const GURL file_url("file:///foo/index.html"); |
3474 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, file_url); | 3340 main_test_rfh()->NavigateAndCommitRendererInitiated(0, file_url); |
3475 EXPECT_EQ(0, rph->bad_msg_count()); | 3341 EXPECT_EQ(0, rph->bad_msg_count()); |
3476 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, | 3342 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, |
3477 main_test_rfh())); | 3343 main_test_rfh())); |
3478 EXPECT_EQ(0, rph->bad_msg_count()); | 3344 EXPECT_EQ(0, rph->bad_msg_count()); |
3479 // Don't honor allow_universal_access_from_file_urls if existing URL is | 3345 // Don't honor allow_universal_access_from_file_urls if existing URL is |
3480 // not file scheme. | 3346 // not file scheme. |
3481 main_test_rfh()->NavigateAndCommitRendererInitiated(0, false, url); | 3347 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
3482 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3348 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3483 main_test_rfh())); | 3349 main_test_rfh())); |
3484 EXPECT_EQ(1, rph->bad_msg_count()); | 3350 EXPECT_EQ(1, rph->bad_msg_count()); |
3485 | 3351 |
3486 // Remove allow_universal_access_from_file_urls flag. | 3352 // Remove allow_universal_access_from_file_urls flag. |
3487 prefs.allow_universal_access_from_file_urls = false; | 3353 prefs.allow_universal_access_from_file_urls = false; |
3488 test_rvh()->UpdateWebkitPreferences(prefs); | 3354 test_rvh()->UpdateWebkitPreferences(prefs); |
3489 prefs = test_rvh()->GetWebkitPreferences(); | 3355 prefs = test_rvh()->GetWebkitPreferences(); |
3490 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); | 3356 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); |
3491 | 3357 |
3492 // Don't believe the renderer if it claims a cross-origin navigation is | 3358 // Don't believe the renderer if it claims a cross-origin navigation is |
3493 // in-page. | 3359 // in-page. |
3494 EXPECT_EQ(1, rph->bad_msg_count()); | 3360 EXPECT_EQ(1, rph->bad_msg_count()); |
3495 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, | 3361 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, |
3496 main_test_rfh())); | 3362 main_test_rfh())); |
3497 EXPECT_EQ(2, rph->bad_msg_count()); | 3363 EXPECT_EQ(2, rph->bad_msg_count()); |
3498 } | 3364 } |
3499 | 3365 |
3500 // Some pages can have subframes with the same base URL (minus the reference) as | 3366 // Some pages can have subframes with the same base URL (minus the reference) as |
3501 // the main page. Even though this is hard, it can happen, and we don't want | 3367 // the main page. Even though this is hard, it can happen, and we don't want |
3502 // these subframe navigations to affect the toplevel document. They should | 3368 // these subframe navigations to affect the toplevel document. They should |
3503 // instead be ignored. http://crbug.com/5585 | 3369 // instead be ignored. http://crbug.com/5585 |
3504 TEST_F(NavigationControllerTest, SameSubframe) { | 3370 TEST_F(NavigationControllerTest, SameSubframe) { |
3505 NavigationControllerImpl& controller = controller_impl(); | 3371 NavigationControllerImpl& controller = controller_impl(); |
3506 // Navigate the main frame. | 3372 // Navigate the main frame. |
3507 const GURL url("http://www.google.com/"); | 3373 const GURL url("http://www.google.com/"); |
3508 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); | 3374 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url); |
3509 | 3375 |
3510 // We should be at the first navigation entry. | 3376 // We should be at the first navigation entry. |
3511 EXPECT_EQ(controller.GetEntryCount(), 1); | 3377 EXPECT_EQ(controller.GetEntryCount(), 1); |
3512 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 3378 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
3513 | 3379 |
3514 // Navigate a subframe that would normally count as in-page. | 3380 // Navigate a subframe that would normally count as in-page. |
3515 const GURL subframe("http://www.google.com/#"); | 3381 const GURL subframe("http://www.google.com/#"); |
3516 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3382 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
3517 params.page_id = 0; | 3383 params.page_id = 0; |
3518 params.nav_entry_id = 0; | |
3519 params.did_create_new_entry = false; | |
3520 params.url = subframe; | 3384 params.url = subframe; |
3521 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3385 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
3522 params.should_update_history = false; | 3386 params.should_update_history = false; |
3523 params.gesture = NavigationGestureAuto; | 3387 params.gesture = NavigationGestureAuto; |
3524 params.is_post = false; | 3388 params.is_post = false; |
3525 params.page_state = PageState::CreateFromURL(subframe); | 3389 params.page_state = PageState::CreateFromURL(subframe); |
3526 LoadCommittedDetails details; | 3390 LoadCommittedDetails details; |
3527 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, | 3391 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
3528 &details)); | 3392 &details)); |
3529 | 3393 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3655 // Now start a pending load to a totally different page, but don't commit it. | 3519 // Now start a pending load to a totally different page, but don't commit it. |
3656 const GURL url2("http://bar/"); | 3520 const GURL url2("http://bar/"); |
3657 controller.LoadURL( | 3521 controller.LoadURL( |
3658 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 3522 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
3659 | 3523 |
3660 // Send a subframe update from the first page, as if one had just | 3524 // Send a subframe update from the first page, as if one had just |
3661 // automatically loaded. Auto subframes don't increment the page ID. | 3525 // automatically loaded. Auto subframes don't increment the page ID. |
3662 const GURL url1_sub("http://foo/subframe"); | 3526 const GURL url1_sub("http://foo/subframe"); |
3663 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 3527 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
3664 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); | 3528 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); |
3665 params.nav_entry_id = 0; | |
3666 params.did_create_new_entry = false; | |
3667 params.url = url1_sub; | 3529 params.url = url1_sub; |
3668 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; | 3530 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; |
3669 params.should_update_history = false; | 3531 params.should_update_history = false; |
3670 params.gesture = NavigationGestureAuto; | 3532 params.gesture = NavigationGestureAuto; |
3671 params.is_post = false; | 3533 params.is_post = false; |
3672 params.page_state = PageState::CreateFromURL(url1_sub); | 3534 params.page_state = PageState::CreateFromURL(url1_sub); |
3673 LoadCommittedDetails details; | 3535 LoadCommittedDetails details; |
3674 | 3536 |
3675 // This should return false meaning that nothing was actually updated. | 3537 // This should return false meaning that nothing was actually updated. |
3676 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, | 3538 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3954 | 3816 |
3955 NavigateAndCommit(url1); | 3817 NavigateAndCommit(url1); |
3956 | 3818 |
3957 scoped_ptr<TestWebContents> other_contents( | 3819 scoped_ptr<TestWebContents> other_contents( |
3958 static_cast<TestWebContents*>(CreateTestWebContents())); | 3820 static_cast<TestWebContents*>(CreateTestWebContents())); |
3959 NavigationControllerImpl& other_controller = other_contents->GetController(); | 3821 NavigationControllerImpl& other_controller = other_contents->GetController(); |
3960 other_contents->NavigateAndCommit(url2a); | 3822 other_contents->NavigateAndCommit(url2a); |
3961 // Simulate a client redirect, which has the same page ID as entry 2a. | 3823 // Simulate a client redirect, which has the same page ID as entry 2a. |
3962 other_controller.LoadURL( | 3824 other_controller.LoadURL( |
3963 url2b, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 3825 url2b, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
3964 NavigationEntry* entry = other_controller.GetPendingEntry(); | 3826 other_controller.GetPendingEntry()->SetPageID( |
3965 entry->SetPageID(other_controller.GetLastCommittedEntry()->GetPageID()); | 3827 other_controller.GetLastCommittedEntry()->GetPageID()); |
3966 | 3828 |
3967 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); | 3829 other_contents->ExpectSetHistoryOffsetAndLength(1, 2); |
3968 other_controller.CopyStateFromAndPrune(&controller, false); | 3830 other_controller.CopyStateFromAndPrune(&controller, false); |
3969 | 3831 |
3970 // other_controller should now contain url1, url2a, and a pending entry | 3832 // other_controller should now contain url1, url2a, and a pending entry |
3971 // for url2b. | 3833 // for url2b. |
3972 | 3834 |
3973 ASSERT_EQ(2, other_controller.GetEntryCount()); | 3835 ASSERT_EQ(2, other_controller.GetEntryCount()); |
3974 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); | 3836 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); |
3975 | 3837 |
3976 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); | 3838 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); |
3977 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); | 3839 EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL()); |
3978 | 3840 |
3979 // And there should be a pending entry for url4. | 3841 // And there should be a pending entry for url4. |
3980 ASSERT_TRUE(other_controller.GetPendingEntry()); | 3842 ASSERT_TRUE(other_controller.GetPendingEntry()); |
3981 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); | 3843 EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL()); |
3982 | 3844 |
3983 // Let the pending entry commit. | 3845 // Let the pending entry commit. |
3984 other_contents->TestDidNavigate(other_contents->GetMainFrame(), | 3846 other_contents->CommitPendingNavigation(); |
3985 entry->GetPageID(), 0, false, url2b, | |
3986 ui::PAGE_TRANSITION_LINK); | |
3987 | 3847 |
3988 // The max page ID map should be copied over and updated with the max page ID | 3848 // The max page ID map should be copied over and updated with the max page ID |
3989 // from the current tab. | 3849 // from the current tab. |
3990 SiteInstance* instance1 = | 3850 SiteInstance* instance1 = |
3991 other_controller.GetEntryAtIndex(1)->site_instance(); | 3851 other_controller.GetEntryAtIndex(1)->site_instance(); |
3992 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); | 3852 EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); |
3993 } | 3853 } |
3994 | 3854 |
3995 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the | 3855 // Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the |
3996 // source, and 1 entry in the target. The back pending entry should be ignored. | 3856 // 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... |
4337 const GURL url1("http://foo/1"); | 4197 const GURL url1("http://foo/1"); |
4338 const GURL url2("http://foo/2"); | 4198 const GURL url2("http://foo/2"); |
4339 const GURL url3("http://foo/3"); | 4199 const GURL url3("http://foo/3"); |
4340 | 4200 |
4341 NavigateAndCommit(url1); | 4201 NavigateAndCommit(url1); |
4342 NavigateAndCommit(url2); | 4202 NavigateAndCommit(url2); |
4343 | 4203 |
4344 // Create a pending entry that is not in the entry list. | 4204 // Create a pending entry that is not in the entry list. |
4345 controller.LoadURL( | 4205 controller.LoadURL( |
4346 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4206 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
4347 int entry_id = controller.GetPendingEntry()->GetUniqueID(); | |
4348 EXPECT_TRUE(controller.GetPendingEntry()); | 4207 EXPECT_TRUE(controller.GetPendingEntry()); |
4349 EXPECT_EQ(2, controller.GetEntryCount()); | 4208 EXPECT_EQ(2, controller.GetEntryCount()); |
4350 | 4209 |
4351 contents()->ExpectSetHistoryOffsetAndLength(0, 1); | 4210 contents()->ExpectSetHistoryOffsetAndLength(0, 1); |
4352 controller.PruneAllButLastCommitted(); | 4211 controller.PruneAllButLastCommitted(); |
4353 | 4212 |
4354 // We should only have the last committed and pending entries at this point, | 4213 // We should only have the last committed and pending entries at this point, |
4355 // and the pending entry should still not be in the entry list. | 4214 // and the pending entry should still not be in the entry list. |
4356 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4215 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4357 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 4216 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
4358 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4217 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4359 EXPECT_TRUE(controller.GetPendingEntry()); | 4218 EXPECT_TRUE(controller.GetPendingEntry()); |
4360 EXPECT_EQ(1, controller.GetEntryCount()); | 4219 EXPECT_EQ(1, controller.GetEntryCount()); |
4361 | 4220 |
4362 // Try to commit the pending entry. | 4221 // Try to commit the pending entry. |
4363 main_test_rfh()->PrepareForCommit(); | 4222 main_test_rfh()->PrepareForCommit(); |
4364 main_test_rfh()->SendNavigate(2, entry_id, true, url3); | 4223 main_test_rfh()->SendNavigate(2, url3); |
4365 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4224 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4366 EXPECT_FALSE(controller.GetPendingEntry()); | 4225 EXPECT_FALSE(controller.GetPendingEntry()); |
4367 EXPECT_EQ(2, controller.GetEntryCount()); | 4226 EXPECT_EQ(2, controller.GetEntryCount()); |
4368 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 4227 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
4369 } | 4228 } |
4370 | 4229 |
4371 // Test to ensure that when we do a history navigation back to the current | 4230 // Test to ensure that when we do a history navigation back to the current |
4372 // committed page (e.g., going forward to a slow-loading page, then pressing | 4231 // committed page (e.g., going forward to a slow-loading page, then pressing |
4373 // the back button), we just stop the navigation to prevent the throbber from | 4232 // the back button), we just stop the navigation to prevent the throbber from |
4374 // running continuously. Otherwise, the RenderViewHost forces the throbber to | 4233 // running continuously. Otherwise, the RenderViewHost forces the throbber to |
(...skipping 21 matching lines...) Expand all Loading... |
4396 TEST_F(NavigationControllerTest, IsInitialNavigation) { | 4255 TEST_F(NavigationControllerTest, IsInitialNavigation) { |
4397 NavigationControllerImpl& controller = controller_impl(); | 4256 NavigationControllerImpl& controller = controller_impl(); |
4398 TestNotificationTracker notifications; | 4257 TestNotificationTracker notifications; |
4399 RegisterForAllNavNotifications(¬ifications, &controller); | 4258 RegisterForAllNavNotifications(¬ifications, &controller); |
4400 | 4259 |
4401 // Initial state. | 4260 // Initial state. |
4402 EXPECT_TRUE(controller.IsInitialNavigation()); | 4261 EXPECT_TRUE(controller.IsInitialNavigation()); |
4403 | 4262 |
4404 // After commit, it stays false. | 4263 // After commit, it stays false. |
4405 const GURL url1("http://foo1"); | 4264 const GURL url1("http://foo1"); |
4406 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); | 4265 main_test_rfh()->NavigateAndCommitRendererInitiated(0, url1); |
4407 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4266 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4408 navigation_entry_committed_counter_ = 0; | 4267 navigation_entry_committed_counter_ = 0; |
4409 EXPECT_FALSE(controller.IsInitialNavigation()); | 4268 EXPECT_FALSE(controller.IsInitialNavigation()); |
4410 | 4269 |
4411 // After starting a new navigation, it stays false. | 4270 // After starting a new navigation, it stays false. |
4412 const GURL url2("http://foo2"); | 4271 const GURL url2("http://foo2"); |
4413 controller.LoadURL( | 4272 controller.LoadURL( |
4414 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4273 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
4415 } | 4274 } |
4416 | 4275 |
4417 // Check that the favicon is not reused across a client redirect. | 4276 // Check that the favicon is not reused across a client redirect. |
4418 // (crbug.com/28515) | 4277 // (crbug.com/28515) |
4419 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 4278 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
4420 const GURL kPageWithFavicon("http://withfavicon.html"); | 4279 const GURL kPageWithFavicon("http://withfavicon.html"); |
4421 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 4280 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
4422 const GURL kIconURL("http://withfavicon.ico"); | 4281 const GURL kIconURL("http://withfavicon.ico"); |
4423 const gfx::Image kDefaultFavicon = FaviconStatus().image; | 4282 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
4424 | 4283 |
4425 NavigationControllerImpl& controller = controller_impl(); | 4284 NavigationControllerImpl& controller = controller_impl(); |
4426 TestNotificationTracker notifications; | 4285 TestNotificationTracker notifications; |
4427 RegisterForAllNavNotifications(¬ifications, &controller); | 4286 RegisterForAllNavNotifications(¬ifications, &controller); |
4428 | 4287 |
4429 main_test_rfh()->NavigateAndCommitRendererInitiated( | 4288 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kPageWithFavicon); |
4430 0, true, kPageWithFavicon); | |
4431 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4289 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4432 navigation_entry_committed_counter_ = 0; | 4290 navigation_entry_committed_counter_ = 0; |
4433 | 4291 |
4434 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4292 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
4435 EXPECT_TRUE(entry); | 4293 EXPECT_TRUE(entry); |
4436 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 4294 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
4437 | 4295 |
4438 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 4296 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
4439 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4297 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
4440 favicon_status.image = CreateImage(SK_ColorWHITE); | 4298 favicon_status.image = CreateImage(SK_ColorWHITE); |
4441 favicon_status.url = kIconURL; | 4299 favicon_status.url = kIconURL; |
4442 favicon_status.valid = true; | 4300 favicon_status.valid = true; |
4443 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4301 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
4444 | 4302 |
4445 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, | 4303 main_test_rfh()->SendRendererInitiatedNavigationRequest(kPageWithoutFavicon, |
4446 false); | 4304 false); |
4447 main_test_rfh()->PrepareForCommit(); | 4305 main_test_rfh()->PrepareForCommit(); |
4448 main_test_rfh()->SendNavigateWithTransition( | 4306 main_test_rfh()->SendNavigateWithTransition( |
4449 0, // same page ID. | 4307 0, // same page ID. |
4450 0, // nav_entry_id | 4308 kPageWithoutFavicon, |
4451 false, // no new entry | 4309 ui::PAGE_TRANSITION_CLIENT_REDIRECT); |
4452 kPageWithoutFavicon, ui::PAGE_TRANSITION_CLIENT_REDIRECT); | |
4453 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4310 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4454 navigation_entry_committed_counter_ = 0; | 4311 navigation_entry_committed_counter_ = 0; |
4455 | 4312 |
4456 entry = controller.GetLastCommittedEntry(); | 4313 entry = controller.GetLastCommittedEntry(); |
4457 EXPECT_TRUE(entry); | 4314 EXPECT_TRUE(entry); |
4458 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 4315 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
4459 | 4316 |
4460 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 4317 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
4461 } | 4318 } |
4462 | 4319 |
4463 // Check that the favicon is not cleared for NavigationEntries which were | 4320 // Check that the favicon is not cleared for NavigationEntries which were |
4464 // previously navigated to. | 4321 // previously navigated to. |
4465 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { | 4322 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
4466 const GURL kUrl1("http://www.a.com/1"); | 4323 const GURL kUrl1("http://www.a.com/1"); |
4467 const GURL kUrl2("http://www.a.com/2"); | 4324 const GURL kUrl2("http://www.a.com/2"); |
4468 const GURL kIconURL("http://www.a.com/1/favicon.ico"); | 4325 const GURL kIconURL("http://www.a.com/1/favicon.ico"); |
4469 | 4326 |
4470 NavigationControllerImpl& controller = controller_impl(); | 4327 NavigationControllerImpl& controller = controller_impl(); |
4471 TestNotificationTracker notifications; | 4328 TestNotificationTracker notifications; |
4472 RegisterForAllNavNotifications(¬ifications, &controller); | 4329 RegisterForAllNavNotifications(¬ifications, &controller); |
4473 | 4330 |
4474 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, kUrl1); | 4331 main_test_rfh()->NavigateAndCommitRendererInitiated(0, kUrl1); |
4475 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4332 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4476 navigation_entry_committed_counter_ = 0; | 4333 navigation_entry_committed_counter_ = 0; |
4477 | 4334 |
4478 // Simulate Chromium having set the favicon for |kUrl1|. | 4335 // Simulate Chromium having set the favicon for |kUrl1|. |
4479 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); | 4336 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); |
4480 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 4337 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
4481 EXPECT_TRUE(entry); | 4338 EXPECT_TRUE(entry); |
4482 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 4339 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
4483 favicon_status.image = favicon_image; | 4340 favicon_status.image = favicon_image; |
4484 favicon_status.url = kIconURL; | 4341 favicon_status.url = kIconURL; |
4485 favicon_status.valid = true; | 4342 favicon_status.valid = true; |
4486 | 4343 |
4487 // Navigate to another page and go back to the original page. | 4344 // Navigate to another page and go back to the original page. |
4488 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, kUrl2); | 4345 main_test_rfh()->NavigateAndCommitRendererInitiated(1, kUrl2); |
4489 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4346 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4490 navigation_entry_committed_counter_ = 0; | 4347 navigation_entry_committed_counter_ = 0; |
4491 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); | 4348 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, false); |
4492 main_test_rfh()->PrepareForCommit(); | 4349 main_test_rfh()->PrepareForCommit(); |
4493 main_test_rfh()->SendNavigateWithTransition( | 4350 main_test_rfh()->SendNavigateWithTransition( |
4494 0, controller.GetEntryAtIndex(0)->GetUniqueID(), false, kUrl1, | 4351 0, |
| 4352 kUrl1, |
4495 ui::PAGE_TRANSITION_FORWARD_BACK); | 4353 ui::PAGE_TRANSITION_FORWARD_BACK); |
4496 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 4354 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
4497 navigation_entry_committed_counter_ = 0; | 4355 navigation_entry_committed_counter_ = 0; |
4498 | 4356 |
4499 // Verify that the favicon for the page at |kUrl1| was not cleared. | 4357 // Verify that the favicon for the page at |kUrl1| was not cleared. |
4500 entry = controller.GetEntryAtIndex(0); | 4358 entry = controller.GetEntryAtIndex(0); |
4501 EXPECT_TRUE(entry); | 4359 EXPECT_TRUE(entry); |
4502 EXPECT_EQ(kUrl1, entry->GetURL()); | 4360 EXPECT_EQ(kUrl1, entry->GetURL()); |
4503 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); | 4361 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); |
4504 } | 4362 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4585 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); | 4443 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); |
4586 for (int i = 0; i < controller.GetEntryCount(); ++i) { | 4444 for (int i = 0; i < controller.GetEntryCount(); ++i) { |
4587 entry = controller.GetEntryAtIndex(i); | 4445 entry = controller.GetEntryAtIndex(i); |
4588 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i | 4446 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i |
4589 << " not cleared"; | 4447 << " not cleared"; |
4590 } | 4448 } |
4591 } | 4449 } |
4592 | 4450 |
4593 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { | 4451 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { |
4594 // Navigate. | 4452 // Navigate. |
4595 main_test_rfh()->NavigateAndCommitRendererInitiated( | 4453 main_test_rfh()->NavigateAndCommitRendererInitiated(1, GURL("http://foo")); |
4596 1, true, GURL("http://foo")); | |
4597 | 4454 |
4598 // Set title and favicon. | 4455 // Set title and favicon. |
4599 base::string16 title(base::ASCIIToUTF16("Title")); | 4456 base::string16 title(base::ASCIIToUTF16("Title")); |
4600 FaviconStatus favicon; | 4457 FaviconStatus favicon; |
4601 favicon.valid = true; | 4458 favicon.valid = true; |
4602 favicon.url = GURL("http://foo/favicon.ico"); | 4459 favicon.url = GURL("http://foo/favicon.ico"); |
4603 controller().GetLastCommittedEntry()->SetTitle(title); | 4460 controller().GetLastCommittedEntry()->SetTitle(title); |
4604 controller().GetLastCommittedEntry()->GetFavicon() = favicon; | 4461 controller().GetLastCommittedEntry()->GetFavicon() = favicon; |
4605 | 4462 |
4606 // history.pushState() is called. | 4463 // history.pushState() is called. |
4607 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4464 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4608 GURL kUrl2("http://foo#foo"); | 4465 GURL kUrl2("http://foo#foo"); |
4609 params.page_id = 2; | 4466 params.page_id = 2; |
4610 params.nav_entry_id = 0; | |
4611 params.did_create_new_entry = true; | |
4612 params.url = kUrl2; | 4467 params.url = kUrl2; |
4613 params.page_state = PageState::CreateFromURL(kUrl2); | 4468 params.page_state = PageState::CreateFromURL(kUrl2); |
4614 params.was_within_same_page = true; | 4469 params.was_within_same_page = true; |
4615 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); | 4470 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, false); |
4616 main_test_rfh()->PrepareForCommit(); | 4471 main_test_rfh()->PrepareForCommit(); |
4617 main_test_rfh()->SendNavigateWithParams(¶ms); | 4472 main_test_rfh()->SendNavigateWithParams(¶ms); |
4618 | 4473 |
4619 // The title should immediately be visible on the new NavigationEntry. | 4474 // The title should immediately be visible on the new NavigationEntry. |
4620 base::string16 new_title = | 4475 base::string16 new_title = |
4621 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); | 4476 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4680 | 4535 |
4681 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { | 4536 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { |
4682 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 4537 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
4683 EXPECT_FALSE(contents()->GetDelegate()); | 4538 EXPECT_FALSE(contents()->GetDelegate()); |
4684 contents()->SetDelegate(delegate.get()); | 4539 contents()->SetDelegate(delegate.get()); |
4685 | 4540 |
4686 // Submit a form. | 4541 // Submit a form. |
4687 GURL url("http://foo"); | 4542 GURL url("http://foo"); |
4688 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4543 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4689 params.page_id = 1; | 4544 params.page_id = 1; |
4690 params.nav_entry_id = 0; | |
4691 params.did_create_new_entry = true; | |
4692 params.url = url; | 4545 params.url = url; |
4693 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; | 4546 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; |
4694 params.gesture = NavigationGestureUser; | 4547 params.gesture = NavigationGestureUser; |
4695 params.page_state = PageState::CreateFromURL(url); | 4548 params.page_state = PageState::CreateFromURL(url); |
4696 params.was_within_same_page = false; | 4549 params.was_within_same_page = false; |
4697 params.is_post = true; | 4550 params.is_post = true; |
4698 params.post_id = 2; | 4551 params.post_id = 2; |
4699 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); | 4552 main_test_rfh()->SendRendererInitiatedNavigationRequest(url, false); |
4700 main_test_rfh()->PrepareForCommit(); | 4553 main_test_rfh()->PrepareForCommit(); |
4701 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4554 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4702 | 4555 |
4703 // history.replaceState() is called. | 4556 // history.replaceState() is called. |
4704 GURL replace_url("http://foo#foo"); | 4557 GURL replace_url("http://foo#foo"); |
4705 params.page_id = 1; | 4558 params.page_id = 1; |
4706 params.nav_entry_id = 0; | |
4707 params.did_create_new_entry = false; | |
4708 params.url = replace_url; | 4559 params.url = replace_url; |
4709 params.transition = ui::PAGE_TRANSITION_LINK; | 4560 params.transition = ui::PAGE_TRANSITION_LINK; |
4710 params.gesture = NavigationGestureUser; | 4561 params.gesture = NavigationGestureUser; |
4711 params.page_state = PageState::CreateFromURL(replace_url); | 4562 params.page_state = PageState::CreateFromURL(replace_url); |
4712 params.was_within_same_page = true; | 4563 params.was_within_same_page = true; |
4713 params.is_post = false; | 4564 params.is_post = false; |
4714 params.post_id = -1; | 4565 params.post_id = -1; |
4715 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); | 4566 main_test_rfh()->SendRendererInitiatedNavigationRequest(replace_url, false); |
4716 main_test_rfh()->PrepareForCommit(); | 4567 main_test_rfh()->PrepareForCommit(); |
4717 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); | 4568 contents()->GetMainFrame()->SendNavigateWithParams(¶ms); |
4718 | 4569 |
4719 // Now reload. replaceState overrides the POST, so we should not show a | 4570 // Now reload. replaceState overrides the POST, so we should not show a |
4720 // repost warning dialog. | 4571 // repost warning dialog. |
4721 controller_impl().Reload(true); | 4572 controller_impl().Reload(true); |
4722 EXPECT_EQ(0, delegate->repost_form_warning_count()); | 4573 EXPECT_EQ(0, delegate->repost_form_warning_count()); |
4723 } | 4574 } |
4724 | 4575 |
4725 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { | 4576 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { |
4726 GURL url("http://foo"); | 4577 GURL url("http://foo"); |
4727 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 4578 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
4728 params.page_id = 1; | 4579 params.page_id = 1; |
4729 params.nav_entry_id = 0; | |
4730 params.did_create_new_entry = true; | |
4731 params.url = url; | 4580 params.url = url; |
4732 params.transition = ui::PAGE_TRANSITION_LINK; | 4581 params.transition = ui::PAGE_TRANSITION_LINK; |
4733 params.gesture = NavigationGestureUser; | 4582 params.gesture = NavigationGestureUser; |
4734 params.page_state = PageState::CreateFromURL(url); | 4583 params.page_state = PageState::CreateFromURL(url); |
4735 params.was_within_same_page = false; | 4584 params.was_within_same_page = false; |
4736 params.is_post = true; | 4585 params.is_post = true; |
4737 params.post_id = 2; | 4586 params.post_id = 2; |
4738 params.url_is_unreachable = true; | 4587 params.url_is_unreachable = true; |
4739 | 4588 // Navigate to new page |
4740 // Navigate to new page. | |
4741 { | 4589 { |
4742 LoadCommittedDetails details; | 4590 LoadCommittedDetails details; |
4743 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4591 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4744 EXPECT_EQ(PAGE_TYPE_ERROR, | 4592 EXPECT_EQ(PAGE_TYPE_ERROR, |
4745 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4593 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4746 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); | 4594 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); |
4747 } | 4595 } |
4748 | 4596 |
4749 // Navigate to existing page. | 4597 // Navigate to existing page. |
4750 { | 4598 { |
4751 params.did_create_new_entry = false; | |
4752 LoadCommittedDetails details; | 4599 LoadCommittedDetails details; |
4753 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4600 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4754 EXPECT_EQ(PAGE_TYPE_ERROR, | 4601 EXPECT_EQ(PAGE_TYPE_ERROR, |
4755 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4602 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4756 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); | 4603 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details.type); |
4757 } | 4604 } |
4758 | 4605 |
4759 // Navigate to same page. | 4606 // Navigate to same page. |
4760 // Note: The call to LoadURL() creates a pending entry in order to trigger the | 4607 // Note: The call to LoadURL() creates a pending entry in order to trigger the |
4761 // same-page transition. | 4608 // same-page transition. |
4762 controller_impl().LoadURL( | 4609 controller_impl().LoadURL( |
4763 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 4610 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
4764 params.nav_entry_id = controller_impl().GetPendingEntry()->GetUniqueID(); | |
4765 params.transition = ui::PAGE_TRANSITION_TYPED; | 4611 params.transition = ui::PAGE_TRANSITION_TYPED; |
4766 { | 4612 { |
4767 LoadCommittedDetails details; | 4613 LoadCommittedDetails details; |
4768 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4614 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4769 EXPECT_EQ(PAGE_TYPE_ERROR, | 4615 EXPECT_EQ(PAGE_TYPE_ERROR, |
4770 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4616 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4771 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); | 4617 EXPECT_EQ(NAVIGATION_TYPE_SAME_PAGE, details.type); |
4772 } | 4618 } |
4773 | 4619 |
4774 // Navigate in page. | 4620 // Navigate in page. |
4775 params.url = GURL("http://foo#foo"); | 4621 params.url = GURL("http://foo#foo"); |
4776 params.transition = ui::PAGE_TRANSITION_LINK; | 4622 params.transition = ui::PAGE_TRANSITION_LINK; |
4777 params.was_within_same_page = true; | 4623 params.was_within_same_page = true; |
4778 { | 4624 { |
4779 LoadCommittedDetails details; | 4625 LoadCommittedDetails details; |
4780 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4626 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4781 EXPECT_EQ(PAGE_TYPE_ERROR, | 4627 EXPECT_EQ(PAGE_TYPE_ERROR, |
4782 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4628 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4783 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4629 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
4784 } | 4630 } |
4785 } | 4631 } |
4786 | 4632 |
4787 } // namespace content | 4633 } // namespace content |
OLD | NEW |