OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 // These are only used for commented out tests. If someone wants to enable | 11 // These are only used for commented out tests. If someone wants to enable |
12 // them, they should be moved to chrome first. | 12 // them, they should be moved to chrome first. |
13 // #include "chrome/browser/history/history.h" | 13 // #include "chrome/browser/history/history.h" |
14 // #include "chrome/browser/profiles/profile_manager.h" | 14 // #include "chrome/browser/profiles/profile_manager.h" |
15 // #include "chrome/browser/sessions/session_service.h" | 15 // #include "chrome/browser/sessions/session_service.h" |
16 // #include "chrome/browser/sessions/session_service_factory.h" | 16 // #include "chrome/browser/sessions/session_service_factory.h" |
17 // #include "chrome/browser/sessions/session_service_test_helper.h" | 17 // #include "chrome/browser/sessions/session_service_test_helper.h" |
18 // #include "chrome/browser/sessions/session_types.h" | 18 // #include "chrome/browser/sessions/session_types.h" |
19 #include "content/browser/renderer_host/test_render_view_host.h" | 19 #include "content/browser/renderer_host/test_render_view_host.h" |
20 #include "content/browser/site_instance_impl.h" | 20 #include "content/browser/site_instance_impl.h" |
21 #include "content/browser/web_contents/navigation_controller_impl.h" | 21 #include "content/browser/web_contents/navigation_controller_impl.h" |
22 #include "content/browser/web_contents/navigation_entry_impl.h" | 22 #include "content/browser/web_contents/navigation_entry_impl.h" |
23 #include "content/browser/web_contents/test_web_contents.h" | 23 #include "content/browser/web_contents/test_web_contents.h" |
24 #include "content/browser/web_contents/web_contents_impl.h" | 24 #include "content/browser/web_contents/web_contents_impl.h" |
25 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
26 #include "content/public/browser/navigation_details.h" | 26 #include "content/public/browser/navigation_details.h" |
27 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/render_view_host_observer.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 31 #include "content/public/browser/web_contents_delegate.h" |
30 #include "content/public/test/mock_render_process_host.h" | 32 #include "content/public/test/mock_render_process_host.h" |
31 #include "content/public/test/test_notification_tracker.h" | 33 #include "content/public/test/test_notification_tracker.h" |
32 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "webkit/glue/webkit_glue.h" | 36 #include "webkit/glue/webkit_glue.h" |
35 | 37 |
36 using base::Time; | 38 using base::Time; |
37 using content::NavigationController; | 39 using content::NavigationController; |
38 using content::NavigationEntry; | 40 using content::NavigationEntry; |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 // Now the reload is committed. | 659 // Now the reload is committed. |
658 EXPECT_EQ(controller.GetEntryCount(), 2); | 660 EXPECT_EQ(controller.GetEntryCount(), 2); |
659 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 661 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
660 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 662 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
661 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 663 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
662 EXPECT_FALSE(controller.GetPendingEntry()); | 664 EXPECT_FALSE(controller.GetPendingEntry()); |
663 EXPECT_TRUE(controller.CanGoBack()); | 665 EXPECT_TRUE(controller.CanGoBack()); |
664 EXPECT_FALSE(controller.CanGoForward()); | 666 EXPECT_FALSE(controller.CanGoForward()); |
665 } | 667 } |
666 | 668 |
| 669 class TestNavigationObserver : public content::RenderViewHostObserver { |
| 670 public: |
| 671 TestNavigationObserver(content::RenderViewHost* render_view_host) |
| 672 : RenderViewHostObserver(render_view_host) { |
| 673 } |
| 674 |
| 675 const GURL& navigated_url() const { |
| 676 return navigated_url_; |
| 677 } |
| 678 |
| 679 protected: |
| 680 virtual void Navigate(const GURL& url) OVERRIDE { |
| 681 navigated_url_ = url; |
| 682 } |
| 683 |
| 684 private: |
| 685 GURL navigated_url_; |
| 686 }; |
| 687 |
| 688 TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { |
| 689 NavigationControllerImpl& controller = controller_impl(); |
| 690 TestNotificationTracker notifications; |
| 691 RegisterForAllNavNotifications(¬ifications, &controller); |
| 692 TestNavigationObserver observer(test_rvh()); |
| 693 |
| 694 const GURL original_url("http://foo1"); |
| 695 const GURL final_url("http://foo2"); |
| 696 |
| 697 // Load up the original URL, but get redirected. |
| 698 controller.LoadURL(original_url, content::Referrer(), |
| 699 content::PAGE_TRANSITION_TYPED, std::string()); |
| 700 EXPECT_EQ(0U, notifications.size()); |
| 701 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); |
| 702 EXPECT_TRUE(notifications.Check1AndReset( |
| 703 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 704 |
| 705 // The NavigationEntry should save both the original URL and the final |
| 706 // redirected URL. |
| 707 EXPECT_EQ(original_url, controller.GetActiveEntry()->GetOriginalRequestURL()); |
| 708 EXPECT_EQ(final_url, controller.GetActiveEntry()->GetURL()); |
| 709 |
| 710 // Reload using the original URL. |
| 711 controller.GetActiveEntry()->SetTitle(ASCIIToUTF16("Title")); |
| 712 controller.ReloadOriginalRequestURL(false); |
| 713 EXPECT_EQ(0U, notifications.size()); |
| 714 |
| 715 // The reload is pending. The request should point to the original URL. |
| 716 EXPECT_EQ(original_url, observer.navigated_url()); |
| 717 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 718 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 719 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
| 720 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 721 EXPECT_TRUE(controller.GetPendingEntry()); |
| 722 EXPECT_FALSE(controller.CanGoBack()); |
| 723 EXPECT_FALSE(controller.CanGoForward()); |
| 724 |
| 725 // Make sure the title has been cleared (will be redrawn just after reload). |
| 726 // Avoids a stale cached title when the new page being reloaded has no title. |
| 727 // See http://crbug.com/96041. |
| 728 EXPECT_TRUE(controller.GetActiveEntry()->GetTitle().empty()); |
| 729 |
| 730 // Send that the navigation has proceeded; say it got redirected again. |
| 731 test_rvh()->SendNavigate(0, final_url); |
| 732 EXPECT_TRUE(notifications.Check1AndReset( |
| 733 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
| 734 |
| 735 // Now the reload is committed. |
| 736 EXPECT_EQ(controller.GetEntryCount(), 1); |
| 737 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
| 738 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
| 739 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
| 740 EXPECT_FALSE(controller.GetPendingEntry()); |
| 741 EXPECT_FALSE(controller.CanGoBack()); |
| 742 EXPECT_FALSE(controller.CanGoForward()); |
| 743 } |
| 744 |
667 // Tests what happens when we navigate back successfully | 745 // Tests what happens when we navigate back successfully |
668 TEST_F(NavigationControllerTest, Back) { | 746 TEST_F(NavigationControllerTest, Back) { |
669 NavigationControllerImpl& controller = controller_impl(); | 747 NavigationControllerImpl& controller = controller_impl(); |
670 TestNotificationTracker notifications; | 748 TestNotificationTracker notifications; |
671 RegisterForAllNavNotifications(¬ifications, &controller); | 749 RegisterForAllNavNotifications(¬ifications, &controller); |
672 | 750 |
673 const GURL url1("http://foo1"); | 751 const GURL url1("http://foo1"); |
674 test_rvh()->SendNavigate(0, url1); | 752 test_rvh()->SendNavigate(0, url1); |
675 EXPECT_TRUE(notifications.Check1AndReset( | 753 EXPECT_TRUE(notifications.Check1AndReset( |
676 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); | 754 content::NOTIFICATION_NAV_ENTRY_COMMITTED)); |
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2655 TabNavigation nav(0, url0, GURL(), string16(), | 2733 TabNavigation nav(0, url0, GURL(), string16(), |
2656 webkit_glue::CreateHistoryStateForURL(url0), | 2734 webkit_glue::CreateHistoryStateForURL(url0), |
2657 content::PAGE_TRANSITION_LINK); | 2735 content::PAGE_TRANSITION_LINK); |
2658 session_helper_.AssertNavigationEquals(nav, | 2736 session_helper_.AssertNavigationEquals(nav, |
2659 windows_[0]->tabs[0]->navigations[0]); | 2737 windows_[0]->tabs[0]->navigations[0]); |
2660 nav.set_url(url2); | 2738 nav.set_url(url2); |
2661 session_helper_.AssertNavigationEquals(nav, | 2739 session_helper_.AssertNavigationEquals(nav, |
2662 windows_[0]->tabs[0]->navigations[1]); | 2740 windows_[0]->tabs[0]->navigations[1]); |
2663 } | 2741 } |
2664 */ | 2742 */ |
OLD | NEW |