| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/public/common/file_chooser_file_info.h" | 30 #include "content/public/common/file_chooser_file_info.h" |
| 31 #include "content/public/common/file_chooser_params.h" | 31 #include "content/public/common/file_chooser_params.h" |
| 32 #include "content/public/common/page_state.h" | 32 #include "content/public/common/page_state.h" |
| 33 #include "content/public/common/url_constants.h" | 33 #include "content/public/common/url_constants.h" |
| 34 #include "content/public/test/browser_test_utils.h" | 34 #include "content/public/test/browser_test_utils.h" |
| 35 #include "content/public/test/content_browser_test.h" | 35 #include "content/public/test/content_browser_test.h" |
| 36 #include "content/public/test/content_browser_test_utils.h" | 36 #include "content/public/test/content_browser_test_utils.h" |
| 37 #include "content/public/test/test_navigation_observer.h" | 37 #include "content/public/test/test_navigation_observer.h" |
| 38 #include "content/public/test/test_utils.h" | 38 #include "content/public/test/test_utils.h" |
| 39 #include "content/shell/browser/shell.h" | 39 #include "content/shell/browser/shell.h" |
| 40 #include "content/test/content_browser_test_utils_internal.h" |
| 40 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
| 41 #include "net/dns/mock_host_resolver.h" | 42 #include "net/dns/mock_host_resolver.h" |
| 42 #include "net/test/embedded_test_server/embedded_test_server.h" | 43 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 43 #include "net/test/spawned_test_server/spawned_test_server.h" | 44 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 44 | 45 |
| 45 using base::ASCIIToUTF16; | 46 using base::ASCIIToUTF16; |
| 46 | 47 |
| 47 namespace content { | 48 namespace content { |
| 48 | 49 |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| 51 const char kOpenUrlViaClickTargetFunc[] = | 52 const char kOpenUrlViaClickTargetFunc[] = |
| 52 "(function(url) {\n" | 53 "(function(url) {\n" |
| 53 " var lnk = document.createElement(\"a\");\n" | 54 " var lnk = document.createElement(\"a\");\n" |
| 54 " lnk.href = url;\n" | 55 " lnk.href = url;\n" |
| 55 " lnk.target = \"_blank\";\n" | 56 " lnk.target = \"_blank\";\n" |
| 56 " document.body.appendChild(lnk);\n" | 57 " document.body.appendChild(lnk);\n" |
| 57 " lnk.click();\n" | 58 " lnk.click();\n" |
| 58 "})"; | 59 "})"; |
| 59 | 60 |
| 60 // Adds a link with given url and target=_blank, and clicks on it. | 61 // Adds a link with given url and target=_blank, and clicks on it. |
| 61 void OpenUrlViaClickTarget(const internal::ToRenderFrameHost& adapter, | 62 void OpenUrlViaClickTarget(const ToRenderFrameHost& adapter, const GURL& url) { |
| 62 const GURL& url) { | |
| 63 EXPECT_TRUE(ExecuteScript(adapter, | 63 EXPECT_TRUE(ExecuteScript(adapter, |
| 64 std::string(kOpenUrlViaClickTargetFunc) + "(\"" + url.spec() + "\");")); | 64 std::string(kOpenUrlViaClickTargetFunc) + "(\"" + url.spec() + "\");")); |
| 65 } | 65 } |
| 66 | 66 |
| 67 Shell* OpenPopup(const internal::ToRenderFrameHost& opener, | |
| 68 const std::string& name) { | |
| 69 ShellAddedObserver new_shell_observer; | |
| 70 bool success = false; | |
| 71 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 72 opener, | |
| 73 "window.domAutomationController.send(!!window.open('', '" + name + "'));", | |
| 74 &success)); | |
| 75 EXPECT_TRUE(success); | |
| 76 Shell* new_shell = new_shell_observer.GetShell(); | |
| 77 return new_shell; | |
| 78 } | |
| 79 | |
| 80 } // anonymous namespace | 67 } // anonymous namespace |
| 81 | 68 |
| 82 class RenderFrameHostManagerTest : public ContentBrowserTest { | 69 class RenderFrameHostManagerTest : public ContentBrowserTest { |
| 83 public: | 70 public: |
| 84 RenderFrameHostManagerTest() : foo_com_("foo.com") { | 71 RenderFrameHostManagerTest() : foo_com_("foo.com") { |
| 85 replace_host_.SetHostStr(foo_com_); | 72 replace_host_.SetHostStr(foo_com_); |
| 86 } | 73 } |
| 87 | 74 |
| 88 static bool GetFilePathWithHostAndPortReplacement( | 75 static bool GetFilePathWithHostAndPortReplacement( |
| 89 const std::string& original_file_path, | 76 const std::string& original_file_path, |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 558 |
| 572 GURL main_url(embedded_test_server()->GetURL("/title1.html")); | 559 GURL main_url(embedded_test_server()->GetURL("/title1.html")); |
| 573 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 560 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 574 | 561 |
| 575 // Get the original SiteInstance for later comparison. | 562 // Get the original SiteInstance for later comparison. |
| 576 scoped_refptr<SiteInstance> orig_site_instance( | 563 scoped_refptr<SiteInstance> orig_site_instance( |
| 577 shell()->web_contents()->GetSiteInstance()); | 564 shell()->web_contents()->GetSiteInstance()); |
| 578 EXPECT_TRUE(orig_site_instance.get() != NULL); | 565 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 579 | 566 |
| 580 // Open a popup using window.open with a 'foo' window.name. | 567 // Open a popup using window.open with a 'foo' window.name. |
| 581 Shell* new_shell = OpenPopup(shell()->web_contents(), "foo"); | 568 Shell* new_shell = |
| 569 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); |
| 570 EXPECT_TRUE(new_shell); |
| 582 | 571 |
| 583 // The window.name for the new popup should be "foo". | 572 // The window.name for the new popup should be "foo". |
| 584 std::string name; | 573 std::string name; |
| 585 EXPECT_TRUE(ExecuteScriptAndExtractString( | 574 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 586 new_shell->web_contents(), | 575 new_shell->web_contents(), |
| 587 "window.domAutomationController.send(window.name);", &name)); | 576 "window.domAutomationController.send(window.name);", &name)); |
| 588 EXPECT_EQ("foo", name); | 577 EXPECT_EQ("foo", name); |
| 589 | 578 |
| 590 // Now navigate the new tab to a different site. | 579 // Now navigate the new tab to a different site. |
| 591 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title2.html")); | 580 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title2.html")); |
| 592 EXPECT_TRUE(NavigateToURL(new_shell, foo_url)); | 581 EXPECT_TRUE(NavigateToURL(new_shell, foo_url)); |
| 593 scoped_refptr<SiteInstance> new_site_instance( | 582 scoped_refptr<SiteInstance> new_site_instance( |
| 594 new_shell->web_contents()->GetSiteInstance()); | 583 new_shell->web_contents()->GetSiteInstance()); |
| 595 EXPECT_NE(orig_site_instance, new_site_instance); | 584 EXPECT_NE(orig_site_instance, new_site_instance); |
| 596 | 585 |
| 597 // window.name should still be "foo". | 586 // window.name should still be "foo". |
| 598 name = ""; | 587 name = ""; |
| 599 EXPECT_TRUE(ExecuteScriptAndExtractString( | 588 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 600 new_shell->web_contents(), | 589 new_shell->web_contents(), |
| 601 "window.domAutomationController.send(window.name);", &name)); | 590 "window.domAutomationController.send(window.name);", &name)); |
| 602 EXPECT_EQ("foo", name); | 591 EXPECT_EQ("foo", name); |
| 603 | 592 |
| 604 // Open another popup from the 'foo' popup and navigate it cross-site. | 593 // Open another popup from the 'foo' popup and navigate it cross-site. |
| 605 Shell* new_shell2 = OpenPopup(new_shell->web_contents(), "bar"); | 594 Shell* new_shell2 = |
| 595 OpenPopup(new_shell->web_contents(), GURL(url::kAboutBlankURL), "bar"); |
| 596 EXPECT_TRUE(new_shell2); |
| 606 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title3.html")); | 597 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title3.html")); |
| 607 EXPECT_TRUE(NavigateToURL(new_shell2, bar_url)); | 598 EXPECT_TRUE(NavigateToURL(new_shell2, bar_url)); |
| 608 | 599 |
| 609 // Check that the new popup's window.opener has name "foo", which verifies | 600 // Check that the new popup's window.opener has name "foo", which verifies |
| 610 // that new swapped-out RenderViews also propagate window.name. This has to | 601 // that new swapped-out RenderViews also propagate window.name. This has to |
| 611 // be done via window.open, since window.name isn't readable cross-origin. | 602 // be done via window.open, since window.name isn't readable cross-origin. |
| 612 bool success = false; | 603 bool success = false; |
| 613 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 604 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 614 new_shell2->web_contents(), | 605 new_shell2->web_contents(), |
| 615 "window.domAutomationController.send(" | 606 "window.domAutomationController.send(" |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 | 1884 |
| 1894 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1885 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1895 ->GetFrameTree() | 1886 ->GetFrameTree() |
| 1896 ->root(); | 1887 ->root(); |
| 1897 | 1888 |
| 1898 scoped_refptr<SiteInstance> orig_site_instance( | 1889 scoped_refptr<SiteInstance> orig_site_instance( |
| 1899 shell()->web_contents()->GetSiteInstance()); | 1890 shell()->web_contents()->GetSiteInstance()); |
| 1900 EXPECT_TRUE(orig_site_instance); | 1891 EXPECT_TRUE(orig_site_instance); |
| 1901 | 1892 |
| 1902 // Open a popup and navigate it cross-site. | 1893 // Open a popup and navigate it cross-site. |
| 1903 Shell* new_shell = OpenPopup(shell()->web_contents(), "foo"); | 1894 Shell* new_shell = |
| 1895 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "foo"); |
| 1896 EXPECT_TRUE(new_shell); |
| 1904 FrameTreeNode* popup_root = | 1897 FrameTreeNode* popup_root = |
| 1905 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 1898 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
| 1906 ->GetFrameTree() | 1899 ->GetFrameTree() |
| 1907 ->root(); | 1900 ->root(); |
| 1908 | 1901 |
| 1909 GURL cross_site_url = | 1902 GURL cross_site_url = |
| 1910 embedded_test_server()->GetURL("foo.com", "/title2.html"); | 1903 embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 1911 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); | 1904 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); |
| 1912 | 1905 |
| 1913 scoped_refptr<SiteInstance> foo_site_instance( | 1906 scoped_refptr<SiteInstance> foo_site_instance( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1938 EXPECT_FALSE(opener_rfph->is_render_frame_proxy_live()); | 1931 EXPECT_FALSE(opener_rfph->is_render_frame_proxy_live()); |
| 1939 | 1932 |
| 1940 // Re-navigate the popup to the same URL and check that this recreates the | 1933 // Re-navigate the popup to the same URL and check that this recreates the |
| 1941 // opener's swapped out RVH and proxy in the foo.com SiteInstance. | 1934 // opener's swapped out RVH and proxy in the foo.com SiteInstance. |
| 1942 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); | 1935 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); |
| 1943 EXPECT_TRUE(opener_rvh->IsRenderViewLive()); | 1936 EXPECT_TRUE(opener_rvh->IsRenderViewLive()); |
| 1944 EXPECT_TRUE(opener_rfph->is_render_frame_proxy_live()); | 1937 EXPECT_TRUE(opener_rfph->is_render_frame_proxy_live()); |
| 1945 } | 1938 } |
| 1946 | 1939 |
| 1947 } // namespace content | 1940 } // namespace content |
| OLD | NEW |