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/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 Loading... |
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 |
133 // This observer keeps track of the last deleted RenderFrameHost to avoid | 156 // This observer keeps track of the last deleted RenderFrameHost to avoid |
134 // accessing it and causing use-after-free condition. | 157 // accessing it and causing use-after-free condition. |
135 class RenderFrameHostDeletedObserver : public WebContentsObserver { | 158 class RenderFrameHostDeletedObserver : public WebContentsObserver { |
136 public: | 159 public: |
137 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) | 160 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) |
138 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), | 161 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), |
139 process_id_(rfh->GetProcess()->GetID()), | 162 process_id_(rfh->GetProcess()->GetID()), |
140 routing_id_(rfh->GetRoutingID()), | 163 routing_id_(rfh->GetRoutingID()), |
141 deleted_(false) { | 164 deleted_(false) { |
142 } | 165 } |
(...skipping 10 matching lines...) Expand all Loading... |
153 } | 176 } |
154 | 177 |
155 private: | 178 private: |
156 int process_id_; | 179 int process_id_; |
157 int routing_id_; | 180 int routing_id_; |
158 bool deleted_; | 181 bool deleted_; |
159 | 182 |
160 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); | 183 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); |
161 }; | 184 }; |
162 | 185 |
163 | |
164 // This observer is used to check whether IPC messages are being filtered for | 186 // This observer is used to check whether IPC messages are being filtered for |
165 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon | 187 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon |
166 // update events, which the FilterMessagesWhileSwappedOut test simulates being | 188 // update events, which the FilterMessagesWhileSwappedOut test simulates being |
167 // sent. The test is successful if the event is not observed. | 189 // sent. The test is successful if the event is not observed. |
168 // See http://crbug.com/351815 | 190 // See http://crbug.com/351815 |
169 class PluginFaviconMessageObserver : public WebContentsObserver { | 191 class PluginFaviconMessageObserver : public WebContentsObserver { |
170 public: | 192 public: |
171 PluginFaviconMessageObserver(WebContents* web_contents) | 193 PluginFaviconMessageObserver(WebContents* web_contents) |
172 : WebContentsObserver(web_contents), | 194 : WebContentsObserver(web_contents), |
173 plugin_crashed_(false), | 195 plugin_crashed_(false), |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 // Also test RunJavaScriptMessage. | 569 // Also test RunJavaScriptMessage. |
548 ntp_process_host->sink().ClearMessages(); | 570 ntp_process_host->sink().ClearMessages(); |
549 FrameHostMsg_RunJavaScriptMessage js_msg( | 571 FrameHostMsg_RunJavaScriptMessage js_msg( |
550 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL, | 572 ntp_rfh->GetRoutingID(), msg, msg, kChromeURL, |
551 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); | 573 JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused); |
552 js_msg.EnableMessagePumping(); | 574 js_msg.EnableMessagePumping(); |
553 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg)); | 575 EXPECT_TRUE(ntp_rfh->OnMessageReceived(js_msg)); |
554 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); | 576 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID)); |
555 } | 577 } |
556 | 578 |
| 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 |
557 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { | 620 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { |
558 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost(); | 621 TestRenderViewHost* swapped_out_rvh = CreateSwappedOutRenderViewHost(); |
559 TestRenderWidgetHostView* swapped_out_rwhv = | 622 TestRenderWidgetHostView* swapped_out_rwhv = |
560 static_cast<TestRenderWidgetHostView*>(swapped_out_rvh->GetView()); | 623 static_cast<TestRenderWidgetHostView*>(swapped_out_rvh->GetView()); |
561 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); | 624 EXPECT_FALSE(swapped_out_rwhv->did_swap_compositor_frame()); |
562 | 625 |
563 MockRenderProcessHost* process_host = | 626 MockRenderProcessHost* process_host = |
564 static_cast<MockRenderProcessHost*>(swapped_out_rvh->GetProcess()); | 627 static_cast<MockRenderProcessHost*>(swapped_out_rvh->GetProcess()); |
565 process_host->sink().ClearMessages(); | 628 process_host->sink().ClearMessages(); |
566 | 629 |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1917 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1855 | 1918 |
1856 // Confirms that a valid, request-matching commit is correctly processed. | 1919 // Confirms that a valid, request-matching commit is correctly processed. |
1857 nbc_info.navigation_url = kUrl2; | 1920 nbc_info.navigation_url = kUrl2; |
1858 nbc_info.navigation_request_id = request_id2; | 1921 nbc_info.navigation_request_id = request_id2; |
1859 render_manager->CommitNavigation(nbc_info); | 1922 render_manager->CommitNavigation(nbc_info); |
1860 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); | 1923 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
1861 } | 1924 } |
1862 | 1925 |
1863 } // namespace content | 1926 } // namespace content |
OLD | NEW |