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

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

Issue 2957783002: Fix wrong ui::PAGE_TRANSITION_FORWARD_BACK in tests. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 }; 417 };
418 418
419 for (int test = 0; test < NUM_TESTS; ++test) { 419 for (int test = 0; test < NUM_TESTS; ++test) {
420 int offset = test_offsets[test]; 420 int offset = test_offsets[test];
421 controller.GoToOffset(offset); 421 controller.GoToOffset(offset);
422 int entry_id = controller.GetPendingEntry()->GetUniqueID(); 422 int entry_id = controller.GetPendingEntry()->GetUniqueID();
423 url_index += offset; 423 url_index += offset;
424 // Check that the GoToOffset will land on the expected page. 424 // Check that the GoToOffset will land on the expected page.
425 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); 425 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL());
426 main_test_rfh()->PrepareForCommit(); 426 main_test_rfh()->PrepareForCommit();
427 main_test_rfh()->SendNavigate(entry_id, false, urls[url_index]); 427 main_test_rfh()->SendNavigateWithTransition(
428 entry_id, false, urls[url_index],
429 controller.GetPendingEntry()->GetTransitionType());
428 EXPECT_EQ(1U, navigation_entry_committed_counter_); 430 EXPECT_EQ(1U, navigation_entry_committed_counter_);
429 navigation_entry_committed_counter_ = 0; 431 navigation_entry_committed_counter_ = 0;
430 // Check that we can go to any valid offset into the history. 432 // Check that we can go to any valid offset into the history.
431 for (size_t j = 0; j < urls.size(); ++j) 433 for (size_t j = 0; j < urls.size(); ++j)
432 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); 434 EXPECT_TRUE(controller.CanGoToOffset(j - url_index));
433 // Check that we can't go beyond the beginning or end of the history. 435 // Check that we can't go beyond the beginning or end of the history.
434 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); 436 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1)));
435 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); 437 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index));
436 } 438 }
437 } 439 }
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1361
1360 // The second load should be committed, and bindings should be remembered. 1362 // The second load should be committed, and bindings should be remembered.
1361 EXPECT_EQ(controller.GetEntryCount(), 2); 1363 EXPECT_EQ(controller.GetEntryCount(), 2);
1362 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1364 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1363 EXPECT_TRUE(controller.CanGoBack()); 1365 EXPECT_TRUE(controller.CanGoBack());
1364 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); 1366 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings());
1365 1367
1366 // Going back, the first entry should still appear unprivileged. 1368 // Going back, the first entry should still appear unprivileged.
1367 controller.GoBack(); 1369 controller.GoBack();
1368 new_rfh->PrepareForCommit(); 1370 new_rfh->PrepareForCommit();
1369 contents()->GetPendingMainFrame()->SendNavigate(entry1_id, false, url1); 1371 contents()->GetPendingMainFrame()->SendNavigateWithTransition(
1372 entry1_id, false, url1,
1373 controller.GetPendingEntry()->GetTransitionType());
1370 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1374 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1371 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); 1375 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings());
1372 } 1376 }
1373 1377
1374 TEST_F(NavigationControllerTest, Reload) { 1378 TEST_F(NavigationControllerTest, Reload) {
1375 NavigationControllerImpl& controller = controller_impl(); 1379 NavigationControllerImpl& controller = controller_impl();
1376 TestNotificationTracker notifications; 1380 TestNotificationTracker notifications;
1377 RegisterForAllNavNotifications(&notifications, &controller); 1381 RegisterForAllNavNotifications(&notifications, &controller);
1378 1382
1379 const GURL url1("http://foo1"); 1383 const GURL url1("http://foo1");
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 1693
1690 // Test that OnWebkitPreferencesChanged is called when going back to propagate 1694 // Test that OnWebkitPreferencesChanged is called when going back to propagate
1691 // change in viewport_meta WebSetting. 1695 // change in viewport_meta WebSetting.
1692 int change_counter = 0; 1696 int change_counter = 0;
1693 test_rvh()->set_webkit_preferences_changed_counter(&change_counter); 1697 test_rvh()->set_webkit_preferences_changed_counter(&change_counter);
1694 1698
1695 controller.GoBack(); 1699 controller.GoBack();
1696 entry_id = controller.GetPendingEntry()->GetUniqueID(); 1700 entry_id = controller.GetPendingEntry()->GetUniqueID();
1697 EXPECT_FALSE(controller.GetPendingEntry()->GetIsOverridingUserAgent()); 1701 EXPECT_FALSE(controller.GetPendingEntry()->GetIsOverridingUserAgent());
1698 main_test_rfh()->PrepareForCommit(); 1702 main_test_rfh()->PrepareForCommit();
1699 main_test_rfh()->SendNavigate(entry_id, false, url1); 1703 main_test_rfh()->SendNavigateWithTransition(
1704 entry_id, false, url1, controller.GetPendingEntry()->GetTransitionType());
1700 1705
1701 EXPECT_EQ(1, change_counter); 1706 EXPECT_EQ(1, change_counter);
1702 } 1707 }
1703 1708
1704 // Tests what happens when we navigate back successfully 1709 // Tests what happens when we navigate back successfully
1705 TEST_F(NavigationControllerTest, Back) { 1710 TEST_F(NavigationControllerTest, Back) {
1706 NavigationControllerImpl& controller = controller_impl(); 1711 NavigationControllerImpl& controller = controller_impl();
1707 TestNotificationTracker notifications; 1712 TestNotificationTracker notifications;
1708 RegisterForAllNavNotifications(&notifications, &controller); 1713 RegisterForAllNavNotifications(&notifications, &controller);
1709 1714
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 // We should now have a pending navigation to go back. 1799 // We should now have a pending navigation to go back.
1795 EXPECT_EQ(controller.GetEntryCount(), 2); 1800 EXPECT_EQ(controller.GetEntryCount(), 2);
1796 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1801 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1797 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1802 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1798 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1803 EXPECT_TRUE(controller.GetLastCommittedEntry());
1799 EXPECT_TRUE(controller.GetPendingEntry()); 1804 EXPECT_TRUE(controller.GetPendingEntry());
1800 EXPECT_FALSE(controller.CanGoBack()); 1805 EXPECT_FALSE(controller.CanGoBack());
1801 EXPECT_TRUE(controller.CanGoForward()); 1806 EXPECT_TRUE(controller.CanGoForward());
1802 1807
1803 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); 1808 main_test_rfh()->PrepareForCommitWithServerRedirect(url3);
1804 main_test_rfh()->SendNavigate(entry1_id, true, url3); 1809 main_test_rfh()->SendNavigateWithTransition(
1810 entry1_id, true, url3, controller.GetPendingEntry()->GetTransitionType());
1805 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1811 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1806 navigation_entry_committed_counter_ = 0; 1812 navigation_entry_committed_counter_ = 0;
1807 1813
1808 // The back navigation resulted in a completely new navigation. 1814 // The back navigation resulted in a completely new navigation.
1809 // TODO(darin): perhaps this behavior will be confusing to users? 1815 // TODO(darin): perhaps this behavior will be confusing to users?
1810 EXPECT_EQ(controller.GetEntryCount(), 3); 1816 EXPECT_EQ(controller.GetEntryCount(), 3);
1811 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); 1817 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2);
1812 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1818 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1813 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1819 EXPECT_TRUE(controller.GetLastCommittedEntry());
1814 EXPECT_FALSE(controller.GetPendingEntry()); 1820 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 1873
1868 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); 1874 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true);
1869 main_test_rfh()->PrepareForCommit(); 1875 main_test_rfh()->PrepareForCommit();
1870 main_test_rfh()->SendNavigate(0, true, url2); 1876 main_test_rfh()->SendNavigate(0, true, url2);
1871 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); 1877 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
1872 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1878 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1873 navigation_entry_committed_counter_ = 0; 1879 navigation_entry_committed_counter_ = 0;
1874 1880
1875 controller.GoBack(); 1881 controller.GoBack();
1876 main_test_rfh()->PrepareForCommit(); 1882 main_test_rfh()->PrepareForCommit();
1877 main_test_rfh()->SendNavigate(entry1->GetUniqueID(), false, url1); 1883 main_test_rfh()->SendNavigateWithTransition(
1884 entry1->GetUniqueID(), false, url1,
1885 controller.GetPendingEntry()->GetTransitionType());
1878 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1886 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1879 navigation_entry_committed_counter_ = 0; 1887 navigation_entry_committed_counter_ = 0;
1880 1888
1881 controller.GoForward(); 1889 controller.GoForward();
1882 1890
1883 // We should now have a pending navigation to go forward. 1891 // We should now have a pending navigation to go forward.
1884 EXPECT_EQ(controller.GetEntryCount(), 2); 1892 EXPECT_EQ(controller.GetEntryCount(), 2);
1885 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1893 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1886 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); 1894 EXPECT_EQ(controller.GetPendingEntryIndex(), 1);
1887 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1895 EXPECT_TRUE(controller.GetLastCommittedEntry());
1888 EXPECT_TRUE(controller.GetPendingEntry()); 1896 EXPECT_TRUE(controller.GetPendingEntry());
1889 EXPECT_TRUE(controller.CanGoBack()); 1897 EXPECT_TRUE(controller.CanGoBack());
1890 EXPECT_TRUE(controller.CanGoToOffset(-1)); 1898 EXPECT_TRUE(controller.CanGoToOffset(-1));
1891 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. 1899 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps.
1892 EXPECT_FALSE(controller.CanGoForward()); 1900 EXPECT_FALSE(controller.CanGoForward());
1893 EXPECT_FALSE(controller.CanGoToOffset(1)); 1901 EXPECT_FALSE(controller.CanGoToOffset(1));
1894 1902
1895 // Timestamp for entry 0 should be on or after that of entry 1 1903 // Timestamp for entry 0 should be on or after that of entry 1
1896 // (since we went back to it). 1904 // (since we went back to it).
1897 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); 1905 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null());
1898 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), 1906 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(),
1899 controller.GetEntryAtIndex(1)->GetTimestamp()); 1907 controller.GetEntryAtIndex(1)->GetTimestamp());
1900 1908
1901 main_test_rfh()->PrepareForCommit(); 1909 main_test_rfh()->PrepareForCommit();
1902 main_test_rfh()->SendNavigate(entry2->GetUniqueID(), false, url2); 1910 main_test_rfh()->SendNavigateWithTransition(
1911 entry2->GetUniqueID(), false, url2,
1912 controller.GetPendingEntry()->GetTransitionType());
1903 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1913 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1904 navigation_entry_committed_counter_ = 0; 1914 navigation_entry_committed_counter_ = 0;
1905 1915
1906 // The forward navigation completed successfully. 1916 // The forward navigation completed successfully.
1907 EXPECT_EQ(controller.GetEntryCount(), 2); 1917 EXPECT_EQ(controller.GetEntryCount(), 2);
1908 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1918 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1909 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1919 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1910 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1920 EXPECT_TRUE(controller.GetLastCommittedEntry());
1911 EXPECT_FALSE(controller.GetPendingEntry()); 1921 EXPECT_FALSE(controller.GetPendingEntry());
1912 EXPECT_TRUE(controller.CanGoBack()); 1922 EXPECT_TRUE(controller.CanGoBack());
(...skipping 26 matching lines...) Expand all
1939 navigation_entry_committed_counter_ = 0; 1949 navigation_entry_committed_counter_ = 0;
1940 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true); 1950 main_test_rfh()->SendRendererInitiatedNavigationRequest(url2, true);
1941 main_test_rfh()->PrepareForCommit(); 1951 main_test_rfh()->PrepareForCommit();
1942 main_test_rfh()->SendNavigate(0, true, url2); 1952 main_test_rfh()->SendNavigate(0, true, url2);
1943 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1953 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1944 NavigationEntry* entry2 = controller.GetLastCommittedEntry(); 1954 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
1945 navigation_entry_committed_counter_ = 0; 1955 navigation_entry_committed_counter_ = 0;
1946 1956
1947 controller.GoBack(); 1957 controller.GoBack();
1948 main_test_rfh()->PrepareForCommit(); 1958 main_test_rfh()->PrepareForCommit();
1949 main_test_rfh()->SendNavigate(entry1->GetUniqueID(), false, url1); 1959 main_test_rfh()->SendNavigateWithTransition(
1960 entry1->GetUniqueID(), false, url1,
1961 controller.GetPendingEntry()->GetTransitionType());
1950 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1962 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1951 navigation_entry_committed_counter_ = 0; 1963 navigation_entry_committed_counter_ = 0;
1952 1964
1953 controller.GoForward(); 1965 controller.GoForward();
1954 EXPECT_EQ(0U, notifications.size()); 1966 EXPECT_EQ(0U, notifications.size());
1955 1967
1956 // Should now have a pending navigation to go forward. 1968 // Should now have a pending navigation to go forward.
1957 EXPECT_EQ(controller.GetEntryCount(), 2); 1969 EXPECT_EQ(controller.GetEntryCount(), 2);
1958 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1970 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1959 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); 1971 EXPECT_EQ(controller.GetPendingEntryIndex(), 1);
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 ASSERT_EQ(0u, entries.size()); 3011 ASSERT_EQ(0u, entries.size());
3000 3012
3001 // Before navigating to the restored entry, it should have a restore_type 3013 // Before navigating to the restored entry, it should have a restore_type
3002 // and no SiteInstance. 3014 // and no SiteInstance.
3003 ASSERT_EQ(1, our_controller.GetEntryCount()); 3015 ASSERT_EQ(1, our_controller.GetEntryCount());
3004 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY, 3016 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY,
3005 our_controller.GetEntryAtIndex(0)->restore_type()); 3017 our_controller.GetEntryAtIndex(0)->restore_type());
3006 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); 3018 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance());
3007 3019
3008 // After navigating, we should have one entry, and it should be "pending". 3020 // After navigating, we should have one entry, and it should be "pending".
3009 our_controller.GoToIndex(0); 3021 EXPECT_TRUE(our_controller.NeedsReload());
arthursonzogni 2017/06/26 14:59:11 This line does a back/forward navigation. But we a
Charlie Reis 2017/06/27 03:59:14 Thanks-- your change here looks good.
3022 our_controller.LoadIfNecessary();
3010 EXPECT_EQ(1, our_controller.GetEntryCount()); 3023 EXPECT_EQ(1, our_controller.GetEntryCount());
3011 EXPECT_EQ(our_controller.GetEntryAtIndex(0), 3024 EXPECT_EQ(our_controller.GetEntryAtIndex(0),
3012 our_controller.GetPendingEntry()); 3025 our_controller.GetPendingEntry());
3013 3026
3014 // Timestamp should remain the same before the navigation finishes. 3027 // Timestamp should remain the same before the navigation finishes.
3015 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); 3028 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp());
3016 3029
3017 // Say we navigated to that entry. 3030 // Say we navigated to that entry.
3018 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3031 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3019 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID(); 3032 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3069 main_test_rfh()->InitializeRenderFrameIfNeeded(); 3082 main_test_rfh()->InitializeRenderFrameIfNeeded();
3070 3083
3071 // Before navigating to the restored entry, it should have a restore_type 3084 // Before navigating to the restored entry, it should have a restore_type
3072 // and no SiteInstance. 3085 // and no SiteInstance.
3073 NavigationEntry* entry = our_controller.GetEntryAtIndex(0); 3086 NavigationEntry* entry = our_controller.GetEntryAtIndex(0);
3074 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY, 3087 EXPECT_EQ(RestoreType::LAST_SESSION_EXITED_CLEANLY,
3075 our_controller.GetEntryAtIndex(0)->restore_type()); 3088 our_controller.GetEntryAtIndex(0)->restore_type());
3076 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); 3089 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance());
3077 3090
3078 // After navigating, we should have one entry, and it should be "pending". 3091 // After navigating, we should have one entry, and it should be "pending".
3079 our_controller.GoToIndex(0); 3092 EXPECT_TRUE(our_controller.NeedsReload());
3093 our_controller.LoadIfNecessary();
3080 EXPECT_EQ(1, our_controller.GetEntryCount()); 3094 EXPECT_EQ(1, our_controller.GetEntryCount());
3081 EXPECT_EQ(our_controller.GetEntryAtIndex(0), 3095 EXPECT_EQ(our_controller.GetEntryAtIndex(0),
3082 our_controller.GetPendingEntry()); 3096 our_controller.GetPendingEntry());
3083 3097
3084 // This pending navigation may have caused a different navigation to fail, 3098 // This pending navigation may have caused a different navigation to fail,
3085 // which causes the pending entry to be cleared. 3099 // which causes the pending entry to be cleared.
3086 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; 3100 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params;
3087 fail_load_params.error_code = net::ERR_ABORTED; 3101 fail_load_params.error_code = net::ERR_ABORTED;
3088 fail_load_params.error_description = base::string16(); 3102 fail_load_params.error_description = base::string16();
3089 fail_load_params.url = url; 3103 fail_load_params.url = url;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3191 3205
3192 // Go back, but don't commit yet. Check that we can't delete the current 3206 // Go back, but don't commit yet. Check that we can't delete the current
3193 // and pending entries. 3207 // and pending entries.
3194 controller.GoBack(); 3208 controller.GoBack();
3195 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3209 entry_id = controller.GetPendingEntry()->GetUniqueID();
3196 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); 3210 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1));
3197 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); 3211 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2));
3198 3212
3199 // Now commit and delete the last entry. 3213 // Now commit and delete the last entry.
3200 main_test_rfh()->PrepareForCommit(); 3214 main_test_rfh()->PrepareForCommit();
3201 main_test_rfh()->SendNavigate(entry_id, false, url4); 3215 main_test_rfh()->SendNavigateWithTransition(
3216 entry_id, false, url4, controller.GetPendingEntry()->GetTransitionType());
3202 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); 3217 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1));
3203 EXPECT_EQ(4, controller.GetEntryCount()); 3218 EXPECT_EQ(4, controller.GetEntryCount());
3204 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); 3219 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex());
3205 EXPECT_FALSE(controller.GetPendingEntry()); 3220 EXPECT_FALSE(controller.GetPendingEntry());
3206 3221
3207 // Remove an entry which is not the last committed one. 3222 // Remove an entry which is not the last committed one.
3208 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); 3223 EXPECT_TRUE(controller.RemoveEntryAtIndex(0));
3209 EXPECT_EQ(3, controller.GetEntryCount()); 3224 EXPECT_EQ(3, controller.GetEntryCount());
3210 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 3225 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
3211 EXPECT_FALSE(controller.GetPendingEntry()); 3226 EXPECT_FALSE(controller.GetPendingEntry());
(...skipping 27 matching lines...) Expand all
3239 controller.LoadURL( 3254 controller.LoadURL(
3240 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3255 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3241 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3256 entry_id = controller.GetPendingEntry()->GetUniqueID();
3242 main_test_rfh()->PrepareForCommit(); 3257 main_test_rfh()->PrepareForCommit();
3243 main_test_rfh()->SendNavigate(entry_id, true, url3); 3258 main_test_rfh()->SendNavigate(entry_id, true, url3);
3244 3259
3245 // Go back, but don't commit yet. Check that we can't delete the current 3260 // Go back, but don't commit yet. Check that we can't delete the current
3246 // and pending entries. 3261 // and pending entries.
3247 controller.GoBack(); 3262 controller.GoBack();
3248 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3263 entry_id = controller.GetPendingEntry()->GetUniqueID();
3264 ui::PageTransition entry_transition =
3265 controller.GetPendingEntry()->GetTransitionType();
3249 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); 3266 EXPECT_FALSE(controller.RemoveEntryAtIndex(2));
3250 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); 3267 EXPECT_FALSE(controller.RemoveEntryAtIndex(1));
3251 3268
3252 // Remove the first entry, while there is a pending entry. This is expected 3269 // Remove the first entry, while there is a pending entry. This is expected
3253 // to discard the pending entry. 3270 // to discard the pending entry.
3254 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); 3271 EXPECT_TRUE(controller.RemoveEntryAtIndex(0));
3255 EXPECT_FALSE(controller.GetPendingEntry()); 3272 EXPECT_FALSE(controller.GetPendingEntry());
3256 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3273 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3257 3274
3258 // We should update the last committed entry index. 3275 // We should update the last committed entry index.
3259 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 3276 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
3260 3277
3261 // Now commit and ensure we land on the right entry. 3278 // Now commit and ensure we land on the right entry.
3262 main_test_rfh()->PrepareForCommit(); 3279 main_test_rfh()->PrepareForCommit();
3263 main_test_rfh()->SendNavigate(entry_id, false, url2); 3280 main_test_rfh()->SendNavigateWithTransition(entry_id, false, url2,
3281 entry_transition);
3264 EXPECT_EQ(2, controller.GetEntryCount()); 3282 EXPECT_EQ(2, controller.GetEntryCount());
3265 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3283 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3266 EXPECT_FALSE(controller.GetPendingEntry()); 3284 EXPECT_FALSE(controller.GetPendingEntry());
3267 } 3285 }
3268 3286
3269 // Tests the transient entry, making sure it goes away with all navigations. 3287 // Tests the transient entry, making sure it goes away with all navigations.
3270 TEST_F(NavigationControllerTest, TransientEntry) { 3288 TEST_F(NavigationControllerTest, TransientEntry) {
3271 NavigationControllerImpl& controller = controller_impl(); 3289 NavigationControllerImpl& controller = controller_impl();
3272 TestNotificationTracker notifications; 3290 TestNotificationTracker notifications;
3273 RegisterForAllNavNotifications(&notifications, &controller); 3291 RegisterForAllNavNotifications(&notifications, &controller);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3356 EXPECT_FALSE(controller.CanGoForward()); 3374 EXPECT_FALSE(controller.CanGoForward());
3357 controller.GoBack(); 3375 controller.GoBack();
3358 // Transient entry should be gone. 3376 // Transient entry should be gone.
3359 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 3377 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
3360 EXPECT_EQ(controller.GetEntryCount(), 5); 3378 EXPECT_EQ(controller.GetEntryCount(), 5);
3361 3379
3362 // Suppose the page requested a history navigation backward. 3380 // Suppose the page requested a history navigation backward.
3363 controller.GoToOffset(-1); 3381 controller.GoToOffset(-1);
3364 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3382 entry_id = controller.GetPendingEntry()->GetUniqueID();
3365 main_test_rfh()->PrepareForCommit(); 3383 main_test_rfh()->PrepareForCommit();
3366 main_test_rfh()->SendNavigate(entry_id, false, url3); 3384 main_test_rfh()->SendNavigateWithTransition(
3385 entry_id, false, url3, controller.GetPendingEntry()->GetTransitionType());
3367 3386
3368 // Add a transient and go to an entry before the current one. 3387 // Add a transient and go to an entry before the current one.
3369 transient_entry.reset(new NavigationEntryImpl); 3388 transient_entry.reset(new NavigationEntryImpl);
3370 transient_entry->SetURL(transient_url); 3389 transient_entry->SetURL(transient_url);
3371 controller.SetTransientEntry(std::move(transient_entry)); 3390 controller.SetTransientEntry(std::move(transient_entry));
3372 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 3391 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
3373 controller.GoToIndex(1); 3392 controller.GoToIndex(1);
3374 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3393 entry_id = controller.GetPendingEntry()->GetUniqueID();
3375 // The navigation should have been initiated, transient entry should be gone. 3394 // The navigation should have been initiated, transient entry should be gone.
3376 EXPECT_FALSE(controller.GetTransientEntry()); 3395 EXPECT_FALSE(controller.GetTransientEntry());
3377 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3396 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
3378 // Visible entry does not update for history navigations until commit. 3397 // Visible entry does not update for history navigations until commit.
3379 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 3398 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
3380 main_test_rfh()->PrepareForCommit(); 3399 main_test_rfh()->PrepareForCommit();
3381 main_test_rfh()->SendNavigate(entry_id, false, url1); 3400 main_test_rfh()->SendNavigateWithTransition(
3401 entry_id, false, url1, controller.GetPendingEntry()->GetTransitionType());
3382 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 3402 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
3383 3403
3384 // Add a transient and go to an entry after the current one. 3404 // Add a transient and go to an entry after the current one.
3385 transient_entry.reset(new NavigationEntryImpl); 3405 transient_entry.reset(new NavigationEntryImpl);
3386 transient_entry->SetURL(transient_url); 3406 transient_entry->SetURL(transient_url);
3387 controller.SetTransientEntry(std::move(transient_entry)); 3407 controller.SetTransientEntry(std::move(transient_entry));
3388 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 3408 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
3389 controller.GoToIndex(3); 3409 controller.GoToIndex(3);
3390 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3410 entry_id = controller.GetPendingEntry()->GetUniqueID();
3391 // The navigation should have been initiated, transient entry should be gone. 3411 // The navigation should have been initiated, transient entry should be gone.
3392 // Because of the transient entry that is removed, going to index 3 makes us 3412 // Because of the transient entry that is removed, going to index 3 makes us
3393 // land on url2 (which is visible after the commit). 3413 // land on url2 (which is visible after the commit).
3394 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); 3414 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
3395 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 3415 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
3396 main_test_rfh()->PrepareForCommit(); 3416 main_test_rfh()->PrepareForCommit();
3397 main_test_rfh()->SendNavigate(entry_id, false, url2); 3417 main_test_rfh()->SendNavigateWithTransition(
3418 entry_id, false, url2, controller.GetPendingEntry()->GetTransitionType());
3398 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3419 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3399 3420
3400 // Add a transient and go forward. 3421 // Add a transient and go forward.
3401 transient_entry.reset(new NavigationEntryImpl); 3422 transient_entry.reset(new NavigationEntryImpl);
3402 transient_entry->SetURL(transient_url); 3423 transient_entry->SetURL(transient_url);
3403 controller.SetTransientEntry(std::move(transient_entry)); 3424 controller.SetTransientEntry(std::move(transient_entry));
3404 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 3425 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
3405 EXPECT_TRUE(controller.CanGoForward()); 3426 EXPECT_TRUE(controller.CanGoForward());
3406 controller.GoForward(); 3427 controller.GoForward();
3407 entry_id = controller.GetPendingEntry()->GetUniqueID(); 3428 entry_id = controller.GetPendingEntry()->GetUniqueID();
3408 // We should have navigated, transient entry should be gone. 3429 // We should have navigated, transient entry should be gone.
3409 EXPECT_FALSE(controller.GetTransientEntry()); 3430 EXPECT_FALSE(controller.GetTransientEntry());
3410 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); 3431 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL());
3411 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3432 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3412 main_test_rfh()->PrepareForCommit(); 3433 main_test_rfh()->PrepareForCommit();
3413 main_test_rfh()->SendNavigate(entry_id, false, url3); 3434 main_test_rfh()->SendNavigateWithTransition(
3435 entry_id, false, url3, controller.GetPendingEntry()->GetTransitionType());
3414 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 3436 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
3415 3437
3416 // Add a transient and do an in-page navigation, replacing the current entry. 3438 // Add a transient and do an in-page navigation, replacing the current entry.
3417 transient_entry.reset(new NavigationEntryImpl); 3439 transient_entry.reset(new NavigationEntryImpl);
3418 transient_entry->SetURL(transient_url); 3440 transient_entry->SetURL(transient_url);
3419 controller.SetTransientEntry(std::move(transient_entry)); 3441 controller.SetTransientEntry(std::move(transient_entry));
3420 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 3442 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
3421 3443
3422 main_test_rfh()->SendNavigate(0, false, url3_ref); 3444 main_test_rfh()->SendNavigate(0, false, url3_ref);
3423 // Transient entry should be gone. 3445 // Transient entry should be gone.
(...skipping 1937 matching lines...) Expand 10 before | Expand all | Expand 10 after
5361 ASSERT_EQ(2, controller.GetEntryCount()); 5383 ASSERT_EQ(2, controller.GetEntryCount());
5362 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 5384 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
5363 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 5385 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
5364 EXPECT_EQ(nullptr, controller.GetPendingEntry()); 5386 EXPECT_EQ(nullptr, controller.GetPendingEntry());
5365 EXPECT_EQ(nullptr, controller.GetTransientEntry()); 5387 EXPECT_EQ(nullptr, controller.GetTransientEntry());
5366 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL()); 5388 EXPECT_EQ(url_0, controller.GetEntryAtIndex(0)->GetURL());
5367 EXPECT_EQ(url_1, controller.GetEntryAtIndex(1)->GetURL()); 5389 EXPECT_EQ(url_1, controller.GetEntryAtIndex(1)->GetURL());
5368 } 5390 }
5369 5391
5370 } // namespace content 5392 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698