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 internal::ToRenderFrameHost& adapter, |
62 const GURL& url) { | 63 const GURL& url) { |
63 EXPECT_TRUE(ExecuteScript(adapter, | 64 EXPECT_TRUE(ExecuteScript(adapter, |
64 std::string(kOpenUrlViaClickTargetFunc) + "(\"" + url.spec() + "\");")); | 65 std::string(kOpenUrlViaClickTargetFunc) + "(\"" + url.spec() + "\");")); |
65 } | 66 } |
66 | 67 |
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 | 68 } // anonymous namespace |
81 | 69 |
82 class RenderFrameHostManagerTest : public ContentBrowserTest { | 70 class RenderFrameHostManagerTest : public ContentBrowserTest { |
83 public: | 71 public: |
84 RenderFrameHostManagerTest() : foo_com_("foo.com") { | 72 RenderFrameHostManagerTest() : foo_com_("foo.com") { |
85 replace_host_.SetHostStr(foo_com_); | 73 replace_host_.SetHostStr(foo_com_); |
86 } | 74 } |
87 | 75 |
88 static bool GetFilePathWithHostAndPortReplacement( | 76 static bool GetFilePathWithHostAndPortReplacement( |
89 const std::string& original_file_path, | 77 const std::string& original_file_path, |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 559 |
572 GURL main_url(embedded_test_server()->GetURL("/title1.html")); | 560 GURL main_url(embedded_test_server()->GetURL("/title1.html")); |
573 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 561 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
574 | 562 |
575 // Get the original SiteInstance for later comparison. | 563 // Get the original SiteInstance for later comparison. |
576 scoped_refptr<SiteInstance> orig_site_instance( | 564 scoped_refptr<SiteInstance> orig_site_instance( |
577 shell()->web_contents()->GetSiteInstance()); | 565 shell()->web_contents()->GetSiteInstance()); |
578 EXPECT_TRUE(orig_site_instance.get() != NULL); | 566 EXPECT_TRUE(orig_site_instance.get() != NULL); |
579 | 567 |
580 // Open a popup using window.open with a 'foo' window.name. | 568 // Open a popup using window.open with a 'foo' window.name. |
581 Shell* new_shell = OpenPopup(shell()->web_contents(), "foo"); | 569 Shell* new_shell = |
570 OpenPopup(shell()->web_contents(), GURL("about:blank"), "foo"); | |
Charlie Reis
2015/07/11 00:12:08
url::kAboutBlankURL (here and below)
| |
571 EXPECT_TRUE(new_shell); | |
582 | 572 |
583 // The window.name for the new popup should be "foo". | 573 // The window.name for the new popup should be "foo". |
584 std::string name; | 574 std::string name; |
585 EXPECT_TRUE(ExecuteScriptAndExtractString( | 575 EXPECT_TRUE(ExecuteScriptAndExtractString( |
586 new_shell->web_contents(), | 576 new_shell->web_contents(), |
587 "window.domAutomationController.send(window.name);", &name)); | 577 "window.domAutomationController.send(window.name);", &name)); |
588 EXPECT_EQ("foo", name); | 578 EXPECT_EQ("foo", name); |
589 | 579 |
590 // Now navigate the new tab to a different site. | 580 // Now navigate the new tab to a different site. |
591 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title2.html")); | 581 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title2.html")); |
592 EXPECT_TRUE(NavigateToURL(new_shell, foo_url)); | 582 EXPECT_TRUE(NavigateToURL(new_shell, foo_url)); |
593 scoped_refptr<SiteInstance> new_site_instance( | 583 scoped_refptr<SiteInstance> new_site_instance( |
594 new_shell->web_contents()->GetSiteInstance()); | 584 new_shell->web_contents()->GetSiteInstance()); |
595 EXPECT_NE(orig_site_instance, new_site_instance); | 585 EXPECT_NE(orig_site_instance, new_site_instance); |
596 | 586 |
597 // window.name should still be "foo". | 587 // window.name should still be "foo". |
598 name = ""; | 588 name = ""; |
599 EXPECT_TRUE(ExecuteScriptAndExtractString( | 589 EXPECT_TRUE(ExecuteScriptAndExtractString( |
600 new_shell->web_contents(), | 590 new_shell->web_contents(), |
601 "window.domAutomationController.send(window.name);", &name)); | 591 "window.domAutomationController.send(window.name);", &name)); |
602 EXPECT_EQ("foo", name); | 592 EXPECT_EQ("foo", name); |
603 | 593 |
604 // Open another popup from the 'foo' popup and navigate it cross-site. | 594 // Open another popup from the 'foo' popup and navigate it cross-site. |
605 Shell* new_shell2 = OpenPopup(new_shell->web_contents(), "bar"); | 595 Shell* new_shell2 = |
596 OpenPopup(new_shell->web_contents(), GURL("about:blank"), "bar"); | |
597 EXPECT_TRUE(new_shell2); | |
606 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title3.html")); | 598 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title3.html")); |
607 EXPECT_TRUE(NavigateToURL(new_shell2, bar_url)); | 599 EXPECT_TRUE(NavigateToURL(new_shell2, bar_url)); |
608 | 600 |
609 // Check that the new popup's window.opener has name "foo", which verifies | 601 // 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 | 602 // 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. | 603 // be done via window.open, since window.name isn't readable cross-origin. |
612 bool success = false; | 604 bool success = false; |
613 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 605 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
614 new_shell2->web_contents(), | 606 new_shell2->web_contents(), |
615 "window.domAutomationController.send(" | 607 "window.domAutomationController.send(" |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1893 | 1885 |
1894 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1886 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
1895 ->GetFrameTree() | 1887 ->GetFrameTree() |
1896 ->root(); | 1888 ->root(); |
1897 | 1889 |
1898 scoped_refptr<SiteInstance> orig_site_instance( | 1890 scoped_refptr<SiteInstance> orig_site_instance( |
1899 shell()->web_contents()->GetSiteInstance()); | 1891 shell()->web_contents()->GetSiteInstance()); |
1900 EXPECT_TRUE(orig_site_instance); | 1892 EXPECT_TRUE(orig_site_instance); |
1901 | 1893 |
1902 // Open a popup and navigate it cross-site. | 1894 // Open a popup and navigate it cross-site. |
1903 Shell* new_shell = OpenPopup(shell()->web_contents(), "foo"); | 1895 Shell* new_shell = |
1896 OpenPopup(shell()->web_contents(), GURL("about:blank"), "foo"); | |
1897 EXPECT_TRUE(new_shell); | |
1904 FrameTreeNode* popup_root = | 1898 FrameTreeNode* popup_root = |
1905 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 1899 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
1906 ->GetFrameTree() | 1900 ->GetFrameTree() |
1907 ->root(); | 1901 ->root(); |
1908 | 1902 |
1909 GURL cross_site_url = | 1903 GURL cross_site_url = |
1910 embedded_test_server()->GetURL("foo.com", "/title2.html"); | 1904 embedded_test_server()->GetURL("foo.com", "/title2.html"); |
1911 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); | 1905 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); |
1912 | 1906 |
1913 scoped_refptr<SiteInstance> foo_site_instance( | 1907 scoped_refptr<SiteInstance> foo_site_instance( |
(...skipping 24 matching lines...) Expand all Loading... | |
1938 EXPECT_FALSE(opener_rfph->is_render_frame_proxy_live()); | 1932 EXPECT_FALSE(opener_rfph->is_render_frame_proxy_live()); |
1939 | 1933 |
1940 // Re-navigate the popup to the same URL and check that this recreates the | 1934 // 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. | 1935 // opener's swapped out RVH and proxy in the foo.com SiteInstance. |
1942 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); | 1936 EXPECT_TRUE(NavigateToURL(new_shell, cross_site_url)); |
1943 EXPECT_TRUE(opener_rvh->IsRenderViewLive()); | 1937 EXPECT_TRUE(opener_rvh->IsRenderViewLive()); |
1944 EXPECT_TRUE(opener_rfph->is_render_frame_proxy_live()); | 1938 EXPECT_TRUE(opener_rfph->is_render_frame_proxy_live()); |
1945 } | 1939 } |
1946 | 1940 |
1947 } // namespace content | 1941 } // namespace content |
OLD | NEW |