OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 7466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7477 EXPECT_EQ(0, child_count); | 7477 EXPECT_EQ(0, child_count); |
7478 | 7478 |
7479 EXPECT_EQ( | 7479 EXPECT_EQ( |
7480 " Site A ------------ proxies for B\n" | 7480 " Site A ------------ proxies for B\n" |
7481 " +--Site B ------- proxies for A\n" | 7481 " +--Site B ------- proxies for A\n" |
7482 "Where A = http://a.com/\n" | 7482 "Where A = http://a.com/\n" |
7483 " B = http://b.com/", | 7483 " B = http://b.com/", |
7484 DepictFrameTree(root)); | 7484 DepictFrameTree(root)); |
7485 } | 7485 } |
7486 | 7486 |
7487 // Helper filter class to wait for a ShowView or ShowWidget message, record the | 7487 // Helper filter class to wait for a ShowView or ShowWidget message, record the |
alexmos
2016/12/13 18:41:40
ShowView -> ShowCreatedWindow
ncarter (slow)
2016/12/15 00:33:16
Done.
| |
7488 // routing ID from the message, and then drop the message. | 7488 // routing ID from the message, and then drop the message. |
7489 const uint32_t kMessageClasses[] = {ViewMsgStart, FrameMsgStart}; | |
7489 class PendingWidgetMessageFilter : public BrowserMessageFilter { | 7490 class PendingWidgetMessageFilter : public BrowserMessageFilter { |
7490 public: | 7491 public: |
7491 PendingWidgetMessageFilter() | 7492 PendingWidgetMessageFilter() |
7492 : BrowserMessageFilter(ViewMsgStart), | 7493 : BrowserMessageFilter(kMessageClasses, arraysize(kMessageClasses)), |
7493 routing_id_(MSG_ROUTING_NONE), | 7494 routing_id_(MSG_ROUTING_NONE), |
7494 message_loop_runner_(new MessageLoopRunner) {} | 7495 message_loop_runner_(new MessageLoopRunner) {} |
7495 | 7496 |
7496 bool OnMessageReceived(const IPC::Message& message) override { | 7497 bool OnMessageReceived(const IPC::Message& message) override { |
7497 bool handled = true; | 7498 bool handled = true; |
7498 IPC_BEGIN_MESSAGE_MAP(PendingWidgetMessageFilter, message) | 7499 IPC_BEGIN_MESSAGE_MAP(PendingWidgetMessageFilter, message) |
7499 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView) | 7500 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow) |
7500 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 7501 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
7501 IPC_MESSAGE_UNHANDLED(handled = false) | 7502 IPC_MESSAGE_UNHANDLED(handled = false) |
7502 IPC_END_MESSAGE_MAP() | 7503 IPC_END_MESSAGE_MAP() |
7503 return handled; | 7504 return handled; |
7504 } | 7505 } |
7505 | 7506 |
7506 void Wait() { | 7507 void Wait() { |
7507 message_loop_runner_->Run(); | 7508 message_loop_runner_->Run(); |
7508 } | 7509 } |
7509 | 7510 |
7510 int routing_id() { return routing_id_; } | 7511 int routing_id() { return routing_id_; } |
7511 | 7512 |
7512 private: | 7513 private: |
7513 ~PendingWidgetMessageFilter() override {} | 7514 ~PendingWidgetMessageFilter() override {} |
7514 | 7515 |
7515 void OnShowView(int routing_id, | 7516 void OnShowCreatedWindow(int pending_tab_main_frame_route_id, |
alexmos
2016/12/13 18:41:40
This is pending_widget_route_id, right?
ncarter (slow)
2016/12/15 00:33:16
Done.
| |
7516 WindowOpenDisposition disposition, | 7517 WindowOpenDisposition disposition, |
7517 const gfx::Rect& initial_rect, | 7518 const gfx::Rect& initial_rect, |
7518 bool user_gesture) { | 7519 bool user_gesture) { |
7519 content::BrowserThread::PostTask( | 7520 content::BrowserThread::PostTask( |
7520 content::BrowserThread::UI, FROM_HERE, | 7521 content::BrowserThread::UI, FROM_HERE, |
7521 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this, | 7522 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this, |
7522 routing_id)); | 7523 pending_tab_main_frame_route_id)); |
7523 } | 7524 } |
7524 | 7525 |
7525 void OnShowWidget(int routing_id, const gfx::Rect& initial_rect) { | 7526 void OnShowWidget(int routing_id, const gfx::Rect& initial_rect) { |
7526 content::BrowserThread::PostTask( | 7527 content::BrowserThread::PostTask( |
7527 content::BrowserThread::UI, FROM_HERE, | 7528 content::BrowserThread::UI, FROM_HERE, |
7528 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this, | 7529 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this, |
7529 routing_id)); | 7530 routing_id)); |
7530 } | 7531 } |
7531 | 7532 |
7532 void OnReceivedRoutingIDOnUI(int routing_id) { | 7533 void OnReceivedRoutingIDOnUI(int routing_id) { |
(...skipping 22 matching lines...) Expand all Loading... | |
7555 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); | 7556 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); |
7556 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 7557 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
7557 | 7558 |
7558 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 7559 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
7559 FrameTreeNode* child1 = root->child_at(0); | 7560 FrameTreeNode* child1 = root->child_at(0); |
7560 FrameTreeNode* child2 = root->child_at(1); | 7561 FrameTreeNode* child2 = root->child_at(1); |
7561 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess(); | 7562 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess(); |
7562 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess(); | 7563 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess(); |
7563 | 7564 |
7564 // Call window.open simultaneously in both subframes to create two popups. | 7565 // Call window.open simultaneously in both subframes to create two popups. |
7565 // Wait for and then drop both ViewHostMsg_ShowView messages. This will | 7566 // Wait for and then drop both ViewHostMsg_ShowView messages. This will |
alexmos
2016/12/13 18:41:40
Update the IPC here
ncarter (slow)
2016/12/15 00:33:16
Done.
| |
7566 // ensure that both CreateNewWindow calls happen before either | 7567 // ensure that both CreateNewWindow calls happen before either |
7567 // ShowCreatedWindow call. | 7568 // ShowCreatedWindow call. |
7568 scoped_refptr<PendingWidgetMessageFilter> filter1 = | 7569 scoped_refptr<PendingWidgetMessageFilter> filter1 = |
7569 new PendingWidgetMessageFilter(); | 7570 new PendingWidgetMessageFilter(); |
7570 process1->AddFilter(filter1.get()); | 7571 process1->AddFilter(filter1.get()); |
7571 EXPECT_TRUE(ExecuteScript(child1, "window.open();")); | 7572 EXPECT_TRUE(ExecuteScript(child1, "window.open();")); |
7572 filter1->Wait(); | 7573 filter1->Wait(); |
7573 | 7574 |
7574 scoped_refptr<PendingWidgetMessageFilter> filter2 = | 7575 scoped_refptr<PendingWidgetMessageFilter> filter2 = |
7575 new PendingWidgetMessageFilter(); | 7576 new PendingWidgetMessageFilter(); |
7576 process2->AddFilter(filter2.get()); | 7577 process2->AddFilter(filter2.get()); |
7577 EXPECT_TRUE(ExecuteScript(child2, "window.open();")); | 7578 EXPECT_TRUE(ExecuteScript(child2, "window.open();")); |
7578 filter2->Wait(); | 7579 filter2->Wait(); |
7579 | 7580 |
7580 // At this point, we should have two pending WebContents. | 7581 // At this point, we should have two pending WebContents. |
7581 EXPECT_TRUE(base::ContainsKey( | 7582 EXPECT_TRUE(base::ContainsKey( |
7582 web_contents()->pending_contents_, | 7583 web_contents()->pending_contents_, |
7583 std::make_pair(process1->GetID(), filter1->routing_id()))); | 7584 std::make_pair(process1->GetID(), filter1->routing_id()))); |
7584 EXPECT_TRUE(base::ContainsKey( | 7585 EXPECT_TRUE(base::ContainsKey( |
7585 web_contents()->pending_contents_, | 7586 web_contents()->pending_contents_, |
7586 std::make_pair(process2->GetID(), filter2->routing_id()))); | 7587 std::make_pair(process2->GetID(), filter2->routing_id()))); |
7587 | 7588 |
7588 // Both subframes were set up in the same way, so the next routing ID for the | 7589 // Both subframes were set up in the same way, so the next routing ID for the |
7589 // new popup windows should match up (this led to the collision in the | 7590 // new popup windows should match up (this led to the collision in the |
7590 // pending contents map in the original bug). | 7591 // pending contents map in the original bug). |
7591 EXPECT_EQ(filter1->routing_id(), filter2->routing_id()); | 7592 EXPECT_EQ(filter1->routing_id(), filter2->routing_id()); |
7592 | 7593 |
7593 // Now, simulate that both ShowView messages arrive by showing both of the | 7594 // Now, simulate that both ShowView messages arrive by showing both of the |
alexmos
2016/12/13 18:41:40
Ditto
ncarter (slow)
2016/12/15 00:33:16
Done.
| |
7594 // pending WebContents. | 7595 // pending WebContents. |
7595 web_contents()->ShowCreatedWindow(process1->GetID(), filter1->routing_id(), | 7596 web_contents()->ShowCreatedWindow(process1->GetID(), filter1->routing_id(), |
7596 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 7597 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
7597 gfx::Rect(), true); | 7598 gfx::Rect(), true); |
7598 web_contents()->ShowCreatedWindow(process2->GetID(), filter2->routing_id(), | 7599 web_contents()->ShowCreatedWindow(process2->GetID(), filter2->routing_id(), |
7599 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 7600 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
7600 gfx::Rect(), true); | 7601 gfx::Rect(), true); |
7601 | 7602 |
7602 // Verify that both shells were properly created. | 7603 // Verify that both shells were properly created. |
7603 EXPECT_EQ(3u, Shell::windows().size()); | 7604 EXPECT_EQ(3u, Shell::windows().size()); |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8798 | 8799 |
8799 // Ensure that the iframe reuses its parent's process. | 8800 // Ensure that the iframe reuses its parent's process. |
8800 EXPECT_EQ(blank_url, child->current_url()); | 8801 EXPECT_EQ(blank_url, child->current_url()); |
8801 EXPECT_EQ(root->current_frame_host()->GetSiteInstance(), | 8802 EXPECT_EQ(root->current_frame_host()->GetSiteInstance(), |
8802 child->current_frame_host()->GetSiteInstance()); | 8803 child->current_frame_host()->GetSiteInstance()); |
8803 EXPECT_EQ(root->current_frame_host()->GetProcess(), | 8804 EXPECT_EQ(root->current_frame_host()->GetProcess(), |
8804 child->current_frame_host()->GetProcess()); | 8805 child->current_frame_host()->GetProcess()); |
8805 } | 8806 } |
8806 | 8807 |
8807 } // namespace content | 8808 } // namespace content |
OLD | NEW |