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

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: Disable popup menu test for Mac/Android 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 routing_id_(MSG_ROUTING_NONE),
6942 message_loop_runner_(new MessageLoopRunner) {}
6943
6944 bool OnMessageReceived(const IPC::Message& message) override {
6945 bool handled = true;
6946 IPC_BEGIN_MESSAGE_MAP(PendingWidgetMessageFilter, message)
6947 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView)
6948 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget)
6949 IPC_MESSAGE_UNHANDLED(handled = false)
6950 IPC_END_MESSAGE_MAP()
6951 return handled;
6952 }
6953
6954 void Wait() {
6955 message_loop_runner_->Run();
6956 }
6957
6958 int routing_id() { return routing_id_; }
6959
6960 private:
6961 ~PendingWidgetMessageFilter() override {}
6962
6963 void OnShowView(int routing_id,
6964 WindowOpenDisposition disposition,
6965 const gfx::Rect& initial_rect,
6966 bool user_gesture) {
6967 content::BrowserThread::PostTask(
6968 content::BrowserThread::UI, FROM_HERE,
6969 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this,
6970 routing_id));
6971 }
6972
6973 void OnShowWidget(int routing_id, const gfx::Rect& initial_rect) {
6974 content::BrowserThread::PostTask(
6975 content::BrowserThread::UI, FROM_HERE,
6976 base::Bind(&PendingWidgetMessageFilter::OnReceivedRoutingIDOnUI, this,
6977 routing_id));
6978 }
6979
6980 void OnReceivedRoutingIDOnUI(int routing_id) {
6981 routing_id_ = routing_id;
6982 message_loop_runner_->Quit();
6983 }
6984
6985 int routing_id_;
6986 scoped_refptr<MessageLoopRunner> message_loop_runner_;
6987
6988 DISALLOW_COPY_AND_ASSIGN(PendingWidgetMessageFilter);
6989 };
6990
6991 // Test for https://crbug.com/612276. Simultaneously open two new windows from
6992 // two subframes in different processes, where each subframe process's next
6993 // routing ID is the same. Make sure that both windows are created properly.
6994 //
6995 // Each new window requires two IPCs to first create it (handled by
6996 // CreateNewWindow) and then show it (ShowCreatedWindow). In the bug, both
6997 // CreateNewWindow calls arrived before the ShowCreatedWindow calls, resulting
6998 // in the two pending windows colliding in the pending WebContents map, which
6999 // used to be keyed only by routing_id.
7000 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7001 TwoSubframesCreatePopupsSimultaneously) {
7002 GURL main_url(embedded_test_server()->GetURL(
7003 "a.com", "/cross_site_iframe_factory.html?a(b,c)"));
7004 EXPECT_TRUE(NavigateToURL(shell(), main_url));
7005
7006 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
7007 FrameTreeNode* child1 = root->child_at(0);
7008 FrameTreeNode* child2 = root->child_at(1);
7009 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess();
7010 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess();
7011
7012 // Call window.open simultaneously in both subframes to create two popups.
7013 // Wait for and then drop both ViewHostMsg_ShowView messages. This will
7014 // ensure that both CreateNewWindow calls happen before either
7015 // ShowCreatedWindow call.
7016 scoped_refptr<PendingWidgetMessageFilter> filter1 =
7017 new PendingWidgetMessageFilter();
7018 process1->AddFilter(filter1.get());
7019 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), "window.open();"));
7020 filter1->Wait();
7021
7022 scoped_refptr<PendingWidgetMessageFilter> filter2 =
7023 new PendingWidgetMessageFilter();
7024 process2->AddFilter(filter2.get());
7025 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "window.open();"));
7026 filter2->Wait();
7027
7028 // At this point, we should have two pending WebContents.
7029 EXPECT_TRUE(
7030 ContainsKey(web_contents()->pending_contents_,
7031 std::make_pair(process1->GetID(), filter1->routing_id())));
7032 EXPECT_TRUE(
7033 ContainsKey(web_contents()->pending_contents_,
7034 std::make_pair(process2->GetID(), filter2->routing_id())));
7035
7036 // Both subframes were set up in the same way, so the next routing ID for the
7037 // new popup windows should match up (this led to the collision in the
7038 // pending contents map in the original bug).
7039 EXPECT_EQ(filter1->routing_id(), filter2->routing_id());
7040
7041 // Now, simulate that both ShowView messages arrive by showing both of the
7042 // pending WebContents.
7043 web_contents()->ShowCreatedWindow(process1->GetID(), filter1->routing_id(),
7044 NEW_FOREGROUND_TAB, gfx::Rect(), true);
7045 web_contents()->ShowCreatedWindow(process2->GetID(), filter2->routing_id(),
7046 NEW_FOREGROUND_TAB, gfx::Rect(), true);
7047
7048 // Verify that both shells were properly created.
7049 EXPECT_EQ(3u, Shell::windows().size());
7050 }
7051
7052 // Test for https://crbug.com/612276. Similar to
7053 // TwoSubframesOpenWindowsSimultaneously, but use popup menu widgets instead of
7054 // windows.
7055 //
7056 // The plumbing that this test is verifying is not utilized on Mac/Android,
7057 // where popup menus don't create a popup RenderWidget, but rather they trigger
7058 // a FrameHostMsg_ShowPopup to ask the browser to build and display the actual
7059 // popup using native controls.
7060 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
7061 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
7062 TwoSubframesCreatePopupMenuWidgetsSimultaneously) {
7063 GURL main_url(embedded_test_server()->GetURL(
7064 "a.com", "/cross_site_iframe_factory.html?a(b,c)"));
7065 EXPECT_TRUE(NavigateToURL(shell(), main_url));
7066
7067 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
7068 FrameTreeNode* child1 = root->child_at(0);
7069 FrameTreeNode* child2 = root->child_at(1);
7070 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess();
7071 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess();
7072
7073 // Navigate both subframes to a page with a <select> element.
7074 NavigateFrameToURL(child1, embedded_test_server()->GetURL(
7075 "b.com", "/site_isolation/page-with-select.html"));
7076 NavigateFrameToURL(child2, embedded_test_server()->GetURL(
7077 "c.com", "/site_isolation/page-with-select.html"));
7078
7079 // Open both <select> menus. This creates a popup widget in both processes.
7080 // Wait for and then drop the ViewHostMsg_ShowWidget messages, so that both
7081 // widgets are left in pending-but-not-shown state.
7082 scoped_refptr<PendingWidgetMessageFilter> filter1 =
7083 new PendingWidgetMessageFilter();
7084 process1->AddFilter(filter1.get());
7085 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), "openSelectMenu();"));
7086 filter1->Wait();
7087
7088 scoped_refptr<PendingWidgetMessageFilter> filter2 =
7089 new PendingWidgetMessageFilter();
7090 process2->AddFilter(filter2.get());
7091 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "openSelectMenu();"));
7092 filter2->Wait();
7093
7094 // At this point, we should have two pending widgets.
7095 EXPECT_TRUE(
7096 ContainsKey(web_contents()->pending_widget_views_,
7097 std::make_pair(process1->GetID(), filter1->routing_id())));
7098 EXPECT_TRUE(
7099 ContainsKey(web_contents()->pending_widget_views_,
7100 std::make_pair(process2->GetID(), filter2->routing_id())));
7101
7102 // Both subframes were set up in the same way, so the next routing ID for the
7103 // new popup widgets should match up (this led to the collision in the
7104 // pending widgets map in the original bug).
7105 EXPECT_EQ(filter1->routing_id(), filter2->routing_id());
7106
7107 // Now simulate both widgets being shown.
7108 web_contents()->ShowCreatedWidget(process1->GetID(), filter1->routing_id(),
7109 false, gfx::Rect());
7110 web_contents()->ShowCreatedWidget(process2->GetID(), filter2->routing_id(),
7111 false, gfx::Rect());
7112 EXPECT_FALSE(
7113 ContainsKey(web_contents()->pending_widget_views_,
7114 std::make_pair(process1->GetID(), filter1->routing_id())));
7115 EXPECT_FALSE(
7116 ContainsKey(web_contents()->pending_widget_views_,
7117 std::make_pair(process2->GetID(), filter2->routing_id())));
7118 }
7119 #endif
7120
6935 } // namespace content 7121 } // 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