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 "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 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1690 base::string16 expected_title(base::UTF8ToUTF16("LOADEDLOADED")); | 1690 base::string16 expected_title(base::UTF8ToUTF16("LOADEDLOADED")); |
1691 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 1691 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
1692 TestNavigationObserver observer(shell()->web_contents()); | 1692 TestNavigationObserver observer(shell()->web_contents()); |
1693 NavigateFrameToURL(root->child_at(0), foo_url); | 1693 NavigateFrameToURL(root->child_at(0), foo_url); |
1694 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1694 EXPECT_TRUE(observer.last_navigation_succeeded()); |
1695 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 1695 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
1696 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); | 1696 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); |
1697 } | 1697 } |
1698 } | 1698 } |
1699 | 1699 |
1700 // Check that postMessage can be routed between cross-site iframes. | |
1701 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SubframePostMessage) { | |
1702 GURL main_url(embedded_test_server()->GetURL( | |
1703 "/frame_tree/page_with_post_message_frames.html")); | |
1704 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
1705 | |
1706 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
1707 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
1708 ->GetFrameTree() | |
1709 ->root(); | |
1710 | |
1711 TestNavigationObserver observer(shell()->web_contents()); | |
1712 ASSERT_EQ(2U, root->child_count()); | |
1713 | |
1714 // Verify the frames start at correct URLs. First frame should be | |
1715 // same-site; second frame should be cross-site. | |
1716 GURL same_site_url(embedded_test_server()->GetURL("/post_message.html")); | |
1717 EXPECT_EQ(same_site_url, root->child_at(0)->current_url()); | |
1718 GURL foo_url(embedded_test_server()->GetURL("foo.com", | |
1719 "/post_message.html")); | |
1720 EXPECT_EQ(foo_url, root->child_at(1)->current_url()); | |
Charlie Reis
2015/04/06 16:18:56
Let's also verify they're in different SiteInstanc
alexmos
2015/04/07 18:44:40
Done.
| |
1721 | |
1722 // Send a message from first, same-site frame to second, cross-site frame. | |
1723 // Expect the second frame to reply back to the first frame. | |
1724 // | |
1725 // TODO(alexmos): Also try sending from second to first frame. Currently, | |
1726 // this fails due to https://crbug.com/473518, which prevents | |
1727 // parent.frames[x] from working when "parent" is a remote frame. | |
1728 bool success = false; | |
1729 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
1730 root->child_at(0)->current_frame_host(), | |
1731 "window.domAutomationController.send(" | |
1732 " postToSibling('subframe-msg','subframe2'));", | |
1733 &success)); | |
1734 EXPECT_TRUE(success); | |
1735 | |
1736 // Wait for first frame to receive a reply from the second frame. It will | |
1737 // send "done-subframe1" from the DOMAutomationController when the reply | |
1738 // arrives. | |
1739 content::DOMMessageQueue msg_queue; | |
1740 std::string status; | |
1741 while (msg_queue.WaitForMessage(&status)) { | |
1742 if (status == "\"done-subframe1\"") | |
1743 break; | |
1744 } | |
1745 | |
1746 // Send a postMessage from second, cross-site frame to its parent. Expect | |
1747 // parent to send a reply to the frame. | |
1748 base::string16 expected_title(base::ASCIIToUTF16("subframe-msg")); | |
1749 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | |
1750 success = false; | |
1751 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
1752 root->child_at(1)->current_frame_host(), | |
1753 "window.domAutomationController.send(postToParent('subframe-msg'));", | |
1754 &success)); | |
1755 EXPECT_TRUE(success); | |
1756 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
1757 | |
1758 // Wait for second frame to receive a reply from the parent. The frame will | |
1759 // return "done-subframe2" from the DOMAutomationController when the reply | |
1760 // arrives. | |
1761 while (msg_queue.WaitForMessage(&status)) { | |
1762 if (status == "\"done-subframe2\"") | |
1763 break; | |
1764 } | |
1765 | |
1766 // Verify the total number of received messages for each subframe. First | |
1767 // frame should have one message (reply from second frame), and second frame | |
1768 // should have two messages (message from first frame and reply from parent). | |
1769 int subframe1_received_messages = 0; | |
1770 int subframe2_received_messages = 0; | |
1771 EXPECT_TRUE(ExecuteScriptAndExtractInt( | |
1772 root->child_at(0)->current_frame_host(), | |
1773 "window.domAutomationController.send(window.receivedMessages);", | |
1774 &subframe1_received_messages)); | |
1775 EXPECT_EQ(1, subframe1_received_messages); | |
1776 EXPECT_TRUE(ExecuteScriptAndExtractInt( | |
1777 root->child_at(1)->current_frame_host(), | |
1778 "window.domAutomationController.send(window.receivedMessages);", | |
1779 &subframe2_received_messages)); | |
1780 EXPECT_EQ(2, subframe2_received_messages); | |
1781 } | |
1782 | |
1700 } // namespace content | 1783 } // namespace content |
OLD | NEW |