OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 // Ensure that frames aren't added to the frame tree, if the message is coming |
| 593 // from a process different than the parent frame's current RenderFrameHost |
| 594 // process. Otherwise it is possible to have collisions of routing ids, as they |
| 595 // are scoped per process. See https://crbug.com/415059. |
| 596 TEST_F(RenderFrameHostManagerTest, DropCreateChildFrameWhileSwappedOut) { |
| 597 const GURL kUrl1("http://foo.com"); |
| 598 const GURL kUrl2("http://www.google.com/"); |
| 599 |
| 600 // Navigate to the first site. |
| 601 NavigateActiveAndCommit(kUrl1); |
| 602 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame(); |
| 603 { |
| 604 RenderFrameHostCreatedObserver observer(contents()); |
| 605 initial_rfh->OnCreateChildFrame( |
| 606 initial_rfh->GetProcess()->GetNextRoutingID(), std::string()); |
| 607 EXPECT_TRUE(observer.created()); |
| 608 } |
| 609 |
| 610 // Create one more frame in the same SiteInstance where initial_rfh |
| 611 // exists so that initial_rfh doesn't get deleted on navigation to another |
| 612 // site. |
| 613 initial_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 614 |
| 615 // Navigate to a cross-site URL. |
| 616 NavigateActiveAndCommit(kUrl2); |
| 617 EXPECT_TRUE(initial_rfh->is_swapped_out()); |
| 618 |
| 619 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); |
| 620 ASSERT_TRUE(dest_rfh); |
| 621 EXPECT_NE(initial_rfh, dest_rfh); |
| 622 |
| 623 { |
| 624 // Since the old RFH is now swapped out, it shouldn't process any messages |
| 625 // to create child frames. |
| 626 RenderFrameHostCreatedObserver observer(contents()); |
| 627 initial_rfh->OnCreateChildFrame( |
| 628 initial_rfh->GetProcess()->GetNextRoutingID(), std::string()); |
| 629 EXPECT_FALSE(observer.created()); |
| 630 } |
| 631 } |
| 632 |
570 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { | 633 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { |
571 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); | 634 TestRenderFrameHost* swapped_out_rfh = CreateSwappedOutRenderFrameHost(); |
572 TestRenderWidgetHostView* swapped_out_rwhv = | 635 TestRenderWidgetHostView* swapped_out_rwhv = |
573 static_cast<TestRenderWidgetHostView*>( | 636 static_cast<TestRenderWidgetHostView*>( |
574 swapped_out_rfh->GetRenderViewHost()->GetView()); | 637 swapped_out_rfh->GetRenderViewHost()->GetView()); |
575 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); | 638 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); |
576 | 639 |
577 MockRenderProcessHost* process_host = | 640 MockRenderProcessHost* process_host = |
578 static_cast<MockRenderProcessHost*>(swapped_out_rfh->GetProcess()); | 641 static_cast<MockRenderProcessHost*>(swapped_out_rfh->GetProcess()); |
579 process_host->sink().ClearMessages(); | 642 process_host->sink().ClearMessages(); |
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1798 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
1736 | 1799 |
1737 contents()->GetMainFrame()->OnMessageReceived( | 1800 contents()->GetMainFrame()->OnMessageReceived( |
1738 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1801 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
1739 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1802 EXPECT_FALSE(contents()->cross_navigation_pending()); |
1740 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1803 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
1741 } | 1804 } |
1742 } | 1805 } |
1743 | 1806 |
1744 } // namespace content | 1807 } // namespace content |
OLD | NEW |