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

Side by Side Diff: content/browser/renderer_host/render_view_host_manager_browsertest.cc

Issue 24733002: Enable sending MessagePorts to a different renderer (Chromium side) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 2 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 | Annotate | Revision Log
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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 10 #include "content/browser/renderer_host/render_view_host_impl.h"
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 659
660 // This postMessage should have created a swapped out RVH for the new 660 // This postMessage should have created a swapped out RVH for the new
661 // SiteInstance in the target=_blank window. 661 // SiteInstance in the target=_blank window.
662 EXPECT_TRUE( 662 EXPECT_TRUE(
663 new_manager->GetSwappedOutRenderViewHost(foo_site_instance.get())); 663 new_manager->GetSwappedOutRenderViewHost(foo_site_instance.get()));
664 664
665 // TODO(nasko): Test subframe targeting of postMessage once 665 // TODO(nasko): Test subframe targeting of postMessage once
666 // http://crbug.com/153701 is fixed. 666 // http://crbug.com/153701 is fixed.
667 } 667 }
668 668
669 // Test for crbug.com/278336. MessagePorts should work cross-process. I.e.,
670 // messages which contain Transferables and get intercepted by
671 // RenderViewImpl::willCheckAndDispatchMessageEvent (because the RenderView is
672 // swapped out) should work.
673 // Specifically:
674 // 1) Create 2 windows (opener and "foo") and send "foo" cross-process.
675 // 2) Post a message containing a message port from opener to "foo".
676 // 3) Post a message from "foo" back to opener via the passed message port.
677 // The test will be enabled when the feature implementation lands.
678 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
679 SupportCrossProcessPostMessageWithMessagePort) {
680 // Start two servers with different sites.
681 ASSERT_TRUE(test_server()->Start());
682 net::SpawnedTestServer https_server(
683 net::SpawnedTestServer::TYPE_HTTPS,
684 net::SpawnedTestServer::kLocalhost,
685 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
686 ASSERT_TRUE(https_server.Start());
687
688 // Load a page with links that open in a new window.
689 std::string replacement_path;
690 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
691 "files/click-noreferrer-links.html",
692 https_server.host_port_pair(),
693 &replacement_path));
694 NavigateToURL(shell(), test_server()->GetURL(replacement_path));
695
696 // Get the original SiteInstance and RVHM for later comparison.
697 WebContents* opener_contents = shell()->web_contents();
698 scoped_refptr<SiteInstance> orig_site_instance(
699 opener_contents->GetSiteInstance());
700 EXPECT_TRUE(orig_site_instance.get() != NULL);
701 RenderViewHostManager* opener_manager = static_cast<WebContentsImpl*>(
702 opener_contents)->GetRenderManagerForTesting();
703
704 // 1) Open a named target=foo window. We will later post a message between the
705 // opener and the new window.
706 ShellAddedObserver new_shell_observer;
707 bool success = false;
708 EXPECT_TRUE(ExecuteScriptAndExtractBool(
709 opener_contents,
710 "window.domAutomationController.send(clickSameSiteTargetedLink());",
711 &success));
712 EXPECT_TRUE(success);
713 Shell* new_shell = new_shell_observer.GetShell();
714
715 // Wait for the navigation in the new window to finish, if it hasn't, then
716 // send it to post_message.html on a different site.
717 WebContents* foo_contents = new_shell->web_contents();
718 WaitForLoadStop(foo_contents);
719 EXPECT_EQ("/files/navigate_opener.html",
720 foo_contents->GetLastCommittedURL().path());
721 NavigateToURL(
722 new_shell,
723 https_server.GetURL("files/post_message.html"));
724 scoped_refptr<SiteInstance> foo_site_instance(
725 foo_contents->GetSiteInstance());
726 EXPECT_NE(orig_site_instance, foo_site_instance);
727
728 // We now have two windows. The opener should have a swapped out RVH
729 // for the new SiteInstance.
730 EXPECT_EQ(2u, Shell::windows().size());
731 EXPECT_TRUE(
732 opener_manager->GetSwappedOutRenderViewHost(foo_site_instance.get()));
733
734 // 2) Post a message containing a MessagePort from opener to the the foo
735 // window. The foo window will reply via the passed port, causing the opener
736 // to update its own title.
737 WindowedNotificationObserver title_observer(
738 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
739 Source<WebContents>(opener_contents));
740 EXPECT_TRUE(ExecuteScriptAndExtractBool(
741 opener_contents,
742 "window.domAutomationController.send(postWithPortToFoo());",
743 &success));
744 EXPECT_TRUE(success);
745 ASSERT_FALSE(
746 opener_manager->GetSwappedOutRenderViewHost(orig_site_instance.get()));
747 title_observer.Wait();
748
749 // Check message counts.
750 int opener_received_messages_via_port = 0;
751 EXPECT_TRUE(ExecuteScriptAndExtractInt(
752 opener_contents,
753 "window.domAutomationController.send(window.receivedMessagesViaPort);",
754 &opener_received_messages_via_port));
755 int foo_received_messages = 0;
756 EXPECT_TRUE(ExecuteScriptAndExtractInt(
757 foo_contents,
758 "window.domAutomationController.send(window.receivedMessages);",
759 &foo_received_messages));
760 int foo_received_messages_with_port = 0;
761 EXPECT_TRUE(ExecuteScriptAndExtractInt(
762 foo_contents,
763 "window.domAutomationController.send(window.receivedMessagesWithPort);",
764 &foo_received_messages_with_port));
765 EXPECT_EQ(1, foo_received_messages);
766 EXPECT_EQ(1, foo_received_messages_with_port);
767 EXPECT_EQ(1, opener_received_messages_via_port);
768 EXPECT_EQ(ASCIIToUTF16("msg-with-port"), foo_contents->GetTitle());
769 EXPECT_EQ(ASCIIToUTF16("msg-back-via-port"), opener_contents->GetTitle());
770 }
771
669 // Test for crbug.com/116192. Navigations to a window's opener should 772 // Test for crbug.com/116192. Navigations to a window's opener should
670 // still work after a process swap. 773 // still work after a process swap.
671 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, 774 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
672 AllowTargetedNavigationsInOpenerAfterSwap) { 775 AllowTargetedNavigationsInOpenerAfterSwap) {
673 // Start two servers with different sites. 776 // Start two servers with different sites.
674 ASSERT_TRUE(test_server()->Start()); 777 ASSERT_TRUE(test_server()->Start());
675 net::SpawnedTestServer https_server( 778 net::SpawnedTestServer https_server(
676 net::SpawnedTestServer::TYPE_HTTPS, 779 net::SpawnedTestServer::TYPE_HTTPS,
677 net::SpawnedTestServer::kLocalhost, 780 net::SpawnedTestServer::kLocalhost,
678 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 781 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); 1394 NavigateToURL(shell(), https_server.GetURL("files/title1.html"));
1292 1395
1293 // Make sure it ends up at the right page. 1396 // Make sure it ends up at the right page.
1294 WaitForLoadStop(shell()->web_contents()); 1397 WaitForLoadStop(shell()->web_contents());
1295 EXPECT_EQ(https_server.GetURL("files/title1.html"), 1398 EXPECT_EQ(https_server.GetURL("files/title1.html"),
1296 shell()->web_contents()->GetLastCommittedURL()); 1399 shell()->web_contents()->GetLastCommittedURL());
1297 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); 1400 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance());
1298 } 1401 }
1299 1402
1300 } // namespace content 1403 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698