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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 RegisterForAllNavNotifications(¬ifications, &controller); | 1118 RegisterForAllNavNotifications(¬ifications, &controller); |
1119 | 1119 |
1120 const GURL url1("http://foo1"); | 1120 const GURL url1("http://foo1"); |
1121 | 1121 |
1122 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1122 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1123 EXPECT_EQ(0U, notifications.size()); | 1123 EXPECT_EQ(0U, notifications.size()); |
1124 test_rvh()->SendNavigate(0, url1); | 1124 test_rvh()->SendNavigate(0, url1); |
1125 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1125 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1126 navigation_entry_committed_counter_ = 0; | 1126 navigation_entry_committed_counter_ = 0; |
1127 ASSERT_TRUE(controller.GetVisibleEntry()); | 1127 ASSERT_TRUE(controller.GetVisibleEntry()); |
1128 controller.GetVisibleEntry()->SetTitle(ASCIIToUTF16("Title")); | 1128 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
1129 controller.Reload(true); | 1129 controller.Reload(true); |
1130 EXPECT_EQ(0U, notifications.size()); | 1130 EXPECT_EQ(0U, notifications.size()); |
1131 | 1131 |
1132 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1132 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
1133 EXPECT_FALSE(timestamp.is_null()); | 1133 EXPECT_FALSE(timestamp.is_null()); |
1134 | 1134 |
1135 // The reload is pending. | 1135 // The reload is pending. |
1136 EXPECT_EQ(controller.GetEntryCount(), 1); | 1136 EXPECT_EQ(controller.GetEntryCount(), 1); |
1137 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1137 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1138 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1138 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1242 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1243 navigation_entry_committed_counter_ = 0; | 1243 navigation_entry_committed_counter_ = 0; |
1244 | 1244 |
1245 // The NavigationEntry should save both the original URL and the final | 1245 // The NavigationEntry should save both the original URL and the final |
1246 // redirected URL. | 1246 // redirected URL. |
1247 EXPECT_EQ( | 1247 EXPECT_EQ( |
1248 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1248 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
1249 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1249 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
1250 | 1250 |
1251 // Reload using the original URL. | 1251 // Reload using the original URL. |
1252 controller.GetVisibleEntry()->SetTitle(ASCIIToUTF16("Title")); | 1252 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
1253 controller.ReloadOriginalRequestURL(false); | 1253 controller.ReloadOriginalRequestURL(false); |
1254 EXPECT_EQ(0U, notifications.size()); | 1254 EXPECT_EQ(0U, notifications.size()); |
1255 | 1255 |
1256 // The reload is pending. The request should point to the original URL. | 1256 // The reload is pending. The request should point to the original URL. |
1257 EXPECT_EQ(original_url, navigated_url()); | 1257 EXPECT_EQ(original_url, navigated_url()); |
1258 EXPECT_EQ(controller.GetEntryCount(), 1); | 1258 EXPECT_EQ(controller.GetEntryCount(), 1); |
1259 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1259 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1260 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1260 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1261 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1261 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1262 EXPECT_TRUE(controller.GetPendingEntry()); | 1262 EXPECT_TRUE(controller.GetPendingEntry()); |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 // everything is updated properly. This can be tricky since there is no | 2285 // everything is updated properly. This can be tricky since there is no |
2286 // SiteInstance for the entries created initially. | 2286 // SiteInstance for the entries created initially. |
2287 TEST_F(NavigationControllerTest, RestoreNavigate) { | 2287 TEST_F(NavigationControllerTest, RestoreNavigate) { |
2288 // Create a NavigationController with a restored set of tabs. | 2288 // Create a NavigationController with a restored set of tabs. |
2289 GURL url("http://foo"); | 2289 GURL url("http://foo"); |
2290 std::vector<NavigationEntry*> entries; | 2290 std::vector<NavigationEntry*> entries; |
2291 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 2291 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
2292 url, Referrer(), PAGE_TRANSITION_RELOAD, false, std::string(), | 2292 url, Referrer(), PAGE_TRANSITION_RELOAD, false, std::string(), |
2293 browser_context()); | 2293 browser_context()); |
2294 entry->SetPageID(0); | 2294 entry->SetPageID(0); |
2295 entry->SetTitle(ASCIIToUTF16("Title")); | 2295 entry->SetTitle(base::ASCIIToUTF16("Title")); |
2296 entry->SetPageState(PageState::CreateFromEncodedData("state")); | 2296 entry->SetPageState(PageState::CreateFromEncodedData("state")); |
2297 const base::Time timestamp = base::Time::Now(); | 2297 const base::Time timestamp = base::Time::Now(); |
2298 entry->SetTimestamp(timestamp); | 2298 entry->SetTimestamp(timestamp); |
2299 entries.push_back(entry); | 2299 entries.push_back(entry); |
2300 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 2300 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
2301 WebContents::Create(WebContents::CreateParams(browser_context())))); | 2301 WebContents::Create(WebContents::CreateParams(browser_context())))); |
2302 NavigationControllerImpl& our_controller = our_contents->GetController(); | 2302 NavigationControllerImpl& our_controller = our_contents->GetController(); |
2303 our_controller.Restore( | 2303 our_controller.Restore( |
2304 0, | 2304 0, |
2305 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, | 2305 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2364 // Tests that we can still navigate to a restored entry after a different | 2364 // Tests that we can still navigate to a restored entry after a different |
2365 // navigation fails and clears the pending entry. http://crbug.com/90085 | 2365 // navigation fails and clears the pending entry. http://crbug.com/90085 |
2366 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { | 2366 TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { |
2367 // Create a NavigationController with a restored set of tabs. | 2367 // Create a NavigationController with a restored set of tabs. |
2368 GURL url("http://foo"); | 2368 GURL url("http://foo"); |
2369 std::vector<NavigationEntry*> entries; | 2369 std::vector<NavigationEntry*> entries; |
2370 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( | 2370 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( |
2371 url, Referrer(), PAGE_TRANSITION_RELOAD, false, std::string(), | 2371 url, Referrer(), PAGE_TRANSITION_RELOAD, false, std::string(), |
2372 browser_context()); | 2372 browser_context()); |
2373 entry->SetPageID(0); | 2373 entry->SetPageID(0); |
2374 entry->SetTitle(ASCIIToUTF16("Title")); | 2374 entry->SetTitle(base::ASCIIToUTF16("Title")); |
2375 entry->SetPageState(PageState::CreateFromEncodedData("state")); | 2375 entry->SetPageState(PageState::CreateFromEncodedData("state")); |
2376 entries.push_back(entry); | 2376 entries.push_back(entry); |
2377 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( | 2377 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( |
2378 WebContents::Create(WebContents::CreateParams(browser_context())))); | 2378 WebContents::Create(WebContents::CreateParams(browser_context())))); |
2379 NavigationControllerImpl& our_controller = our_contents->GetController(); | 2379 NavigationControllerImpl& our_controller = our_contents->GetController(); |
2380 our_controller.Restore( | 2380 our_controller.Restore( |
2381 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); | 2381 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
2382 ASSERT_EQ(0u, entries.size()); | 2382 ASSERT_EQ(0u, entries.size()); |
2383 | 2383 |
2384 // Before navigating to the restored entry, it should have a restore_type | 2384 // Before navigating to the restored entry, it should have a restore_type |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2958 EXPECT_EQ(controller.GetEntryCount(), 1); | 2958 EXPECT_EQ(controller.GetEntryCount(), 1); |
2959 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 2959 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
2960 } | 2960 } |
2961 | 2961 |
2962 // Make sure that on cloning a WebContentsImpl and going back needs_reload is | 2962 // Make sure that on cloning a WebContentsImpl and going back needs_reload is |
2963 // false. | 2963 // false. |
2964 TEST_F(NavigationControllerTest, CloneAndGoBack) { | 2964 TEST_F(NavigationControllerTest, CloneAndGoBack) { |
2965 NavigationControllerImpl& controller = controller_impl(); | 2965 NavigationControllerImpl& controller = controller_impl(); |
2966 const GURL url1("http://foo1"); | 2966 const GURL url1("http://foo1"); |
2967 const GURL url2("http://foo2"); | 2967 const GURL url2("http://foo2"); |
2968 const base::string16 title(ASCIIToUTF16("Title")); | 2968 const base::string16 title(base::ASCIIToUTF16("Title")); |
2969 | 2969 |
2970 NavigateAndCommit(url1); | 2970 NavigateAndCommit(url1); |
2971 controller.GetVisibleEntry()->SetTitle(title); | 2971 controller.GetVisibleEntry()->SetTitle(title); |
2972 NavigateAndCommit(url2); | 2972 NavigateAndCommit(url2); |
2973 | 2973 |
2974 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); | 2974 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
2975 | 2975 |
2976 ASSERT_EQ(2, clone->GetController().GetEntryCount()); | 2976 ASSERT_EQ(2, clone->GetController().GetEntryCount()); |
2977 EXPECT_TRUE(clone->GetController().NeedsReload()); | 2977 EXPECT_TRUE(clone->GetController().NeedsReload()); |
2978 clone->GetController().GoBack(); | 2978 clone->GetController().GoBack(); |
2979 // Navigating back should have triggered needs_reload_ to go false. | 2979 // Navigating back should have triggered needs_reload_ to go false. |
2980 EXPECT_FALSE(clone->GetController().NeedsReload()); | 2980 EXPECT_FALSE(clone->GetController().NeedsReload()); |
2981 | 2981 |
2982 // Ensure that the pending URL and its title are visible. | 2982 // Ensure that the pending URL and its title are visible. |
2983 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL()); | 2983 EXPECT_EQ(url1, clone->GetController().GetVisibleEntry()->GetURL()); |
2984 EXPECT_EQ(title, clone->GetTitle()); | 2984 EXPECT_EQ(title, clone->GetTitle()); |
2985 } | 2985 } |
2986 | 2986 |
2987 // Make sure that reloading a cloned tab doesn't change its pending entry index. | 2987 // Make sure that reloading a cloned tab doesn't change its pending entry index. |
2988 // See http://crbug.com/234491. | 2988 // See http://crbug.com/234491. |
2989 TEST_F(NavigationControllerTest, CloneAndReload) { | 2989 TEST_F(NavigationControllerTest, CloneAndReload) { |
2990 NavigationControllerImpl& controller = controller_impl(); | 2990 NavigationControllerImpl& controller = controller_impl(); |
2991 const GURL url1("http://foo1"); | 2991 const GURL url1("http://foo1"); |
2992 const GURL url2("http://foo2"); | 2992 const GURL url2("http://foo2"); |
2993 const base::string16 title(ASCIIToUTF16("Title")); | 2993 const base::string16 title(base::ASCIIToUTF16("Title")); |
2994 | 2994 |
2995 NavigateAndCommit(url1); | 2995 NavigateAndCommit(url1); |
2996 controller.GetVisibleEntry()->SetTitle(title); | 2996 controller.GetVisibleEntry()->SetTitle(title); |
2997 NavigateAndCommit(url2); | 2997 NavigateAndCommit(url2); |
2998 | 2998 |
2999 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); | 2999 scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); |
3000 clone->GetController().LoadIfNecessary(); | 3000 clone->GetController().LoadIfNecessary(); |
3001 | 3001 |
3002 ASSERT_EQ(2, clone->GetController().GetEntryCount()); | 3002 ASSERT_EQ(2, clone->GetController().GetEntryCount()); |
3003 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); | 3003 EXPECT_EQ(1, clone->GetController().GetPendingEntryIndex()); |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4008 EXPECT_EQ(1, controller.GetEntryCount()); | 4008 EXPECT_EQ(1, controller.GetEntryCount()); |
4009 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4009 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
4010 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4010 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4011 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4011 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4012 EXPECT_FALSE(controller.CanGoBack()); | 4012 EXPECT_FALSE(controller.CanGoBack()); |
4013 EXPECT_FALSE(controller.CanGoForward()); | 4013 EXPECT_FALSE(controller.CanGoForward()); |
4014 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4014 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
4015 } | 4015 } |
4016 | 4016 |
4017 } // namespace content | 4017 } // namespace content |
OLD | NEW |