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

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

Issue 1046933005: Refactor postMessage for out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enable SupportCrossProcessPostMessage test on FYI bots Created 5 years, 8 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/frame_host/cross_process_frame_connector.h" 10 #include "content/browser/frame_host/cross_process_frame_connector.h"
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 base::string16 expected_title(base::UTF8ToUTF16("LOADEDLOADED")); 1650 base::string16 expected_title(base::UTF8ToUTF16("LOADEDLOADED"));
1651 TitleWatcher title_watcher(shell()->web_contents(), expected_title); 1651 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
1652 TestNavigationObserver observer(shell()->web_contents()); 1652 TestNavigationObserver observer(shell()->web_contents());
1653 NavigateFrameToURL(root->child_at(0), foo_url); 1653 NavigateFrameToURL(root->child_at(0), foo_url);
1654 EXPECT_TRUE(observer.last_navigation_succeeded()); 1654 EXPECT_TRUE(observer.last_navigation_succeeded());
1655 EXPECT_EQ(foo_url, observer.last_navigation_url()); 1655 EXPECT_EQ(foo_url, observer.last_navigation_url());
1656 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); 1656 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title);
1657 } 1657 }
1658 } 1658 }
1659 1659
1660 // Check that postMessage can be routed between cross-site iframes.
1661 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SubframePostMessage) {
1662 GURL main_url(embedded_test_server()->GetURL(
1663 "/frame_tree/page_with_post_message_frames.html"));
1664 EXPECT_TRUE(NavigateToURL(shell(), main_url));
1665
1666 // It is safe to obtain the root frame tree node here, as it doesn't change.
1667 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
1668 ->GetFrameTree()
1669 ->root();
1670
1671 TestNavigationObserver observer(shell()->web_contents());
1672 ASSERT_EQ(2U, root->child_count());
1673
1674 // Verify the frames start at correct URLs. First frame should be
1675 // same-site; second frame should be cross-site.
1676 GURL same_site_url(embedded_test_server()->GetURL("/post_message.html"));
1677 EXPECT_EQ(same_site_url, root->child_at(0)->current_url());
1678 GURL foo_url(embedded_test_server()->GetURL("foo.com",
1679 "/post_message.html"));
1680 EXPECT_EQ(foo_url, root->child_at(1)->current_url());
1681
1682 // Send a message from first, same-site frame to second, cross-site frame.
1683 // Expect the second frame to reply back to the first frame.
1684 //
1685 // TODO(alexmos): Also try sending from second to first frame. Currently,
1686 // this fails because a proxy for the first frame is not created in second
1687 // frame's process due to https://crbug.com/423587.
1688 bool success = false;
1689 EXPECT_TRUE(ExecuteScriptAndExtractBool(
1690 root->child_at(0)->current_frame_host(),
1691 "window.domAutomationController.send("
1692 " postToSibling('subframe-msg','subframe2'));",
1693 &success));
1694 EXPECT_TRUE(success);
1695
1696 // Wait for first frame to receive a reply from the second frame. It will
1697 // send "done-subframe1" from the DOMAutomationController when the reply
1698 // arrives.
1699 content::DOMMessageQueue msg_queue;
1700 std::string status;
1701 while (msg_queue.WaitForMessage(&status)) {
1702 if (status == "\"done-subframe1\"")
1703 break;
1704 }
1705
1706 // Send a postMessage from second, cross-site frame to its parent. Expect
1707 // parent to send a reply to the frame.
1708 base::string16 expected_title(base::ASCIIToUTF16("subframe-msg"));
1709 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
1710 success = false;
1711 EXPECT_TRUE(ExecuteScriptAndExtractBool(
1712 root->child_at(1)->current_frame_host(),
1713 "window.domAutomationController.send(postToParent('subframe-msg'));",
1714 &success));
1715 EXPECT_TRUE(success);
1716 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
1717
1718 // Wait for second frame to receive a reply from the parent. The frame will
1719 // return "done-subframe2" from the DOMAutomationController when the reply
1720 // arrives.
1721 while (msg_queue.WaitForMessage(&status)) {
1722 if (status == "\"done-subframe2\"")
1723 break;
1724 }
1725
1726 // Verify the total number of received messages for each subframe. First
1727 // frame should have one message (reply from second frame), and second frame
1728 // should have two messages (message from first frame and reply from parent).
1729 int subframe1_received_messages = 0;
1730 int subframe2_received_messages = 0;
1731 EXPECT_TRUE(ExecuteScriptAndExtractInt(
1732 root->child_at(0)->current_frame_host(),
1733 "window.domAutomationController.send(window.receivedMessages);",
1734 &subframe1_received_messages));
1735 EXPECT_EQ(1, subframe1_received_messages);
1736 EXPECT_TRUE(ExecuteScriptAndExtractInt(
1737 root->child_at(1)->current_frame_host(),
1738 "window.domAutomationController.send(window.receivedMessages);",
1739 &subframe2_received_messages));
1740 EXPECT_EQ(2, subframe2_received_messages);
1741 }
1742
1660 } // namespace content 1743 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698