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

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1986643002: Track pending WebContents and widgets by (process_id, routing_id) pair. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fullscreen-flash
Patch Set: Cleanup Created 4 years, 7 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 (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 6914 matching lines...) Expand 10 before | Expand all | Expand 10 after
6925 EXPECT_EQ(0, child_count); 6925 EXPECT_EQ(0, child_count);
6926 6926
6927 EXPECT_EQ( 6927 EXPECT_EQ(
6928 " Site A ------------ proxies for B\n" 6928 " Site A ------------ proxies for B\n"
6929 " +--Site B ------- proxies for A\n" 6929 " +--Site B ------- proxies for A\n"
6930 "Where A = http://a.com/\n" 6930 "Where A = http://a.com/\n"
6931 " B = http://b.com/", 6931 " B = http://b.com/",
6932 DepictFrameTree(root)); 6932 DepictFrameTree(root));
6933 } 6933 }
6934 6934
6935 // Helper filter class to wait for a ShowView or ShowWidget message, record the
6936 // routing ID from the message, and then drop the message.
6937 class PendingWidgetMessageFilter : public BrowserMessageFilter {
6938 public:
6939 PendingWidgetMessageFilter()
6940 : BrowserMessageFilter(ViewMsgStart),
6941 done_(false),
6942 routing_id_(MSG_ROUTING_NONE),
6943 message_loop_runner_(new MessageLoopRunner) {}
6944
6945 bool OnMessageReceived(const IPC::Message& message) override {
6946 bool handled = true;
6947 IPC_BEGIN_MESSAGE_MAP(PendingWidgetMessageFilter, message)
6948 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView)
6949 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget)
6950 IPC_MESSAGE_UNHANDLED(handled = false)
6951 IPC_END_MESSAGE_MAP()
6952 return handled;
6953 }
6954
6955 void Wait() {
6956 if (!done_)
ncarter (slow) 2016/05/20 23:38:01 FWIW, I don't think you need the |done_| member he
alexmos 2016/05/23 16:46:24 Ah yes, good point. Removed.
6957 message_loop_runner_->Run();
6958 }
6959
6960 int routing_id() { return routing_id_; }
6961
6962 private:
6963 ~PendingWidgetMessageFilter() override {}
6964
6965 void OnShowView(int routing_id,
6966 WindowOpenDisposition disposition,
6967 const gfx::Rect& initial_rect,
6968 bool user_gesture) {
6969 content::BrowserThread::PostTask(
6970 content::BrowserThread::UI, FROM_HERE,
6971 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this,
6972 routing_id));
6973 }
6974
6975 void OnShowWidget(int routing_id, const gfx::Rect& initial_rect) {
6976 content::BrowserThread::PostTask(
6977 content::BrowserThread::UI, FROM_HERE,
6978 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this,
6979 routing_id));
6980 }
6981
6982 void OnReceivedRoutingIDOnUI(int routing_id) {
6983 routing_id_ = routing_id;
6984 done_ = true;
6985 message_loop_runner_->Quit();
6986 }
6987
6988 bool done_;
6989 int routing_id_;
6990 scoped_refptr<MessageLoopRunner> message_loop_runner_;
6991
6992 DISALLOW_COPY_AND_ASSIGN(PendingWidgetMessageFilter);
6993 };
6994
6995 // Test for https://crbug.com/612276. Simultaneously open two new windows from
6996 // two subframes in different processes, where each subframe process's next
6997 // routing ID is the same. Make sure that both windows are created properly.
6998 //
6999 // Each new window requires two IPCs to first create it (handled by
7000 // CreateNewWindow) and then show it (ShowCreatedWindow). In the bug, both
7001 // CreateNewWindow calls arrived before the ShowCreatedWindow calls, resulting
7002 // in the two pending windows colliding in the pending WebContents map, which
7003 // used to be keyed only by routing_id.
7004 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7005 TwoSubframesCreatePopupsSimultaneously) {
7006 GURL main_url(embedded_test_server()->GetURL(
7007 "a.com", "/cross_site_iframe_factory.html?a(b,c)"));
7008 EXPECT_TRUE(NavigateToURL(shell(), main_url));
7009
7010 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
7011 FrameTreeNode* child1 = root->child_at(0);
7012 FrameTreeNode* child2 = root->child_at(1);
7013 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess();
7014 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess();
7015
7016 // Call window.open simultaneously in both subframes to create two popups.
7017 // Wait for and then drop both ViewHostMsg_ShowView messages. This will
7018 // ensure that both CreateNewWindow calls happen before either
7019 // ShowCreatedWindow call.
7020 scoped_refptr<PendingWidgetMessageFilter> filter1 =
7021 new PendingWidgetMessageFilter();
7022 process1->AddFilter(filter1.get());
7023 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), "window.open();"));
7024 filter1->Wait();
7025
7026 scoped_refptr<PendingWidgetMessageFilter> filter2 =
7027 new PendingWidgetMessageFilter();
7028 process2->AddFilter(filter2.get());
7029 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "window.open();"));
7030 filter2->Wait();
7031
7032 // At this point, we should have two pending WebContents.
7033 EXPECT_TRUE(
7034 ContainsKey(web_contents()->pending_contents_,
7035 std::make_pair(process1->GetID(), filter1->routing_id())));
7036 EXPECT_TRUE(
7037 ContainsKey(web_contents()->pending_contents_,
7038 std::make_pair(process2->GetID(), filter2->routing_id())));
7039
7040 // Both subframes were set up in the same way, so the next routing ID for the
7041 // new popup windows should match up (this led to the collision in the
7042 // pending contents map in the original bug).
7043 EXPECT_EQ(filter1->routing_id(), filter2->routing_id());
7044
7045 // Now, simulate that both ShowView messages arrive by showing both of the
7046 // pending WebContents.
7047 web_contents()->ShowCreatedWindow(process1->GetID(), filter1->routing_id(),
7048 NEW_FOREGROUND_TAB, gfx::Rect(), true);
7049 web_contents()->ShowCreatedWindow(process2->GetID(), filter2->routing_id(),
7050 NEW_FOREGROUND_TAB, gfx::Rect(), true);
ncarter (slow) 2016/05/20 23:38:01 Interesting test technique. I really worry about h
7051
7052 // Verify that both shells were properly created.
7053 EXPECT_EQ(3u, Shell::windows().size());
7054 }
7055
7056 // Test for https://crbug.com/612276. Similar to
7057 // TwoSubframesOpenWindowsSimultaneously, but use popup menu widgets instead of
7058 // windows.
7059 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7060 TwoSubframesCreatePopupMenuWidgetsSimultaneously) {
7061 GURL main_url(embedded_test_server()->GetURL(
7062 "a.com", "/cross_site_iframe_factory.html?a(b,c)"));
7063 EXPECT_TRUE(NavigateToURL(shell(), main_url));
7064
7065 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
7066 FrameTreeNode* child1 = root->child_at(0);
7067 FrameTreeNode* child2 = root->child_at(1);
7068 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess();
7069 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess();
7070
7071 // Navigate both subframes to a page with a <select> element.
7072 NavigateFrameToURL(child1, embedded_test_server()->GetURL(
7073 "b.com", "/site_isolation/page-with-select.html"));
7074 NavigateFrameToURL(child2, embedded_test_server()->GetURL(
7075 "c.com", "/site_isolation/page-with-select.html"));
7076
7077 // Open both <select> menus. This creates a popup widget in both processes.
7078 // Wait for and then drop the ViewHostMsg_ShowWidget messages, so that both
7079 // widgets are left in pending-but-not-shown state.
7080 scoped_refptr<PendingWidgetMessageFilter> filter1 =
7081 new PendingWidgetMessageFilter();
7082 process1->AddFilter(filter1.get());
7083 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), "openSelectMenu();"));
7084 filter1->Wait();
7085
7086 scoped_refptr<PendingWidgetMessageFilter> filter2 =
7087 new PendingWidgetMessageFilter();
7088 process2->AddFilter(filter2.get());
7089 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "openSelectMenu();"));
7090 filter2->Wait();
7091
7092 // At this point, we should have two pending widgets.
7093 EXPECT_TRUE(
7094 ContainsKey(web_contents()->pending_widget_views_,
7095 std::make_pair(process1->GetID(), filter1->routing_id())));
7096 EXPECT_TRUE(
7097 ContainsKey(web_contents()->pending_widget_views_,
7098 std::make_pair(process2->GetID(), filter2->routing_id())));
7099
7100 // Both subframes were set up in the same way, so the next routing ID for the
7101 // new popup widgets should match up (this led to the collision in the
7102 // pending widgets map in the original bug).
7103 EXPECT_EQ(filter1->routing_id(), filter2->routing_id());
7104
7105 // Now simulate both widgets being shown.
7106 web_contents()->ShowCreatedWidget(process1->GetID(), filter1->routing_id(),
7107 false, gfx::Rect());
7108 web_contents()->ShowCreatedWidget(process2->GetID(), filter2->routing_id(),
7109 false, gfx::Rect());
7110 EXPECT_FALSE(
7111 ContainsKey(web_contents()->pending_widget_views_,
7112 std::make_pair(process1->GetID(), filter1->routing_id())));
7113 EXPECT_FALSE(
7114 ContainsKey(web_contents()->pending_widget_views_,
7115 std::make_pair(process2->GetID(), filter2->routing_id())));
7116 }
7117
6935 } // namespace content 7118 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698