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

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

Issue 281653003: DRAFT CL: Add FrameNavigationEntry and track subframe session histories. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 5 years, 9 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 | Annotate | Revision Log
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 "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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/frame_host/cross_site_transferring_request.h" 14 #include "content/browser/frame_host/cross_site_transferring_request.h"
15 #include "content/browser/frame_host/frame_navigation_entry.h"
15 #include "content/browser/frame_host/navigation_controller_impl.h" 16 #include "content/browser/frame_host/navigation_controller_impl.h"
16 #include "content/browser/frame_host/navigation_entry_impl.h" 17 #include "content/browser/frame_host/navigation_entry_impl.h"
17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 18 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
18 #include "content/browser/frame_host/navigation_request.h" 19 #include "content/browser/frame_host/navigation_request.h"
19 #include "content/browser/frame_host/navigator.h" 20 #include "content/browser/frame_host/navigator.h"
20 #include "content/browser/frame_host/navigator_impl.h" 21 #include "content/browser/frame_host/navigator_impl.h"
21 #include "content/browser/site_instance_impl.h" 22 #include "content/browser/site_instance_impl.h"
22 #include "content/browser/web_contents/web_contents_impl.h" 23 #include "content/browser/web_contents/web_contents_impl.h"
23 #include "content/common/frame_messages.h" 24 #include "content/common/frame_messages.h"
24 #include "content/common/view_messages.h" 25 #include "content/common/view_messages.h"
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); 1592 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true);
1592 main_test_rfh()->PrepareForCommit(); 1593 main_test_rfh()->PrepareForCommit();
1593 main_test_rfh()->SendNavigate(2, kUrl3); 1594 main_test_rfh()->SendNavigate(2, kUrl3);
1594 1595
1595 // With nothing pending, say we get a renderer back navigation request to the 1596 // With nothing pending, say we get a renderer back navigation request to the
1596 // second entry. 1597 // second entry.
1597 controller.GoToOffset(-1); 1598 controller.GoToOffset(-1);
1598 main_test_rfh()->PrepareForCommit(); 1599 main_test_rfh()->PrepareForCommit();
1599 main_test_rfh()->SendNavigate(1, kUrl2); 1600 main_test_rfh()->SendNavigate(1, kUrl2);
1600 1601
1601 // We know all the entries have the same site instance, so we can just grab
1602 // a random one for looking up other entries.
1603 SiteInstance* site_instance =
1604 controller.GetLastCommittedEntry()->site_instance();
1605
1606 // That second URL should be the last committed and it should have gotten the 1602 // That second URL should be the last committed and it should have gotten the
1607 // new title. 1603 // new title.
1608 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); 1604 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(1)->GetURL());
1609 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1605 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1610 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1606 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1611 1607
1612 // Now go forward to the last item again and say it was committed. 1608 // Now go forward to the last item again and say it was committed.
1613 controller.GoForward(); 1609 controller.GoForward();
1614 main_test_rfh()->PrepareForCommit(); 1610 main_test_rfh()->PrepareForCommit();
1615 main_test_rfh()->SendNavigate(2, kUrl3); 1611 main_test_rfh()->SendNavigate(2, kUrl3);
1616 1612
1617 // Now start going back one to the second page. It will be pending. 1613 // Now start going back one to the second page. It will be pending.
1618 controller.GoBack(); 1614 controller.GoBack();
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 } 1921 }
1926 1922
1927 // Tests navigation via link click within a subframe. A new navigation entry 1923 // Tests navigation via link click within a subframe. A new navigation entry
1928 // should be created. 1924 // should be created.
1929 TEST_F(NavigationControllerTest, NewSubframe) { 1925 TEST_F(NavigationControllerTest, NewSubframe) {
1930 NavigationControllerImpl& controller = controller_impl(); 1926 NavigationControllerImpl& controller = controller_impl();
1931 TestNotificationTracker notifications; 1927 TestNotificationTracker notifications;
1932 RegisterForAllNavNotifications(&notifications, &controller); 1928 RegisterForAllNavNotifications(&notifications, &controller);
1933 1929
1934 const GURL url1("http://foo1"); 1930 const GURL url1("http://foo1");
1935 main_test_rfh()->SendNavigate(0, url1); 1931 main_test_rfh()->SendNavigate(-1, url1);
1936 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1932 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1937 navigation_entry_committed_counter_ = 0; 1933 navigation_entry_committed_counter_ = 0;
1934 EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID());
1938 1935
1939 const GURL url2("http://foo2"); 1936 // Add a subframe to navigate, with an initial page.
1937 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
1938 SandboxFlags::NONE);
1939 RenderFrameHostImpl* subframe =
1940 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
1941 {
1942 const GURL url2("http://foo2");
1943 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1944 params.page_id = 1;
1945 params.url = url2;
1946 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
1947 params.should_update_history = false;
1948 params.gesture = NavigationGestureUser;
1949 params.is_post = false;
1950 params.page_state = PageState::CreateFromURL(url2);
1951 LoadCommittedDetails details;
1952 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
1953 EXPECT_EQ(0U, notifications.size());
1954 }
1955
1956 const GURL url3("http://foo3");
1940 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1957 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1941 params.page_id = 1; 1958 params.page_id = -1;
1942 params.url = url2; 1959 params.url = url3;
1943 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 1960 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
1944 params.should_update_history = false; 1961 params.should_update_history = false;
1945 params.gesture = NavigationGestureUser; 1962 params.gesture = NavigationGestureUser;
1946 params.is_post = false; 1963 params.is_post = false;
1947 params.page_state = PageState::CreateFromURL(url2); 1964 params.page_state = PageState::CreateFromURL(url3);
1948 1965
1949 LoadCommittedDetails details; 1966 LoadCommittedDetails details;
1950 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1967 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
1951 &details));
1952 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1968 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1953 navigation_entry_committed_counter_ = 0; 1969 navigation_entry_committed_counter_ = 0;
1954 EXPECT_EQ(url1, details.previous_url); 1970 EXPECT_EQ(url1, details.previous_url);
1955 EXPECT_FALSE(details.is_in_page); 1971 EXPECT_FALSE(details.is_in_page);
1956 EXPECT_FALSE(details.is_main_frame); 1972 EXPECT_FALSE(details.is_main_frame);
1957 1973
1958 // The new entry should be appended. 1974 // The new entry should be appended.
1959 EXPECT_EQ(2, controller.GetEntryCount()); 1975 EXPECT_EQ(2, controller.GetEntryCount());
1960 1976
1961 // New entry should refer to the new page, but the old URL (entries only 1977 // The new entry should have a page ID for the new page, but the entry's URL
1962 // reflect the toplevel URL). 1978 // is for the top level and shouldn't change.
1963 EXPECT_EQ(url1, details.entry->GetURL()); 1979 NavigationEntryImpl* entry = static_cast<NavigationEntryImpl*>(details.entry);
1964 EXPECT_EQ(params.page_id, details.entry->GetPageID()); 1980 EXPECT_EQ(url1, entry->GetURL());
1981 EXPECT_EQ(2, entry->GetPageID());
1982 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get();
1983 EXPECT_EQ(url1, root_entry->url());
1984
1985 // The subframe's FrameNavigationEntry should have the new URL.
1986 ASSERT_EQ(1U, entry->root_node()->children.size());
1987 FrameNavigationEntry* frame_entry =
1988 entry->root_node()->children[0]->frame_entry.get();
1989 EXPECT_EQ(url3, frame_entry->url());
1965 } 1990 }
1966 1991
1967 // Auto subframes are ones the page loads automatically like ads. They should 1992 // Auto subframes are ones the page loads automatically like ads. They should
1968 // not create new navigation entries. 1993 // not create new navigation entries.
1969 TEST_F(NavigationControllerTest, AutoSubframe) { 1994 TEST_F(NavigationControllerTest, AutoSubframe) {
1970 NavigationControllerImpl& controller = controller_impl(); 1995 NavigationControllerImpl& controller = controller_impl();
1971 TestNotificationTracker notifications; 1996 TestNotificationTracker notifications;
1972 RegisterForAllNavNotifications(&notifications, &controller); 1997 RegisterForAllNavNotifications(&notifications, &controller);
1973 1998
1974 const GURL url1("http://foo1"); 1999 const GURL url1("http://foo/1");
1975 main_test_rfh()->SendNavigate(0, url1); 2000 main_test_rfh()->SendNavigate(-1, url1);
1976 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2001 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1977 navigation_entry_committed_counter_ = 0; 2002 navigation_entry_committed_counter_ = 0;
2003 EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID());
1978 2004
1979 const GURL url2("http://foo2"); 2005 // Add a subframe to navigate.
2006 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2007 SandboxFlags::NONE);
2008 RenderFrameHostImpl* subframe =
2009 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
2010
2011 const GURL url2("http://foo/2");
1980 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2012 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1981 params.page_id = 0; 2013 params.page_id = 1;
1982 params.url = url2; 2014 params.url = url2;
1983 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2015 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
1984 params.should_update_history = false; 2016 params.should_update_history = false;
1985 params.gesture = NavigationGestureUser; 2017 params.gesture = NavigationGestureUser;
1986 params.is_post = false; 2018 params.is_post = false;
1987 params.page_state = PageState::CreateFromURL(url2); 2019 params.page_state = PageState::CreateFromURL(url2);
1988 2020
1989 // Navigating should do nothing. 2021 // Navigating should do nothing.
1990 LoadCommittedDetails details; 2022 LoadCommittedDetails details;
1991 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 2023 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
1992 &details));
1993 EXPECT_EQ(0U, notifications.size()); 2024 EXPECT_EQ(0U, notifications.size());
1994 2025
1995 // There should still be only one entry. 2026 // There should still be only one entry.
1996 EXPECT_EQ(1, controller.GetEntryCount()); 2027 EXPECT_EQ(1, controller.GetEntryCount());
2028 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2029 EXPECT_EQ(url1, entry->GetURL());
2030 EXPECT_EQ(1, entry->GetPageID());
2031
2032 // The entry should now have a subframe FrameNavigationEntry.
2033 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get();
2034 EXPECT_EQ(url1, root_entry->url());
2035 ASSERT_EQ(1U, entry->root_node()->children.size());
2036 FrameNavigationEntry* frame_entry =
2037 entry->root_node()->children[0]->frame_entry.get();
2038 EXPECT_EQ(url2, frame_entry->url());
1997 } 2039 }
1998 2040
1999 // Tests navigation and then going back to a subframe navigation. 2041 // Tests navigation and then going back to a subframe navigation.
2000 TEST_F(NavigationControllerTest, BackSubframe) { 2042 TEST_F(NavigationControllerTest, BackSubframe) {
2001 NavigationControllerImpl& controller = controller_impl(); 2043 NavigationControllerImpl& controller = controller_impl();
2002 TestNotificationTracker notifications; 2044 TestNotificationTracker notifications;
2003 RegisterForAllNavNotifications(&notifications, &controller); 2045 RegisterForAllNavNotifications(&notifications, &controller);
2004 2046
2005 // Main page. 2047 // Main page.
2006 const GURL url1("http://foo1"); 2048 const GURL url1("http://foo1");
2007 main_test_rfh()->SendNavigate(0, url1); 2049 main_test_rfh()->SendNavigate(-1, url1);
2008 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2050 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2009 navigation_entry_committed_counter_ = 0; 2051 navigation_entry_committed_counter_ = 0;
2052 EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID());
2053
2054 // Add a subframe with an initial page to navigate.
2055 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2056 SandboxFlags::NONE);
2057 RenderFrameHostImpl* subframe =
2058 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
2059 const GURL init_subframe_url("http://foo1/subframe");
2060 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2061 params.page_id = -1;
2062 params.url = init_subframe_url;
2063 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2064 params.should_update_history = false;
2065 params.gesture = NavigationGestureUser;
2066 params.is_post = false;
2067 params.page_state = PageState::CreateFromURL(init_subframe_url);
2068
2069 // This auto-subframe should not create a new entry.
2070 LoadCommittedDetails details;
2071 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2072 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2073 navigation_entry_committed_counter_ = 0;
2074 EXPECT_EQ(1, controller.GetEntryCount());
2075 EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID());
2010 2076
2011 // First manual subframe navigation. 2077 // First manual subframe navigation.
2012 const GURL url2("http://foo2"); 2078 const GURL url2("http://foo2");
2013 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2079 params.page_id = -1;
2014 params.page_id = 1;
2015 params.url = url2; 2080 params.url = url2;
2016 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2081 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2017 params.should_update_history = false;
2018 params.gesture = NavigationGestureUser;
2019 params.is_post = false;
2020 params.page_state = PageState::CreateFromURL(url2); 2082 params.page_state = PageState::CreateFromURL(url2);
2021 2083
2022 // This should generate a new entry. 2084 // This should generate a new entry.
2023 LoadCommittedDetails details; 2085 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2024 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2025 &details));
2026 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2086 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2027 navigation_entry_committed_counter_ = 0; 2087 navigation_entry_committed_counter_ = 0;
2028 EXPECT_EQ(2, controller.GetEntryCount()); 2088 EXPECT_EQ(2, controller.GetEntryCount());
2089 EXPECT_EQ(2, controller.GetLastCommittedEntry()->GetPageID());
2029 2090
2030 // Second manual subframe navigation should also make a new entry. 2091 // Second manual subframe navigation should also make a new entry.
2031 const GURL url3("http://foo3"); 2092 const GURL url3("http://foo3");
2032 params.page_id = 2; 2093 params.page_id = -1;
2033 params.url = url3; 2094 params.url = url3;
2034 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2095 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2035 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2096 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2036 &details));
2037 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2097 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2038 navigation_entry_committed_counter_ = 0; 2098 navigation_entry_committed_counter_ = 0;
2039 EXPECT_EQ(3, controller.GetEntryCount()); 2099 EXPECT_EQ(3, controller.GetEntryCount());
2040 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2100 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2101 EXPECT_EQ(3, controller.GetLastCommittedEntry()->GetPageID());
2041 2102
2042 // Go back one. 2103 // Go back one.
2043 controller.GoBack(); 2104 controller.GoBack();
2105 // TODO(creis): Verify shape of the pending entry's tree.
2044 params.page_id = 1; 2106 params.page_id = 1;
2045 params.url = url2; 2107 params.url = url2;
2046 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2108 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2047 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2109 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2048 &details));
2049 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2110 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2050 navigation_entry_committed_counter_ = 0; 2111 navigation_entry_committed_counter_ = 0;
2051 EXPECT_EQ(3, controller.GetEntryCount()); 2112 EXPECT_EQ(3, controller.GetEntryCount());
2052 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2113 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2053 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2114 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2054 EXPECT_FALSE(controller.GetPendingEntry()); 2115 EXPECT_FALSE(controller.GetPendingEntry());
2116 EXPECT_EQ(2, controller.GetLastCommittedEntry()->GetPageID());
2055 2117
2056 // Go back one more. 2118 // Go back one more.
2057 controller.GoBack(); 2119 controller.GoBack();
2058 params.page_id = 0; 2120 params.page_id = 0;
2059 params.url = url1; 2121 params.url = url1;
2060 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2122 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2061 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2123 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2062 &details));
2063 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2124 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2064 navigation_entry_committed_counter_ = 0; 2125 navigation_entry_committed_counter_ = 0;
2065 EXPECT_EQ(3, controller.GetEntryCount()); 2126 EXPECT_EQ(3, controller.GetEntryCount());
2066 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2127 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2067 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2128 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2068 EXPECT_FALSE(controller.GetPendingEntry()); 2129 EXPECT_FALSE(controller.GetPendingEntry());
2130 EXPECT_EQ(1, controller.GetLastCommittedEntry()->GetPageID());
2069 } 2131 }
2070 2132
2071 TEST_F(NavigationControllerTest, LinkClick) { 2133 TEST_F(NavigationControllerTest, LinkClick) {
2072 NavigationControllerImpl& controller = controller_impl(); 2134 NavigationControllerImpl& controller = controller_impl();
2073 TestNotificationTracker notifications; 2135 TestNotificationTracker notifications;
2074 RegisterForAllNavNotifications(&notifications, &controller); 2136 RegisterForAllNavNotifications(&notifications, &controller);
2075 2137
2076 const GURL url1("http://foo1"); 2138 const GURL url1("http://foo1");
2077 const GURL url2("http://foo2"); 2139 const GURL url2("http://foo2");
2078 2140
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
3274 } 3336 }
3275 3337
3276 // Some pages can have subframes with the same base URL (minus the reference) as 3338 // Some pages can have subframes with the same base URL (minus the reference) as
3277 // the main page. Even though this is hard, it can happen, and we don't want 3339 // the main page. Even though this is hard, it can happen, and we don't want
3278 // these subframe navigations to affect the toplevel document. They should 3340 // these subframe navigations to affect the toplevel document. They should
3279 // instead be ignored. http://crbug.com/5585 3341 // instead be ignored. http://crbug.com/5585
3280 TEST_F(NavigationControllerTest, SameSubframe) { 3342 TEST_F(NavigationControllerTest, SameSubframe) {
3281 NavigationControllerImpl& controller = controller_impl(); 3343 NavigationControllerImpl& controller = controller_impl();
3282 // Navigate the main frame. 3344 // Navigate the main frame.
3283 const GURL url("http://www.google.com/"); 3345 const GURL url("http://www.google.com/");
3284 main_test_rfh()->SendNavigate(0, url); 3346 main_test_rfh()->SendNavigate(-1, url);
3285 3347
3286 // We should be at the first navigation entry. 3348 // We should be at the first navigation entry.
3287 EXPECT_EQ(controller.GetEntryCount(), 1); 3349 EXPECT_EQ(1, controller.GetEntryCount());
3288 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3350 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3351
3352 // Add a subframe to navigate.
3353 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
3354 SandboxFlags::NONE);
3355 RenderFrameHostImpl* subframe =
3356 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
3289 3357
3290 // Navigate a subframe that would normally count as in-page. 3358 // Navigate a subframe that would normally count as in-page.
3291 const GURL subframe("http://www.google.com/#"); 3359 const GURL subframe_url("http://www.google.com/#");
3292 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3360 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3293 params.page_id = 0; 3361 params.page_id = 1;
3294 params.url = subframe; 3362 params.url = subframe_url;
3295 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3363 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3296 params.should_update_history = false; 3364 params.should_update_history = false;
3297 params.gesture = NavigationGestureAuto; 3365 params.gesture = NavigationGestureAuto;
3298 params.is_post = false; 3366 params.is_post = false;
3299 params.page_state = PageState::CreateFromURL(subframe); 3367 params.page_state = PageState::CreateFromURL(subframe_url);
3300 LoadCommittedDetails details; 3368 LoadCommittedDetails details;
3301 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3369 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
3302 &details));
3303 3370
3304 // Nothing should have changed. 3371 // Nothing should have changed at the top level.
3305 EXPECT_EQ(controller.GetEntryCount(), 1); 3372 EXPECT_EQ(1, controller.GetEntryCount());
3306 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3373 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3374
3375 // The entry should now have a subframe FrameNavigationEntry.
3376 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
3377 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get();
3378 EXPECT_EQ(url, root_entry->url());
3379 ASSERT_EQ(1U, entry->root_node()->children.size());
3380 FrameNavigationEntry* frame_entry =
3381 entry->root_node()->children[0]->frame_entry.get();
3382 EXPECT_EQ(subframe_url, frame_entry->url());
3307 } 3383 }
3308 3384
3309 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 3385 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
3310 // false. 3386 // false.
3311 TEST_F(NavigationControllerTest, CloneAndGoBack) { 3387 TEST_F(NavigationControllerTest, CloneAndGoBack) {
3312 NavigationControllerImpl& controller = controller_impl(); 3388 NavigationControllerImpl& controller = controller_impl();
3313 const GURL url1("http://foo1"); 3389 const GURL url1("http://foo1");
3314 const GURL url2("http://foo2"); 3390 const GURL url2("http://foo2");
3315 const base::string16 title(base::ASCIIToUTF16("Title")); 3391 const base::string16 title(base::ASCIIToUTF16("Title"));
3316 3392
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 { 4599 {
4524 LoadCommittedDetails details; 4600 LoadCommittedDetails details;
4525 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4601 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4526 EXPECT_EQ(PAGE_TYPE_ERROR, 4602 EXPECT_EQ(PAGE_TYPE_ERROR,
4527 controller_impl().GetLastCommittedEntry()->GetPageType()); 4603 controller_impl().GetLastCommittedEntry()->GetPageType());
4528 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4604 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4529 } 4605 }
4530 } 4606 }
4531 4607
4532 } // namespace content 4608 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/browser/frame_host/navigation_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698