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

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

Issue 2312243002: Avoid use-after-free if frame is deleted when stopping loading. (Closed)
Patch Set: Created 4 years, 3 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/renderer/render_frame_impl.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 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 3043 matching lines...) Expand 10 before | Expand all | Expand 10 after
3054 EXPECT_EQ(1, controller.GetEntryCount()); 3054 EXPECT_EQ(1, controller.GetEntryCount());
3055 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3055 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3056 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 3056 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
3057 3057
3058 // The entry should have a FrameNavigationEntry for the blank subframe. 3058 // The entry should have a FrameNavigationEntry for the blank subframe.
3059 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 3059 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
3060 ASSERT_EQ(1U, entry->root_node()->children.size()); 3060 ASSERT_EQ(1U, entry->root_node()->children.size());
3061 EXPECT_EQ(blank_url, entry->root_node()->children[0]->frame_entry->url()); 3061 EXPECT_EQ(blank_url, entry->root_node()->children[0]->frame_entry->url());
3062 } 3062 }
3063 3063
3064 // 3. Navigate the main frame, destroying the frames. 3064 // 2. Navigate the main frame, destroying the frames.
3065 GURL main_url_2(embedded_test_server()->GetURL( 3065 GURL main_url_2(embedded_test_server()->GetURL(
3066 "/navigation_controller/simple_page_1.html")); 3066 "/navigation_controller/simple_page_1.html"));
3067 EXPECT_TRUE(NavigateToURL(shell(), main_url_2)); 3067 EXPECT_TRUE(NavigateToURL(shell(), main_url_2));
3068 ASSERT_EQ(0U, root->child_count()); 3068 ASSERT_EQ(0U, root->child_count());
3069 EXPECT_EQ(main_url_2, root->current_url()); 3069 EXPECT_EQ(main_url_2, root->current_url());
3070 3070
3071 EXPECT_EQ(2, controller.GetEntryCount()); 3071 EXPECT_EQ(2, controller.GetEntryCount());
3072 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 3072 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
3073 3073
3074 // 4. Go back, recreating the iframe. 3074 // 3. Go back, recreating the iframe.
3075 { 3075 {
3076 TestNavigationObserver back_load_observer(shell()->web_contents()); 3076 TestNavigationObserver back_load_observer(shell()->web_contents());
3077 controller.GoBack(); 3077 controller.GoBack();
3078 back_load_observer.Wait(); 3078 back_load_observer.Wait();
3079 } 3079 }
3080 ASSERT_EQ(1U, root->child_count()); 3080 ASSERT_EQ(1U, root->child_count());
3081 EXPECT_EQ(main_url, root->current_url()); 3081 EXPECT_EQ(main_url, root->current_url());
3082 3082
3083 // TODO(creis): The child's current_url should be about:blank, but we're not 3083 // TODO(creis): The child's current_url should be about:blank, but we're not
3084 // currently getting a commit in this case. For now, we'll lack a commit for 3084 // currently getting a commit in this case. For now, we'll lack a commit for
(...skipping 16 matching lines...) Expand all
3101 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3101 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3102 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); 3102 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
3103 3103
3104 // The entry should have a FrameNavigationEntry for the blank subframe. 3104 // The entry should have a FrameNavigationEntry for the blank subframe.
3105 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 3105 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
3106 ASSERT_EQ(1U, entry->root_node()->children.size()); 3106 ASSERT_EQ(1U, entry->root_node()->children.size());
3107 EXPECT_EQ(blank_url, entry->root_node()->children[0]->frame_entry->url()); 3107 EXPECT_EQ(blank_url, entry->root_node()->children[0]->frame_entry->url());
3108 } 3108 }
3109 } 3109 }
3110 3110
3111 // Ensure we don't crash if an onload handler removes an about:blank frame after
3112 // recreating it on a back/forward. See https://crbug.com/638166.
3113 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
3114 FrameNavigationEntry_RemoveRecreatedBlankSubframe) {
3115 // 1. Start on a page that removes its about:blank iframe during onload.
3116 GURL main_url(embedded_test_server()->GetURL(
3117 "/navigation_controller/remove_blank_iframe_on_load.html"));
3118 GURL blank_url(url::kAboutBlankURL);
3119 EXPECT_TRUE(NavigateToURL(shell(), main_url));
3120 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>(
3121 shell()->web_contents()->GetController());
3122 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
3123 ->GetFrameTree()
3124 ->root();
3125 EXPECT_EQ(main_url, root->current_url());
3126
3127 EXPECT_EQ(1, controller.GetEntryCount());
3128 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3129 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
3130
3131 // The entry should have a FrameNavigationEntry for the blank subframe, even
3132 // though it is being removed from the page.
3133 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
3134 ASSERT_EQ(1U, entry->root_node()->children.size());
3135 EXPECT_EQ(blank_url, entry->root_node()->children[0]->frame_entry->url());
3136 }
3137
3138 // 2. Navigate the main frame, destroying the frames.
3139 GURL main_url_2(embedded_test_server()->GetURL(
3140 "/navigation_controller/simple_page_1.html"));
3141 EXPECT_TRUE(NavigateToURL(shell(), main_url_2));
3142 ASSERT_EQ(0U, root->child_count());
3143 EXPECT_EQ(main_url_2, root->current_url());
3144
3145 EXPECT_EQ(2, controller.GetEntryCount());
3146 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
3147
3148 // 3. Go back, recreating the iframe (and removing it again).
3149 {
3150 TestNavigationObserver back_load_observer(shell()->web_contents());
3151 controller.GoBack();
3152 back_load_observer.Wait();
3153 }
3154 EXPECT_EQ(main_url, root->current_url());
3155
3156 // Check that the renderer is still alive.
3157 EXPECT_TRUE(ExecuteScript(shell(), "console.log('Success');"));
3158
3159 EXPECT_EQ(2, controller.GetEntryCount());
3160 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3161 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
3162
3163 // The entry should have a FrameNavigationEntry for the blank subframe.
3164 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
3165 ASSERT_EQ(1U, entry->root_node()->children.size());
3166 EXPECT_EQ(blank_url, entry->root_node()->children[0]->frame_entry->url());
3167 }
3168 }
3169
3111 // Verifies that we clear the children FrameNavigationEntries if a history 3170 // Verifies that we clear the children FrameNavigationEntries if a history
3112 // navigation redirects, so that we don't try to load previous history items in 3171 // navigation redirects, so that we don't try to load previous history items in
3113 // frames of the new page. This should only clear the children of the frame 3172 // frames of the new page. This should only clear the children of the frame
3114 // that is redirecting. See https://crbug.com/585194. 3173 // that is redirecting. See https://crbug.com/585194.
3115 // 3174 //
3116 // Specifically, this test covers the following interesting cases: 3175 // Specifically, this test covers the following interesting cases:
3117 // - Subframe redirect when going back from a different main frame (step 4). 3176 // - Subframe redirect when going back from a different main frame (step 4).
3118 // - Subframe redirect without changing the main frame (step 6). 3177 // - Subframe redirect without changing the main frame (step 6).
3119 // - Main frame redirect, clearing the children (step 8). 3178 // - Main frame redirect, clearing the children (step 8).
3120 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 3179 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
(...skipping 2737 matching lines...) Expand 10 before | Expand all | Expand 10 after
5858 &headers)); 5917 &headers));
5859 5918
5860 // Verify the Origin and Referer headers. 5919 // Verify the Origin and Referer headers.
5861 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null")); 5920 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null"));
5862 EXPECT_THAT(headers, 5921 EXPECT_THAT(headers,
5863 ::testing::ContainsRegex( 5922 ::testing::ContainsRegex(
5864 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); 5923 "Referer: http://a.com:.*/form_that_posts_cross_site.html"));
5865 } 5924 }
5866 5925
5867 } // namespace content 5926 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698