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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 3122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3133 shell()->web_contents()->GetController().GoBack(); | 3133 shell()->web_contents()->GetController().GoBack(); |
3134 back_load_observer.Wait(); | 3134 back_load_observer.Wait(); |
3135 } | 3135 } |
3136 EXPECT_EQ(redirect_dest_url, root->current_url()); | 3136 EXPECT_EQ(redirect_dest_url, root->current_url()); |
3137 EXPECT_EQ(0U, root->child_count()); | 3137 EXPECT_EQ(0U, root->child_count()); |
3138 EXPECT_EQ(0U, entry2->root_node()->children.size()); | 3138 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
3139 EXPECT_EQ(4, controller.GetEntryCount()); | 3139 EXPECT_EQ(4, controller.GetEntryCount()); |
3140 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 3140 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
3141 } | 3141 } |
3142 | 3142 |
| 3143 // Similar to FrameNavigationEntry_BackWithRedirect but with same-origin frames. |
| 3144 // (This wasn't working initially). |
| 3145 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 3146 FrameNavigationEntry_SameOriginBackWithRedirect) { |
| 3147 // 1. Start on a page with an iframe. |
| 3148 GURL initial_url(embedded_test_server()->GetURL( |
| 3149 "/navigation_controller/page_with_data_iframe.html")); |
| 3150 EXPECT_TRUE(NavigateToURL(shell(), initial_url)); |
| 3151 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( |
| 3152 shell()->web_contents()->GetController()); |
| 3153 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 3154 ->GetFrameTree() |
| 3155 ->root(); |
| 3156 EXPECT_EQ(initial_url, root->current_url()); |
| 3157 EXPECT_EQ(1U, root->child_count()); |
| 3158 NavigationEntryImpl* entry1 = controller.GetLastCommittedEntry(); |
| 3159 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) |
| 3160 EXPECT_EQ(1U, entry1->root_node()->children.size()); |
| 3161 |
| 3162 // 2. Navigate the iframe to a page with a nested iframe. |
| 3163 GURL frame_url(embedded_test_server()->GetURL( |
| 3164 "/navigation_controller/page_with_data_iframe.html")); |
| 3165 GURL data_url("data:text/html,Subframe"); |
| 3166 NavigateFrameToURL(root->child_at(0), frame_url); |
| 3167 EXPECT_EQ(initial_url, root->current_url()); |
| 3168 EXPECT_EQ(frame_url, root->child_at(0)->current_url()); |
| 3169 EXPECT_EQ(data_url, root->child_at(0)->child_at(0)->current_url()); |
| 3170 |
| 3171 EXPECT_EQ(2, controller.GetEntryCount()); |
| 3172 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 3173 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); |
| 3174 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 3175 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 3176 NavigationEntryImpl::TreeNode* root_node = entry2->root_node(); |
| 3177 ASSERT_EQ(1U, root_node->children.size()); |
| 3178 EXPECT_EQ(frame_url, root_node->children[0]->frame_entry->url()); |
| 3179 EXPECT_EQ(data_url, |
| 3180 root_node->children[0]->children[0]->frame_entry->url()); |
| 3181 } |
| 3182 |
| 3183 // Cause the iframe to redirect when we come back later. It will go |
| 3184 // same-origin to a page with an about:blank iframe. |
| 3185 GURL frame_redirect_dest_url(embedded_test_server()->GetURL( |
| 3186 "/navigation_controller/page_with_iframe.html")); |
| 3187 { |
| 3188 TestNavigationObserver observer(shell()->web_contents()); |
| 3189 std::string script = "history.replaceState({}, '', '/server-redirect?" + |
| 3190 frame_redirect_dest_url.spec() + "')"; |
| 3191 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 3192 observer.Wait(); |
| 3193 } |
| 3194 |
| 3195 // We should not have lost subframe entries for the nested frame. |
| 3196 EXPECT_EQ(2, controller.GetEntryCount()); |
| 3197 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 3198 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 3199 FrameNavigationEntry* nested_entry = |
| 3200 entry2->GetFrameEntry(root->child_at(0)->child_at(0)); |
| 3201 EXPECT_TRUE(nested_entry); |
| 3202 EXPECT_EQ(data_url, nested_entry->url()); |
| 3203 } |
| 3204 |
| 3205 // 3. Navigate the main frame to a different page. When we come back, we'll |
| 3206 // commit the main frame first and have no pending entry when navigating the |
| 3207 // subframes. |
| 3208 GURL url2(embedded_test_server()->GetURL( |
| 3209 "/navigation_controller/simple_page_1.html")); |
| 3210 EXPECT_TRUE(NavigateToURL(shell(), url2)); |
| 3211 EXPECT_EQ(3, controller.GetEntryCount()); |
| 3212 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 3213 |
| 3214 // 4. Go back. The first iframe should redirect to a same-origin page with a |
| 3215 // different nested iframe. |
| 3216 { |
| 3217 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 3218 controller.GoBack(); |
| 3219 back_load_observer.Wait(); |
| 3220 } |
| 3221 GURL blank_url(url::kAboutBlankURL); |
| 3222 EXPECT_EQ(initial_url, root->current_url()); |
| 3223 EXPECT_EQ(frame_redirect_dest_url, root->child_at(0)->current_url()); |
| 3224 EXPECT_EQ(blank_url, root->child_at(0)->child_at(0)->current_url()); |
| 3225 |
| 3226 // Check the FrameNavigationEntries as well. |
| 3227 EXPECT_EQ(3, controller.GetEntryCount()); |
| 3228 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 3229 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 3230 EXPECT_EQ(frame_redirect_dest_url, |
| 3231 entry2->GetFrameEntry(root->child_at(0))->url()); |
| 3232 EXPECT_EQ(blank_url, |
| 3233 entry2->GetFrameEntry(root->child_at(0)->child_at(0))->url()); |
| 3234 } |
| 3235 |
| 3236 // Now cause the main frame to redirect to a page with no frames when we come |
| 3237 // back to it. |
| 3238 GURL redirect_dest_url(embedded_test_server()->GetURL( |
| 3239 "/navigation_controller/simple_page_2.html")); |
| 3240 { |
| 3241 TestNavigationObserver observer(shell()->web_contents()); |
| 3242 std::string script = "history.replaceState({}, '', '/server-redirect?" + |
| 3243 redirect_dest_url.spec() + "')"; |
| 3244 EXPECT_TRUE(ExecuteScript(root, script)); |
| 3245 observer.Wait(); |
| 3246 } |
| 3247 |
| 3248 // 5. Navigate the main frame to a different page. |
| 3249 EXPECT_TRUE(NavigateToURL(shell(), url2)); |
| 3250 EXPECT_EQ(3, controller.GetEntryCount()); |
| 3251 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 3252 |
| 3253 // 6. Go back, causing the main frame to redirect to a page with no frames. |
| 3254 // All child items should be gone. |
| 3255 { |
| 3256 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 3257 controller.GoBack(); |
| 3258 back_load_observer.Wait(); |
| 3259 } |
| 3260 EXPECT_EQ(redirect_dest_url, root->current_url()); |
| 3261 EXPECT_EQ(0U, root->child_count()); |
| 3262 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
| 3263 EXPECT_EQ(3, controller.GetEntryCount()); |
| 3264 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 3265 } |
| 3266 |
3143 // Verify that subframes can be restored in a new NavigationController using the | 3267 // Verify that subframes can be restored in a new NavigationController using the |
3144 // PageState of an existing NavigationEntry. | 3268 // PageState of an existing NavigationEntry. |
3145 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 3269 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
3146 FrameNavigationEntry_RestoreViaPageState) { | 3270 FrameNavigationEntry_RestoreViaPageState) { |
3147 // 1. Start on a page with a data URL iframe. | 3271 // 1. Start on a page with a data URL iframe. |
3148 GURL main_url_a(embedded_test_server()->GetURL( | 3272 GURL main_url_a(embedded_test_server()->GetURL( |
3149 "a.com", "/navigation_controller/page_with_data_iframe.html")); | 3273 "a.com", "/navigation_controller/page_with_data_iframe.html")); |
3150 GURL data_url("data:text/html,Subframe"); | 3274 GURL data_url("data:text/html,Subframe"); |
3151 NavigateToURL(shell(), main_url_a); | 3275 NavigateToURL(shell(), main_url_a); |
3152 const NavigationControllerImpl& controller = | 3276 const NavigationControllerImpl& controller = |
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5205 std::string body; | 5329 std::string body; |
5206 EXPECT_TRUE(ExecuteScriptAndExtractString( | 5330 EXPECT_TRUE(ExecuteScriptAndExtractString( |
5207 shell()->web_contents(), | 5331 shell()->web_contents(), |
5208 "window.domAutomationController.send(" | 5332 "window.domAutomationController.send(" |
5209 "document.getElementsByTagName('pre')[0].innerText);", | 5333 "document.getElementsByTagName('pre')[0].innerText);", |
5210 &body)); | 5334 &body)); |
5211 EXPECT_EQ("text=value\n", body); | 5335 EXPECT_EQ("text=value\n", body); |
5212 } | 5336 } |
5213 | 5337 |
5214 } // namespace content | 5338 } // namespace content |
OLD | NEW |