OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
(...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 capturer.Wait(); | 1952 capturer.Wait(); |
1953 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 1953 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
1954 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 1954 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
1955 } | 1955 } |
1956 EXPECT_EQ(3, controller.GetEntryCount()); | 1956 EXPECT_EQ(3, controller.GetEntryCount()); |
1957 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1957 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1958 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); | 1958 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); |
1959 | 1959 |
1960 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 1960 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
1961 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 1961 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
1962 // The entry should have a new FrameNavigationEntries for the subframe. | 1962 // The entry should have a FrameNavigationEntry for the subframe. |
1963 ASSERT_EQ(1U, entry2->root_node()->children.size()); | 1963 ASSERT_EQ(1U, entry2->root_node()->children.size()); |
1964 EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url()); | 1964 EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url()); |
1965 } else { | 1965 } else { |
1966 // There are no subframe FrameNavigationEntries by default. | 1966 // There are no subframe FrameNavigationEntries by default. |
1967 EXPECT_EQ(0U, entry2->root_node()->children.size()); | 1967 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
1968 } | 1968 } |
1969 | 1969 |
1970 // 5. Go back in the subframe again to the parent page's site. | 1970 // 5. Go back in the subframe again to the parent page's site. |
1971 { | 1971 { |
1972 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 1972 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
1973 shell()->web_contents()->GetController().GoBack(); | 1973 shell()->web_contents()->GetController().GoBack(); |
1974 capturer.Wait(); | 1974 capturer.Wait(); |
1975 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 1975 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
1976 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 1976 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
1977 } | 1977 } |
1978 EXPECT_EQ(3, controller.GetEntryCount()); | 1978 EXPECT_EQ(3, controller.GetEntryCount()); |
1979 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1979 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1980 EXPECT_EQ(entry1, controller.GetLastCommittedEntry()); | 1980 EXPECT_EQ(entry1, controller.GetLastCommittedEntry()); |
1981 | 1981 |
1982 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 1982 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
1983 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 1983 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
1984 // The entry should have a new FrameNavigationEntries for the subframe. | 1984 // The entry should have a FrameNavigationEntry for the subframe. |
1985 ASSERT_EQ(1U, entry1->root_node()->children.size()); | 1985 ASSERT_EQ(1U, entry1->root_node()->children.size()); |
1986 EXPECT_EQ(frame_url, entry1->root_node()->children[0]->frame_entry->url()); | 1986 EXPECT_EQ(frame_url, entry1->root_node()->children[0]->frame_entry->url()); |
1987 } else { | 1987 } else { |
1988 // There are no subframe FrameNavigationEntries by default. | 1988 // There are no subframe FrameNavigationEntries by default. |
1989 EXPECT_EQ(0U, entry1->root_node()->children.size()); | 1989 EXPECT_EQ(0U, entry1->root_node()->children.size()); |
1990 } | 1990 } |
1991 | 1991 |
1992 // 6. Go forward in the subframe cross-site. | 1992 // 6. Go forward in the subframe cross-site. |
1993 { | 1993 { |
1994 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 1994 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
1995 shell()->web_contents()->GetController().GoForward(); | 1995 shell()->web_contents()->GetController().GoForward(); |
1996 capturer.Wait(); | 1996 capturer.Wait(); |
1997 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 1997 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
1998 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 1998 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
1999 } | 1999 } |
2000 EXPECT_EQ(3, controller.GetEntryCount()); | 2000 EXPECT_EQ(3, controller.GetEntryCount()); |
2001 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2001 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
2002 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); | 2002 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); |
2003 | 2003 |
2004 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 2004 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
2005 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 2005 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
2006 // The entry should have a new FrameNavigationEntries for the subframe. | 2006 // The entry should have a FrameNavigationEntry for the subframe. |
2007 ASSERT_EQ(1U, entry2->root_node()->children.size()); | 2007 ASSERT_EQ(1U, entry2->root_node()->children.size()); |
2008 EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url()); | 2008 EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url()); |
2009 } else { | 2009 } else { |
2010 // There are no subframe FrameNavigationEntries by default. | 2010 // There are no subframe FrameNavigationEntries by default. |
2011 EXPECT_EQ(0U, entry2->root_node()->children.size()); | 2011 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
2012 } | 2012 } |
2013 | 2013 |
2014 // 7. Go forward in the subframe again, cross-site. | 2014 // 7. Go forward in the subframe again, cross-site. |
2015 { | 2015 { |
2016 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 2016 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
2017 shell()->web_contents()->GetController().GoForward(); | 2017 shell()->web_contents()->GetController().GoForward(); |
2018 capturer.Wait(); | 2018 capturer.Wait(); |
2019 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); | 2019 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.params().transition); |
2020 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); | 2020 EXPECT_EQ(NAVIGATION_TYPE_AUTO_SUBFRAME, capturer.details().type); |
2021 } | 2021 } |
2022 EXPECT_EQ(3, controller.GetEntryCount()); | 2022 EXPECT_EQ(3, controller.GetEntryCount()); |
2023 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2023 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
2024 EXPECT_EQ(entry3, controller.GetLastCommittedEntry()); | 2024 EXPECT_EQ(entry3, controller.GetLastCommittedEntry()); |
2025 | 2025 |
2026 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 2026 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
2027 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 2027 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
2028 // The entry should have a new FrameNavigationEntries for the subframe. | 2028 // The entry should have a FrameNavigationEntry for the subframe. |
2029 ASSERT_EQ(1U, entry3->root_node()->children.size()); | 2029 ASSERT_EQ(1U, entry3->root_node()->children.size()); |
2030 EXPECT_EQ(frame_url3, entry3->root_node()->children[0]->frame_entry->url()); | 2030 EXPECT_EQ(frame_url3, entry3->root_node()->children[0]->frame_entry->url()); |
2031 } else { | 2031 } else { |
2032 // There are no subframe FrameNavigationEntries by default. | 2032 // There are no subframe FrameNavigationEntries by default. |
2033 EXPECT_EQ(0U, entry3->root_node()->children.size()); | 2033 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
2034 } | 2034 } |
2035 } | 2035 } |
2036 | 2036 |
| 2037 // Verify the tree of FrameNavigationEntries after subframes are recreated in |
| 2038 // history navigations, including nested frames. The history will look like: |
| 2039 // 1. initial_url |
| 2040 // 2. main_url_a (data_url) |
| 2041 // 3. main_url_a (frame_url_b (data_url)) |
| 2042 // 4. main_url_a (frame_url_b (frame_url_c)) |
| 2043 // 5. main_url_d |
| 2044 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 2045 FrameNavigationEntry_RecreatedSubframeBackForward) { |
| 2046 // 1. Start on a page with no frames. |
| 2047 GURL initial_url(embedded_test_server()->GetURL( |
| 2048 "/navigation_controller/simple_page_1.html")); |
| 2049 NavigateToURL(shell(), initial_url); |
| 2050 const NavigationControllerImpl& controller = |
| 2051 static_cast<const NavigationControllerImpl&>( |
| 2052 shell()->web_contents()->GetController()); |
| 2053 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 2054 ->GetFrameTree() |
| 2055 ->root(); |
| 2056 EXPECT_EQ(initial_url, root->current_url()); |
| 2057 NavigationEntryImpl* entry1 = controller.GetLastCommittedEntry(); |
| 2058 EXPECT_EQ(0U, entry1->root_node()->children.size()); |
| 2059 |
| 2060 // 2. Navigate to a page with a data URL iframe. |
| 2061 GURL main_url_a(embedded_test_server()->GetURL( |
| 2062 "a.com", "/navigation_controller/page_with_data_iframe.html")); |
| 2063 GURL data_url("data:text/html,Subframe"); |
| 2064 NavigateToURL(shell(), main_url_a); |
| 2065 ASSERT_EQ(1U, root->child_count()); |
| 2066 ASSERT_EQ(0U, root->child_at(0)->child_count()); |
| 2067 EXPECT_EQ(main_url_a, root->current_url()); |
| 2068 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 2069 |
| 2070 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2071 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2072 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); |
| 2073 |
| 2074 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2075 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2076 // The entry should have a FrameNavigationEntry for the data subframe. |
| 2077 ASSERT_EQ(1U, entry2->root_node()->children.size()); |
| 2078 EXPECT_EQ(data_url, entry2->root_node()->children[0]->frame_entry->url()); |
| 2079 } else { |
| 2080 // There are no subframe FrameNavigationEntries by default. |
| 2081 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
| 2082 } |
| 2083 |
| 2084 // 3. Navigate the iframe cross-site to a page with a nested iframe. |
| 2085 GURL frame_url_b(embedded_test_server()->GetURL( |
| 2086 "b.com", "/navigation_controller/page_with_data_iframe.html")); |
| 2087 { |
| 2088 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 2089 NavigateFrameToURL(root->child_at(0), frame_url_b); |
| 2090 capturer.Wait(); |
| 2091 } |
| 2092 ASSERT_EQ(1U, root->child_count()); |
| 2093 EXPECT_EQ(main_url_a, root->current_url()); |
| 2094 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2095 EXPECT_EQ(data_url, root->child_at(0)->child_at(0)->current_url()); |
| 2096 |
| 2097 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2098 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 2099 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); |
| 2100 |
| 2101 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2102 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2103 // The entry should have a FrameNavigationEntry for the b.com subframe. |
| 2104 ASSERT_EQ(1U, entry3->root_node()->children.size()); |
| 2105 ASSERT_EQ(1U, entry3->root_node()->children[0]->children.size()); |
| 2106 EXPECT_EQ(frame_url_b, |
| 2107 entry3->root_node()->children[0]->frame_entry->url()); |
| 2108 EXPECT_EQ( |
| 2109 data_url, |
| 2110 entry3->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2111 } else { |
| 2112 // There are no subframe FrameNavigationEntries by default. |
| 2113 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| 2114 } |
| 2115 |
| 2116 // 4. Navigate the nested iframe cross-site. |
| 2117 GURL frame_url_c(embedded_test_server()->GetURL( |
| 2118 "c.com", "/navigation_controller/simple_page_2.html")); |
| 2119 { |
| 2120 FrameNavigateParamsCapturer capturer(root->child_at(0)->child_at(0)); |
| 2121 NavigateFrameToURL(root->child_at(0)->child_at(0), frame_url_c); |
| 2122 capturer.Wait(); |
| 2123 } |
| 2124 ASSERT_EQ(1U, root->child_count()); |
| 2125 EXPECT_EQ(main_url_a, root->current_url()); |
| 2126 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2127 EXPECT_EQ(frame_url_c, root->child_at(0)->child_at(0)->current_url()); |
| 2128 |
| 2129 EXPECT_EQ(4, controller.GetEntryCount()); |
| 2130 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
| 2131 NavigationEntryImpl* entry4 = controller.GetLastCommittedEntry(); |
| 2132 |
| 2133 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2134 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2135 // The entry should have FrameNavigationEntries for the subframes. |
| 2136 ASSERT_EQ(1U, entry4->root_node()->children.size()); |
| 2137 ASSERT_EQ(1U, entry4->root_node()->children[0]->children.size()); |
| 2138 EXPECT_EQ(frame_url_b, |
| 2139 entry4->root_node()->children[0]->frame_entry->url()); |
| 2140 EXPECT_EQ( |
| 2141 frame_url_c, |
| 2142 entry4->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2143 } else { |
| 2144 // There are no subframe FrameNavigationEntries by default. |
| 2145 EXPECT_EQ(0U, entry4->root_node()->children.size()); |
| 2146 } |
| 2147 |
| 2148 // 5. Navigate main frame cross-site, destroying the frames. |
| 2149 GURL main_url_d(embedded_test_server()->GetURL( |
| 2150 "d.com", "/navigation_controller/simple_page_2.html")); |
| 2151 NavigateToURL(shell(), main_url_d); |
| 2152 ASSERT_EQ(0U, root->child_count()); |
| 2153 EXPECT_EQ(main_url_d, root->current_url()); |
| 2154 |
| 2155 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2156 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
| 2157 NavigationEntryImpl* entry5 = controller.GetLastCommittedEntry(); |
| 2158 EXPECT_EQ(0U, entry5->root_node()->children.size()); |
| 2159 |
| 2160 // 6. Go back, recreating the iframe and its nested iframe. |
| 2161 { |
| 2162 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2163 shell()->web_contents()->GetController().GoBack(); |
| 2164 back_load_observer.Wait(); |
| 2165 } |
| 2166 ASSERT_EQ(1U, root->child_count()); |
| 2167 ASSERT_EQ(1U, root->child_at(0)->child_count()); |
| 2168 EXPECT_EQ(main_url_a, root->current_url()); |
| 2169 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2170 EXPECT_EQ(frame_url_c, root->child_at(0)->child_at(0)->current_url()); |
| 2171 |
| 2172 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2173 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
| 2174 EXPECT_EQ(entry4, controller.GetLastCommittedEntry()); |
| 2175 |
| 2176 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2177 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2178 // The entry should have FrameNavigationEntries for the subframes. |
| 2179 ASSERT_EQ(1U, entry4->root_node()->children.size()); |
| 2180 ASSERT_EQ(1U, entry4->root_node()->children[0]->children.size()); |
| 2181 EXPECT_EQ(frame_url_b, |
| 2182 entry4->root_node()->children[0]->frame_entry->url()); |
| 2183 EXPECT_EQ( |
| 2184 frame_url_c, |
| 2185 entry4->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2186 } else { |
| 2187 // There are no subframe FrameNavigationEntries by default. |
| 2188 EXPECT_EQ(0U, entry4->root_node()->children.size()); |
| 2189 } |
| 2190 |
| 2191 // 7. Go back again, to the data URL in the nested iframe. |
| 2192 { |
| 2193 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2194 shell()->web_contents()->GetController().GoBack(); |
| 2195 back_load_observer.Wait(); |
| 2196 } |
| 2197 ASSERT_EQ(1U, root->child_count()); |
| 2198 ASSERT_EQ(1U, root->child_at(0)->child_count()); |
| 2199 EXPECT_EQ(main_url_a, root->current_url()); |
| 2200 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2201 EXPECT_EQ(data_url, root->child_at(0)->child_at(0)->current_url()); |
| 2202 |
| 2203 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2204 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 2205 EXPECT_EQ(entry3, controller.GetLastCommittedEntry()); |
| 2206 |
| 2207 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2208 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2209 // The entry should have FrameNavigationEntries for the subframes. |
| 2210 ASSERT_EQ(1U, entry3->root_node()->children.size()); |
| 2211 ASSERT_EQ(1U, entry3->root_node()->children[0]->children.size()); |
| 2212 EXPECT_EQ(frame_url_b, |
| 2213 entry3->root_node()->children[0]->frame_entry->url()); |
| 2214 EXPECT_EQ( |
| 2215 data_url, |
| 2216 entry3->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2217 } else { |
| 2218 // There are no subframe FrameNavigationEntries by default. |
| 2219 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| 2220 } |
| 2221 |
| 2222 // 8. Go back again, to the data URL in the first subframe. |
| 2223 { |
| 2224 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2225 shell()->web_contents()->GetController().GoBack(); |
| 2226 back_load_observer.Wait(); |
| 2227 } |
| 2228 ASSERT_EQ(1U, root->child_count()); |
| 2229 ASSERT_EQ(0U, root->child_at(0)->child_count()); |
| 2230 EXPECT_EQ(main_url_a, root->current_url()); |
| 2231 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 2232 |
| 2233 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2234 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2235 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); |
| 2236 |
| 2237 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2238 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2239 // The entry should have a FrameNavigationEntry for the subframe. |
| 2240 ASSERT_EQ(1U, entry2->root_node()->children.size()); |
| 2241 EXPECT_EQ(data_url, entry2->root_node()->children[0]->frame_entry->url()); |
| 2242 } else { |
| 2243 // There are no subframe FrameNavigationEntries by default. |
| 2244 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
| 2245 } |
| 2246 |
| 2247 // 9. Go back again, to the initial main frame page. |
| 2248 { |
| 2249 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2250 shell()->web_contents()->GetController().GoBack(); |
| 2251 back_load_observer.Wait(); |
| 2252 } |
| 2253 ASSERT_EQ(0U, root->child_count()); |
| 2254 EXPECT_EQ(initial_url, root->current_url()); |
| 2255 |
| 2256 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2257 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 2258 EXPECT_EQ(entry1, controller.GetLastCommittedEntry()); |
| 2259 EXPECT_EQ(0U, entry1->root_node()->children.size()); |
| 2260 |
| 2261 // 10. Go forward multiple entries and verify the correct subframe URLs load. |
| 2262 { |
| 2263 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2264 shell()->web_contents()->GetController().GoToOffset(2); |
| 2265 back_load_observer.Wait(); |
| 2266 } |
| 2267 ASSERT_EQ(1U, root->child_count()); |
| 2268 EXPECT_EQ(main_url_a, root->current_url()); |
| 2269 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2270 EXPECT_EQ(data_url, root->child_at(0)->child_at(0)->current_url()); |
| 2271 |
| 2272 EXPECT_EQ(5, controller.GetEntryCount()); |
| 2273 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 2274 EXPECT_EQ(entry3, controller.GetLastCommittedEntry()); |
| 2275 |
| 2276 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 2277 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 2278 // The entry should have FrameNavigationEntries for the subframes. |
| 2279 ASSERT_EQ(1U, entry3->root_node()->children.size()); |
| 2280 EXPECT_EQ(frame_url_b, |
| 2281 entry3->root_node()->children[0]->frame_entry->url()); |
| 2282 EXPECT_EQ( |
| 2283 data_url, |
| 2284 entry3->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2285 } else { |
| 2286 // There are no subframe FrameNavigationEntries by default. |
| 2287 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| 2288 } |
| 2289 } |
| 2290 |
| 2291 // Verify that we navigate to the fallback (original) URL if a subframe's |
| 2292 // FrameNavigationEntry can't be found during a history navigation. |
| 2293 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 2294 FrameNavigationEntry_SubframeHistoryFallback) { |
| 2295 // This test only makes sense when subframe FrameNavigationEntries are in use. |
| 2296 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |
| 2297 return; |
| 2298 |
| 2299 // 1. Start on a page with a data URL iframe. |
| 2300 GURL main_url_a(embedded_test_server()->GetURL( |
| 2301 "a.com", "/navigation_controller/page_with_data_iframe.html")); |
| 2302 GURL data_url("data:text/html,Subframe"); |
| 2303 NavigateToURL(shell(), main_url_a); |
| 2304 const NavigationControllerImpl& controller = |
| 2305 static_cast<const NavigationControllerImpl&>( |
| 2306 shell()->web_contents()->GetController()); |
| 2307 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 2308 ->GetFrameTree() |
| 2309 ->root(); |
| 2310 ASSERT_EQ(1U, root->child_count()); |
| 2311 ASSERT_EQ(0U, root->child_at(0)->child_count()); |
| 2312 EXPECT_EQ(main_url_a, root->current_url()); |
| 2313 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 2314 |
| 2315 EXPECT_EQ(1, controller.GetEntryCount()); |
| 2316 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 2317 NavigationEntryImpl* entry1 = controller.GetLastCommittedEntry(); |
| 2318 |
| 2319 // The entry should have a FrameNavigationEntry for the data subframe. |
| 2320 ASSERT_EQ(1U, entry1->root_node()->children.size()); |
| 2321 EXPECT_EQ(data_url, entry1->root_node()->children[0]->frame_entry->url()); |
| 2322 |
| 2323 // 2. Navigate the iframe cross-site to a page with a nested iframe. |
| 2324 GURL frame_url_b(embedded_test_server()->GetURL( |
| 2325 "b.com", "/navigation_controller/simple_page_1.html")); |
| 2326 { |
| 2327 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 2328 NavigateFrameToURL(root->child_at(0), frame_url_b); |
| 2329 capturer.Wait(); |
| 2330 } |
| 2331 ASSERT_EQ(1U, root->child_count()); |
| 2332 EXPECT_EQ(main_url_a, root->current_url()); |
| 2333 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2334 |
| 2335 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2336 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2337 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); |
| 2338 |
| 2339 // The entry should have a FrameNavigationEntry for the b.com subframe. |
| 2340 ASSERT_EQ(1U, entry2->root_node()->children.size()); |
| 2341 EXPECT_EQ(frame_url_b, entry2->root_node()->children[0]->frame_entry->url()); |
| 2342 |
| 2343 // 3. Navigate main frame cross-site, destroying the frames. |
| 2344 GURL main_url_c(embedded_test_server()->GetURL( |
| 2345 "c.com", "/navigation_controller/simple_page_2.html")); |
| 2346 NavigateToURL(shell(), main_url_c); |
| 2347 ASSERT_EQ(0U, root->child_count()); |
| 2348 EXPECT_EQ(main_url_c, root->current_url()); |
| 2349 |
| 2350 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2351 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 2352 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); |
| 2353 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| 2354 |
| 2355 // Force the subframe entry to have the wrong name, so that it isn't found |
| 2356 // when we go back. |
| 2357 entry2->root_node()->children[0]->frame_entry->set_frame_unique_name("wrong"); |
| 2358 |
| 2359 // 4. Go back, recreating the iframe. The subframe entry won't be found, and |
| 2360 // we should fall back to the default URL. |
| 2361 { |
| 2362 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2363 shell()->web_contents()->GetController().GoBack(); |
| 2364 back_load_observer.Wait(); |
| 2365 } |
| 2366 ASSERT_EQ(1U, root->child_count()); |
| 2367 EXPECT_EQ(main_url_a, root->current_url()); |
| 2368 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 2369 |
| 2370 EXPECT_EQ(3, controller.GetEntryCount()); |
| 2371 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2372 EXPECT_EQ(entry2, controller.GetLastCommittedEntry()); |
| 2373 |
| 2374 // The entry should have both the stale FrameNavigationEntry with the old |
| 2375 // name and the new FrameNavigationEntry for the fallback navigation. |
| 2376 ASSERT_EQ(2U, entry2->root_node()->children.size()); |
| 2377 EXPECT_EQ(frame_url_b, entry2->root_node()->children[0]->frame_entry->url()); |
| 2378 EXPECT_EQ(data_url, entry2->root_node()->children[1]->frame_entry->url()); |
| 2379 } |
| 2380 |
2037 // Verifies that the |frame_unique_name| is set to the correct frame, so that we | 2381 // Verifies that the |frame_unique_name| is set to the correct frame, so that we |
2038 // can match subframe FrameNavigationEntries to newly created frames after | 2382 // can match subframe FrameNavigationEntries to newly created frames after |
2039 // back/forward and restore. | 2383 // back/forward and restore. |
2040 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 2384 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
2041 FrameNavigationEntry_FrameUniqueName) { | 2385 FrameNavigationEntry_FrameUniqueName) { |
2042 const NavigationControllerImpl& controller = | 2386 const NavigationControllerImpl& controller = |
2043 static_cast<const NavigationControllerImpl&>( | 2387 static_cast<const NavigationControllerImpl&>( |
2044 shell()->web_contents()->GetController()); | 2388 shell()->web_contents()->GetController()); |
2045 | 2389 |
2046 // 1. Navigate the main frame. | 2390 // 1. Navigate the main frame. |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2599 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 2943 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
2600 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2944 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
2601 } | 2945 } |
2602 | 2946 |
2603 // Make sure the renderer is still alive. | 2947 // Make sure the renderer is still alive. |
2604 EXPECT_TRUE( | 2948 EXPECT_TRUE( |
2605 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2949 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
2606 } | 2950 } |
2607 | 2951 |
2608 } // namespace content | 2952 } // namespace content |
OLD | NEW |