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

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

Issue 2546533007: Store the last committed origin in RenderFrameHostImpl. (Closed)
Patch Set: Rebase (and remove DCHECK) Created 4 years 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
(...skipping 2929 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 2940
2941 // In the bug, after the back navigation the popup was still showing 2941 // In the bug, after the back navigation the popup was still showing
2942 // the sad tab. Ensure this is not the case. 2942 // the sad tab. Ensure this is not the case.
2943 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, 2943 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
2944 popup->web_contents()->GetCrashedStatus()); 2944 popup->web_contents()->GetCrashedStatus());
2945 EXPECT_TRUE(popup->web_contents()->GetMainFrame()->IsRenderFrameLive()); 2945 EXPECT_TRUE(popup->web_contents()->GetMainFrame()->IsRenderFrameLive());
2946 EXPECT_EQ(popup->web_contents()->GetMainFrame()->GetSiteInstance(), 2946 EXPECT_EQ(popup->web_contents()->GetMainFrame()->GetSiteInstance(),
2947 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); 2947 shell()->web_contents()->GetMainFrame()->GetSiteInstance());
2948 } 2948 }
2949 2949
2950 // Verify that GetLastCommittedOrigin() is correct for the full lifetime of a
2951 // RenderFrameHost, including when it's pending, current, and pending deletion.
2952 // This is checked both for main frames and subframes. See
2953 // https://crbug.com/590035.
2954 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, LastCommittedOrigin) {
2955 StartEmbeddedServer();
2956 GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html"));
2957 EXPECT_TRUE(NavigateToURL(shell(), url_a));
2958
2959 WebContentsImpl* web_contents =
2960 static_cast<WebContentsImpl*>(shell()->web_contents());
2961 FrameTreeNode* root = web_contents->GetFrameTree()->root();
2962 RenderFrameHostImpl* rfh_a = root->current_frame_host();
2963 rfh_a->DisableSwapOutTimerForTesting();
2964
2965 EXPECT_EQ(url::Origin(url_a), rfh_a->GetLastCommittedOrigin());
2966 EXPECT_EQ(rfh_a, web_contents->GetMainFrame());
2967
2968 // Start a navigation to a b.com URL, and don't wait for commit.
2969 GURL url_b(embedded_test_server()->GetURL("b.com", "/title2.html"));
2970 TestFrameNavigationObserver commit_observer(root);
2971 RenderFrameDeletedObserver deleted_observer(rfh_a);
2972 shell()->LoadURL(url_b);
2973
2974 // The pending RFH shouln't have a last committed origin (the default value
2975 // is a unique origin). The current RFH shouldn't change its last committed
2976 // origin before commit.
2977 RenderFrameHostImpl* rfh_b =
2978 IsBrowserSideNavigationEnabled()
2979 ? root->render_manager()->speculative_frame_host()
2980 : root->render_manager()->pending_frame_host();
2981 EXPECT_EQ("null", rfh_b->GetLastCommittedOrigin().Serialize());
2982 EXPECT_EQ(url::Origin(url_a), rfh_a->GetLastCommittedOrigin());
2983
2984 // Verify that the last committed origin is set for the b.com RHF once it
2985 // commits.
2986 commit_observer.WaitForCommit();
2987 EXPECT_EQ(url::Origin(url_b), rfh_b->GetLastCommittedOrigin());
2988 EXPECT_EQ(rfh_b, web_contents->GetMainFrame());
2989
2990 // The old RFH should now be pending deletion. Verify it still has correct
2991 // last committed origin.
2992 EXPECT_EQ(url::Origin(url_a), rfh_a->GetLastCommittedOrigin());
2993 EXPECT_FALSE(rfh_a->is_active());
2994
2995 // Wait for |rfh_a| to be deleted and double-check |rfh_b|'s origin.
2996 deleted_observer.WaitUntilDeleted();
2997 EXPECT_EQ(url::Origin(url_b), rfh_b->GetLastCommittedOrigin());
2998
2999 // Navigate to a same-origin page with an about:blank iframe. The iframe
3000 // should also have a b.com origin.
3001 GURL url_b_with_frame(embedded_test_server()->GetURL(
3002 "b.com", "/navigation_controller/page_with_iframe.html"));
3003 EXPECT_TRUE(NavigateToURL(shell(), url_b_with_frame));
3004 EXPECT_EQ(rfh_b, web_contents->GetMainFrame());
3005 EXPECT_EQ(url::Origin(url_b), rfh_b->GetLastCommittedOrigin());
3006 FrameTreeNode* child = root->child_at(0);
3007 RenderFrameHostImpl* child_rfh_b = root->child_at(0)->current_frame_host();
3008 child_rfh_b->DisableSwapOutTimerForTesting();
3009 EXPECT_EQ(url::Origin(url_b), child_rfh_b->GetLastCommittedOrigin());
3010
3011 // Navigate subframe to c.com. Wait for commit but not full load, and then
3012 // verify the subframe's origin.
3013 GURL url_c(embedded_test_server()->GetURL("c.com", "/title3.html"));
3014 {
3015 TestFrameNavigationObserver commit_observer(root->child_at(0));
3016 EXPECT_TRUE(
3017 ExecuteScript(child, "location.href = '" + url_c.spec() + "';"));
3018 commit_observer.WaitForCommit();
3019 }
3020 EXPECT_EQ(url::Origin(url_c),
3021 child->current_frame_host()->GetLastCommittedOrigin());
3022
3023 // With OOPIFs, this navigation used a cross-process transfer. Ensure that
3024 // the iframe's old RFH still has correct origin, even though it's pending
3025 // deletion.
3026 if (AreAllSitesIsolatedForTesting()) {
3027 EXPECT_FALSE(child_rfh_b->is_active());
3028 EXPECT_NE(child_rfh_b, child->current_frame_host());
3029 EXPECT_EQ(url::Origin(url_b), child_rfh_b->GetLastCommittedOrigin());
3030 }
3031 }
3032
2950 } // namespace content 3033 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698