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

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: Charlie's nits 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 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
1721 EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(),
1722 root->child_at(1)->current_frame_host()->GetSiteInstance());
1723
1724 // Send a message from first, same-site frame to second, cross-site frame.
1725 // Expect the second frame to reply back to the first frame.
1726 //
1727 // TODO(alexmos): Also try sending from second to first frame. Currently,
1728 // this fails due to https://crbug.com/473518, which prevents
1729 // parent.frames[x] from working when "parent" is a remote frame.
1730 bool success = false;
1731 EXPECT_TRUE(ExecuteScriptAndExtractBool(
1732 root->child_at(0)->current_frame_host(),
1733 "window.domAutomationController.send("
1734 " postToSibling('subframe-msg','subframe2'));",
1735 &success));
1736 EXPECT_TRUE(success);
1737
1738 // Wait for first frame to receive a reply from the second frame. It will
1739 // send "done-subframe1" from the DOMAutomationController when the reply
1740 // arrives.
1741 content::DOMMessageQueue msg_queue;
1742 std::string status;
1743 while (msg_queue.WaitForMessage(&status)) {
1744 if (status == "\"done-subframe1\"")
1745 break;
1746 }
1747
1748 // Send a postMessage from second, cross-site frame to its parent. Expect
1749 // parent to send a reply to the frame.
1750 base::string16 expected_title(base::ASCIIToUTF16("subframe-msg"));
1751 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
1752 success = false;
1753 EXPECT_TRUE(ExecuteScriptAndExtractBool(
1754 root->child_at(1)->current_frame_host(),
1755 "window.domAutomationController.send(postToParent('subframe-msg'));",
1756 &success));
1757 EXPECT_TRUE(success);
1758 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
1759
1760 // Wait for second frame to receive a reply from the parent. The frame will
1761 // return "done-subframe2" from the DOMAutomationController when the reply
1762 // arrives.
1763 while (msg_queue.WaitForMessage(&status)) {
1764 if (status == "\"done-subframe2\"")
1765 break;
1766 }
1767
1768 // Verify the total number of received messages for each subframe. First
1769 // frame should have one message (reply from second frame), and second frame
1770 // should have two messages (message from first frame and reply from parent).
1771 int subframe1_received_messages = 0;
1772 int subframe2_received_messages = 0;
1773 EXPECT_TRUE(ExecuteScriptAndExtractInt(
1774 root->child_at(0)->current_frame_host(),
1775 "window.domAutomationController.send(window.receivedMessages);",
1776 &subframe1_received_messages));
1777 EXPECT_EQ(1, subframe1_received_messages);
1778 EXPECT_TRUE(ExecuteScriptAndExtractInt(
1779 root->child_at(1)->current_frame_host(),
1780 "window.domAutomationController.send(window.receivedMessages);",
1781 &subframe2_received_messages));
1782 EXPECT_EQ(2, subframe2_received_messages);
1783 }
1784
1700 } // namespace content 1785 } // 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