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

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

Issue 663183003: Revert of Drop CreateChildFrame messages when swapping out. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 2 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 | « content/browser/frame_host/render_frame_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/browser/frame_host/cross_site_transferring_request.h" 9 #include "content/browser/frame_host/cross_site_transferring_request.h"
10 #include "content/browser/frame_host/navigation_before_commit_info.h" 10 #include "content/browser/frame_host/navigation_before_commit_info.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 124
125 private: 125 private:
126 int process_id_; 126 int process_id_;
127 int routing_id_; 127 int routing_id_;
128 bool deleted_; 128 bool deleted_;
129 129
130 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); 130 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver);
131 }; 131 };
132 132
133 // This observer keeps track of the last created RenderFrameHost to allow tests
134 // to ensure that no RenderFrameHost objects are created when not expected.
135 class RenderFrameHostCreatedObserver : public WebContentsObserver {
136 public:
137 RenderFrameHostCreatedObserver(WebContents* web_contents)
138 : WebContentsObserver(web_contents),
139 created_(false) {
140 }
141
142 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) override {
143 created_ = true;
144 }
145
146 bool created() {
147 return created_;
148 }
149
150 private:
151 bool created_;
152
153 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostCreatedObserver);
154 };
155
156 // This observer keeps track of the last deleted RenderFrameHost to avoid 133 // This observer keeps track of the last deleted RenderFrameHost to avoid
157 // accessing it and causing use-after-free condition. 134 // accessing it and causing use-after-free condition.
158 class RenderFrameHostDeletedObserver : public WebContentsObserver { 135 class RenderFrameHostDeletedObserver : public WebContentsObserver {
159 public: 136 public:
160 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) 137 RenderFrameHostDeletedObserver(RenderFrameHost* rfh)
161 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), 138 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)),
162 process_id_(rfh->GetProcess()->GetID()), 139 process_id_(rfh->GetProcess()->GetID()),
163 routing_id_(rfh->GetRoutingID()), 140 routing_id_(rfh->GetRoutingID()),
164 deleted_(false) { 141 deleted_(false) {
165 } 142 }
(...skipping 10 matching lines...) Expand all
176 } 153 }
177 154
178 private: 155 private:
179 int process_id_; 156 int process_id_;
180 int routing_id_; 157 int routing_id_;
181 bool deleted_; 158 bool deleted_;
182 159
183 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); 160 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver);
184 }; 161 };
185 162
163
186 // This observer is used to check whether IPC messages are being filtered for 164 // This observer is used to check whether IPC messages are being filtered for
187 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon 165 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon
188 // update events, which the FilterMessagesWhileSwappedOut test simulates being 166 // update events, which the FilterMessagesWhileSwappedOut test simulates being
189 // sent. The test is successful if the event is not observed. 167 // sent. The test is successful if the event is not observed.
190 // See http://crbug.com/351815 168 // See http://crbug.com/351815
191 class PluginFaviconMessageObserver : public WebContentsObserver { 169 class PluginFaviconMessageObserver : public WebContentsObserver {
192 public: 170 public:
193 PluginFaviconMessageObserver(WebContents* web_contents) 171 PluginFaviconMessageObserver(WebContents* web_contents)
194 : WebContentsObserver(web_contents), 172 : WebContentsObserver(web_contents),
195 plugin_crashed_(false), 173 plugin_crashed_(false),
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 // Also test RunJavaScriptMessage. 547 // Also test RunJavaScriptMessage.
570 ntp_process_host->sink().ClearMessages(); 548 ntp_process_host->sink().ClearMessages();
571 FrameHostMsg_RunJavaScriptMessage js_msg( 549 FrameHostMsg_RunJavaScriptMessage js_msg(
572 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL, 550 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL,
573 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); 551 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused);
574 js_msg.EnableMessagePumping(); 552 js_msg.EnableMessagePumping();
575 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg)); 553 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg));
576 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); 554 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
577 } 555 }
578 556
579 // Ensure that frames aren't added to the frame tree, if the message is coming
580 // from a process different than the parent frame's current RenderFrameHost
581 // process. Otherwise it is possible to have collisions of routing ids, as they
582 // are scoped per process. See https://crbug.com/415059.
583 TEST_F(RenderFrameHostManagerTest, DropCreateChildFrameWhileSwappedOut) {
584 const GURL kUrl1("http://foo.com");
585 const GURL kUrl2("http://www.google.com/");
586
587 // Navigate to the first site.
588 NavigateActiveAndCommit(kUrl1);
589 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame();
590 {
591 RenderFrameHostCreatedObserver observer(contents());
592 initial_rfh->OnCreateChildFrame(
593 initial_rfh->GetProcess()->GetNextRoutingID(), std::string());
594 EXPECT_TRUE(observer.created());
595 }
596
597 // Create one more frame in the same SiteInstance where initial_rfh
598 // exists so that initial_rfh doesn't get deleted on navigation to another
599 // site.
600 initial_rfh->GetSiteInstance()->increment_active_frame_count();
601
602 // Navigate to a cross-site URL.
603 NavigateActiveAndCommit(kUrl2);
604 EXPECT_TRUE(initial_rfh->is_swapped_out());
605
606 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame();
607 ASSERT_TRUE(dest_rfh);
608 EXPECT_NE(initial_rfh, dest_rfh);
609
610 {
611 // Since the old RFH is now swapped out, it shouldn't process any messages
612 // to create child frames.
613 RenderFrameHostCreatedObserver observer(contents());
614 initial_rfh->OnCreateChildFrame(
615 initial_rfh->GetProcess()->GetNextRoutingID(), std::string());
616 EXPECT_FALSE(observer.created());
617 }
618 }
619
620 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { 557 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) {
621 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost(); 558 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost();
622 TestRenderWidgetHostView* swapped_out_rwhv = 559 TestRenderWidgetHostView* swapped_out_rwhv =
623 static_cast<TestRenderWidgetHostView*>(swapped_out_rvh->GetView()); 560 static_cast<TestRenderWidgetHostView*>(swapped_out_rvh->GetView());
624 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); 561 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame());
625 562
626 MockRenderProcessHost* process_host = 563 MockRenderProcessHost* process_host =
627 static_cast<MockRenderProcessHost*>(swapped_out_rvh->GetProcess()); 564 static_cast<MockRenderProcessHost*>(swapped_out_rvh->GetProcess());
628 process_host->sink().ClearMessages(); 565 process_host->sink().ClearMessages();
629 566
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 1854 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
1918 1855
1919 // Confirms that a valid, request-matching commit is correctly processed. 1856 // Confirms that a valid, request-matching commit is correctly processed.
1920 nbc_info.navigation_url = kUrl2; 1857 nbc_info.navigation_url = kUrl2;
1921 nbc_info.navigation_request_id = request_id2; 1858 nbc_info.navigation_request_id = request_id2;
1922 render_manager->CommitNavigation(nbc_info); 1859 render_manager->CommitNavigation(nbc_info);
1923 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 1860 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
1924 } 1861 }
1925 1862
1926 } // namespace content 1863 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698