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

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

Issue 1224363002: OOPIF: Fix window.open to work from frames with remote parent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Charlie's comments Created 5 years, 5 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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // number of messages received via postMessage by the current window. 69 // number of messages received via postMessage by the current window.
70 int GetReceivedMessages(FrameTreeNode* ftn) { 70 int GetReceivedMessages(FrameTreeNode* ftn) {
71 int received_messages = 0; 71 int received_messages = 0;
72 EXPECT_TRUE(ExecuteScriptAndExtractInt( 72 EXPECT_TRUE(ExecuteScriptAndExtractInt(
73 ftn->current_frame_host(), 73 ftn->current_frame_host(),
74 "window.domAutomationController.send(window.receivedMessages);", 74 "window.domAutomationController.send(window.receivedMessages);",
75 &received_messages)); 75 &received_messages));
76 return received_messages; 76 return received_messages;
77 } 77 }
78 78
79 Shell* OpenPopup(const internal::ToRenderFrameHost& opener,
Charlie Reis 2015/07/10 21:44:49 Move to content_browser_test_utils_internal (and s
alexmos 2015/07/10 23:03:02 Done. Also refactored slightly to remove the EXPE
80 const GURL& url,
81 const std::string& name) {
82 ShellAddedObserver new_shell_observer;
83 bool success = false;
84 EXPECT_TRUE(ExecuteScriptAndExtractBool(
85 opener,
86 "window.domAutomationController.send("
87 " !!window.open('" + url.spec() + "', '" + name + "'));",
88 &success));
89 EXPECT_TRUE(success);
90 Shell* new_shell = new_shell_observer.GetShell();
91 return new_shell;
92 }
93
79 class RedirectNotificationObserver : public NotificationObserver { 94 class RedirectNotificationObserver : public NotificationObserver {
80 public: 95 public:
81 // Register to listen for notifications of the given type from either a 96 // Register to listen for notifications of the given type from either a
82 // specific source, or from all sources if |source| is 97 // specific source, or from all sources if |source| is
83 // NotificationService::AllSources(). 98 // NotificationService::AllSources().
84 RedirectNotificationObserver(int notification_type, 99 RedirectNotificationObserver(int notification_type,
85 const NotificationSource& source); 100 const NotificationSource& source);
86 ~RedirectNotificationObserver() override; 101 ~RedirectNotificationObserver() override;
87 102
88 // Wait until the specified notification occurs. If the notification was 103 // Wait until the specified notification occurs. If the notification was
(...skipping 2619 matching lines...) Expand 10 before | Expand all | Expand 10 after
2708 " Site A\n" 2723 " Site A\n"
2709 " |--Site A\n" 2724 " |--Site A\n"
2710 " +--Site A\n" 2725 " +--Site A\n"
2711 " |--Site A\n" 2726 " |--Site A\n"
2712 " +--Site A\n" 2727 " +--Site A\n"
2713 " +--Site A\n" 2728 " +--Site A\n"
2714 "Where A = http://127.0.0.1/", 2729 "Where A = http://127.0.0.1/",
2715 DepictFrameTree(root)); 2730 DepictFrameTree(root));
2716 } 2731 }
2717 2732
2733 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OpenPopupWithRemoteParent) {
2734 GURL main_url(
2735 embedded_test_server()->GetURL("a.com", "/site_per_process_main.html"));
2736 NavigateToURL(shell(), main_url);
2737
2738 // It is safe to obtain the root frame tree node here, as it doesn't change.
2739 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2740 ->GetFrameTree()
2741 ->root();
2742
2743 // Navigate first child cross-site.
2744 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html"));
2745 NavigateFrameToURL(root->child_at(0), frame_url);
2746
2747 // Open a popup from the first child.
2748 Shell* new_shell = OpenPopup(root->child_at(0)->current_frame_host(),
2749 GURL("about:blank"), "");
2750
2751 // Check that the popup's opener is correct on both the browser and renderer
2752 // sides.
2753 FrameTreeNode* popup_root =
2754 static_cast<WebContentsImpl*>(new_shell->web_contents())
2755 ->GetFrameTree()
2756 ->root();
2757 EXPECT_EQ(root->child_at(0), popup_root->opener());
2758
2759 std::string opener_url;
2760 EXPECT_TRUE(ExecuteScriptAndExtractString(
2761 popup_root->current_frame_host(),
2762 "window.domAutomationController.send(window.opener.location.href);",
2763 &opener_url));
2764 EXPECT_EQ(frame_url.spec(), opener_url);
2765
2766 // Now try the same with a cross-site popup and make sure it ends up in a new
2767 // process and with a correct opener.
2768 GURL popup_url(embedded_test_server()->GetURL("c.com", "/title2.html"));
2769 Shell* cross_site_popup =
2770 OpenPopup(root->child_at(0)->current_frame_host(), popup_url, "");
2771 WaitForLoadStop(cross_site_popup->web_contents());
2772
2773 FrameTreeNode* cross_site_popup_root =
2774 static_cast<WebContentsImpl*>(cross_site_popup->web_contents())
2775 ->GetFrameTree()
2776 ->root();
2777 EXPECT_EQ(cross_site_popup_root->current_url(), popup_url);
2778
2779 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
2780 cross_site_popup->web_contents()->GetSiteInstance());
2781 EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(),
2782 cross_site_popup->web_contents()->GetSiteInstance());
2783
2784 EXPECT_EQ(root->child_at(0), cross_site_popup_root->opener());
2785
2786 // Ensure the popup's window.opener points to the right subframe. Note that
2787 // we can't check the opener's location as above since it's cross-origin.
2788 bool success = false;
2789 EXPECT_TRUE(ExecuteScriptAndExtractBool(
2790 cross_site_popup_root->current_frame_host(),
2791 "window.domAutomationController.send("
2792 " window.opener === window.opener.top.frames[0]);",
2793 &success));
2794 EXPECT_TRUE(success);
2795 }
2796
2718 } // namespace content 2797 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698