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

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

Issue 642813007: Drop CreateChildFrame messages when swapping out. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
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/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/frame_host/cross_site_transferring_request.h" 10 #include "content/browser/frame_host/cross_site_transferring_request.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 142
143 private: 143 private:
144 int process_id_; 144 int process_id_;
145 int routing_id_; 145 int routing_id_;
146 bool deleted_; 146 bool deleted_;
147 147
148 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); 148 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver);
149 }; 149 };
150 150
151 // This observer keeps track of the last created RenderFrameHost to allow tests
152 // to ensure that no RenderFrameHost objects are created when not expected.
153 class RenderFrameHostCreatedObserver : public WebContentsObserver {
154 public:
155 RenderFrameHostCreatedObserver(WebContents* web_contents)
156 : WebContentsObserver(web_contents),
157 created_(false) {
158 }
159
160 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) override {
161 created_ = true;
162 }
163
164 bool created() {
165 return created_;
166 }
167
168 private:
169 bool created_;
170
171 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostCreatedObserver);
172 };
173
151 // This observer keeps track of the last deleted RenderFrameHost to avoid 174 // This observer keeps track of the last deleted RenderFrameHost to avoid
152 // accessing it and causing use-after-free condition. 175 // accessing it and causing use-after-free condition.
153 class RenderFrameHostDeletedObserver : public WebContentsObserver { 176 class RenderFrameHostDeletedObserver : public WebContentsObserver {
154 public: 177 public:
155 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) 178 RenderFrameHostDeletedObserver(RenderFrameHost* rfh)
156 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), 179 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)),
157 process_id_(rfh->GetProcess()->GetID()), 180 process_id_(rfh->GetProcess()->GetID()),
158 routing_id_(rfh->GetRoutingID()), 181 routing_id_(rfh->GetRoutingID()),
159 deleted_(false) { 182 deleted_(false) {
160 } 183 }
(...skipping 10 matching lines...) Expand all
171 } 194 }
172 195
173 private: 196 private:
174 int process_id_; 197 int process_id_;
175 int routing_id_; 198 int routing_id_;
176 bool deleted_; 199 bool deleted_;
177 200
178 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); 201 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver);
179 }; 202 };
180 203
181
182 // This observer is used to check whether IPC messages are being filtered for 204 // This observer is used to check whether IPC messages are being filtered for
183 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon 205 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon
184 // update events, which the FilterMessagesWhileSwappedOut test simulates being 206 // update events, which the FilterMessagesWhileSwappedOut test simulates being
185 // sent. The test is successful if the event is not observed. 207 // sent. The test is successful if the event is not observed.
186 // See http://crbug.com/351815 208 // See http://crbug.com/351815
187 class PluginFaviconMessageObserver : public WebContentsObserver { 209 class PluginFaviconMessageObserver : public WebContentsObserver {
188 public: 210 public:
189 PluginFaviconMessageObserver(WebContents* web_contents) 211 PluginFaviconMessageObserver(WebContents* web_contents)
190 : WebContentsObserver(web_contents), 212 : WebContentsObserver(web_contents),
191 plugin_crashed_(false), 213 plugin_crashed_(false),
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // Also test RunJavaScriptMessage. 582 // Also test RunJavaScriptMessage.
561 ntp_process_host->sink().ClearMessages(); 583 ntp_process_host->sink().ClearMessages();
562 FrameHostMsg_RunJavaScriptMessage js_msg( 584 FrameHostMsg_RunJavaScriptMessage js_msg(
563 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL, 585 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL,
564 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); 586 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused);
565 js_msg.EnableMessagePumping(); 587 js_msg.EnableMessagePumping();
566 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg)); 588 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg));
567 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); 589 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
568 } 590 }
569 591
592 TEST_F(RenderFrameHostManagerTest, DropCreateChildFrameWhileSwappedOut) {
Charlie Reis 2014/10/15 23:54:18 Can you add a comment here mentioning the duplicat
nasko 2014/10/16 17:08:36 Done.
593 const GURL kUrl1("http://foo.com");
594 const GURL kUrl2("http://www.google.com/");
595
596 // Navigate first to one site and then cross-site.
Charlie Reis 2014/10/15 23:54:18 nit: Drop "and then cross-site" since it's not don
nasko 2014/10/16 17:08:36 Done.
597 NavigateActiveAndCommit(kUrl1);
598 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame();
599
600 {
601 RenderFrameHostCreatedObserver observer(contents());
602 initial_rfh->OnCreateChildFrame(3, std::string());
603 EXPECT_TRUE(observer.created());
604 }
605 // Create one more frame in the same SiteInstance where initial_rfh
Charlie Reis 2014/10/15 23:54:18 nit: Either add a blank line above this or remove
nasko 2014/10/16 17:08:36 Done.
606 // exists so that it doesn't get deleted on navigation to another
Charlie Reis 2014/10/15 23:54:18 nit: it -> initial_rfh (It's a little ambiguous a
nasko 2014/10/16 17:08:36 Done.
607 // site.
608 initial_rfh->GetSiteInstance()->increment_active_frame_count();
609
610 // Navigate to a cross-site URL.
611 NavigateActiveAndCommit(kUrl2);
612 EXPECT_TRUE(initial_rfh->is_swapped_out());
613
614 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame();
615 ASSERT_TRUE(dest_rfh);
616 EXPECT_NE(initial_rfh, dest_rfh);
617
618 {
619 // Since the old RFH is now swapped out, it shouldn't process any messages
620 // to create child frames.
621 RenderFrameHostCreatedObserver observer(contents());
622 initial_rfh->OnCreateChildFrame(
623 initial_rfh->GetProcess()->GetNextRoutingID(), std::string());
624 EXPECT_FALSE(observer.created());
625 }
626 }
627
570 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { 628 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) {
571 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); 629 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost();
572 TestRenderWidgetHostView* swapped_out_rwhv = 630 TestRenderWidgetHostView* swapped_out_rwhv =
573 static_cast<TestRenderWidgetHostView*>( 631 static_cast<TestRenderWidgetHostView*>(
574 swapped_out_rfh->GetRenderViewHost()->GetView()); 632 swapped_out_rfh->GetRenderViewHost()->GetView());
575 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); 633 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame());
576 634
577 MockRenderProcessHost* process_host = 635 MockRenderProcessHost* process_host =
578 static_cast<MockRenderProcessHost*>(swapped_out_rfh->GetProcess()); 636 static_cast<MockRenderProcessHost*>(swapped_out_rfh->GetProcess());
579 process_host->sink().ClearMessages(); 637 process_host->sink().ClearMessages();
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 pending_rfh->GetSiteInstance()->increment_active_frame_count(); 1793 pending_rfh->GetSiteInstance()->increment_active_frame_count();
1736 1794
1737 contents()->GetMainFrame()->OnMessageReceived( 1795 contents()->GetMainFrame()->OnMessageReceived(
1738 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); 1796 FrameHostMsg_BeforeUnload_ACK(0, false, now, now));
1739 EXPECT_FALSE(contents()->cross_navigation_pending()); 1797 EXPECT_FALSE(contents()->cross_navigation_pending());
1740 EXPECT_FALSE(rfh_deleted_observer.deleted()); 1798 EXPECT_FALSE(rfh_deleted_observer.deleted());
1741 } 1799 }
1742 } 1800 }
1743 1801
1744 } // namespace content 1802 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698