| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "content/browser/child_process_security_policy_impl.h" | 17 #include "content/browser/child_process_security_policy_impl.h" |
| 17 #include "content/browser/frame_host/render_frame_proxy_host.h" | 18 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 18 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 19 #include "content/browser/site_instance_impl.h" | 20 #include "content/browser/site_instance_impl.h" |
| 20 #include "content/browser/web_contents/web_contents_impl.h" | 21 #include "content/browser/web_contents/web_contents_impl.h" |
| 21 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 22 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 22 #include "content/browser/webui/web_ui_impl.h" | 23 #include "content/browser/webui/web_ui_impl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 #include "content/public/test/browser_test_utils.h" | 39 #include "content/public/test/browser_test_utils.h" |
| 39 #include "content/public/test/content_browser_test.h" | 40 #include "content/public/test/content_browser_test.h" |
| 40 #include "content/public/test/content_browser_test_utils.h" | 41 #include "content/public/test/content_browser_test_utils.h" |
| 41 #include "content/public/test/test_navigation_observer.h" | 42 #include "content/public/test/test_navigation_observer.h" |
| 42 #include "content/public/test/test_utils.h" | 43 #include "content/public/test/test_utils.h" |
| 43 #include "content/shell/browser/shell.h" | 44 #include "content/shell/browser/shell.h" |
| 44 #include "content/test/content_browser_test_utils_internal.h" | 45 #include "content/test/content_browser_test_utils_internal.h" |
| 45 #include "net/base/net_util.h" | 46 #include "net/base/net_util.h" |
| 46 #include "net/dns/mock_host_resolver.h" | 47 #include "net/dns/mock_host_resolver.h" |
| 47 #include "net/test/embedded_test_server/embedded_test_server.h" | 48 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 48 #include "net/test/spawned_test_server/spawned_test_server.h" | 49 #include "net/test/embedded_test_server/request_handler_util.h" |
| 49 | 50 |
| 50 using base::ASCIIToUTF16; | 51 using base::ASCIIToUTF16; |
| 51 | 52 |
| 52 namespace content { | 53 namespace content { |
| 53 | 54 |
| 54 namespace { | 55 namespace { |
| 55 | 56 |
| 56 const char kOpenUrlViaClickTargetFunc[] = | 57 const char kOpenUrlViaClickTargetFunc[] = |
| 57 "(function(url) {\n" | 58 "(function(url) {\n" |
| 58 " var lnk = document.createElement(\"a\");\n" | 59 " var lnk = document.createElement(\"a\");\n" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 } | 70 } |
| 70 | 71 |
| 71 } // anonymous namespace | 72 } // anonymous namespace |
| 72 | 73 |
| 73 class RenderFrameHostManagerTest : public ContentBrowserTest { | 74 class RenderFrameHostManagerTest : public ContentBrowserTest { |
| 74 public: | 75 public: |
| 75 RenderFrameHostManagerTest() : foo_com_("foo.com") { | 76 RenderFrameHostManagerTest() : foo_com_("foo.com") { |
| 76 replace_host_.SetHostStr(foo_com_); | 77 replace_host_.SetHostStr(foo_com_); |
| 77 } | 78 } |
| 78 | 79 |
| 79 static bool GetFilePathWithHostAndPortReplacement( | 80 static void GetFilePathWithHostAndPortReplacement( |
| 80 const std::string& original_file_path, | 81 const std::string& original_file_path, |
| 81 const net::HostPortPair& host_port_pair, | 82 const net::HostPortPair& host_port_pair, |
| 82 std::string* replacement_path) { | 83 std::string* replacement_path) { |
| 83 std::vector<net::SpawnedTestServer::StringPair> replacement_text; | 84 base::StringPairs replacement_text; |
| 84 replacement_text.push_back( | 85 replacement_text.push_back( |
| 85 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); | 86 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); |
| 86 return net::SpawnedTestServer::GetFilePathWithReplacements( | 87 net::test_server::GetFilePathWithReplacements( |
| 87 original_file_path, replacement_text, replacement_path); | 88 original_file_path, replacement_text, replacement_path); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void StartServer() { | 91 void StartServer() { |
| 91 // Support multiple sites on the test server. | 92 // Support multiple sites on the test server. |
| 92 host_resolver()->AddRule("*", "127.0.0.1"); | 93 host_resolver()->AddRule("*", "127.0.0.1"); |
| 93 ASSERT_TRUE(test_server()->Start()); | 94 ASSERT_TRUE(embedded_test_server()->Start()); |
| 94 | 95 |
| 95 foo_host_port_ = test_server()->host_port_pair(); | 96 foo_host_port_ = embedded_test_server()->host_port_pair(); |
| 96 foo_host_port_.set_host(foo_com_); | 97 foo_host_port_.set_host(foo_com_); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void StartEmbeddedServer() { | 100 void StartEmbeddedServer() { |
| 100 // Support multiple sites on the embedded test server. | 101 // Support multiple sites on the embedded test server. |
| 101 host_resolver()->AddRule("*", "127.0.0.1"); | 102 host_resolver()->AddRule("*", "127.0.0.1"); |
| 102 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 103 ASSERT_TRUE(embedded_test_server()->Start()); |
| 103 SetupCrossSiteRedirector(embedded_test_server()); | 104 SetupCrossSiteRedirector(embedded_test_server()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 // Returns a URL on foo.com with the given path. | 107 // Returns a URL on foo.com with the given path. |
| 107 GURL GetCrossSiteURL(const std::string& path) { | 108 GURL GetCrossSiteURL(const std::string& path) { |
| 108 GURL cross_site_url(test_server()->GetURL(path)); | 109 GURL cross_site_url(embedded_test_server()->GetURL(path)); |
| 109 return cross_site_url.ReplaceComponents(replace_host_); | 110 return cross_site_url.ReplaceComponents(replace_host_); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void NavigateToPageWithLinks(Shell* shell) { | 113 void NavigateToPageWithLinks(Shell* shell) { |
| 113 EXPECT_TRUE(NavigateToURL( | 114 EXPECT_TRUE(NavigateToURL( |
| 114 shell, embedded_test_server()->GetURL("/click-noreferrer-links.html"))); | 115 shell, embedded_test_server()->GetURL("/click-noreferrer-links.html"))); |
| 115 | 116 |
| 116 // Rewrite selected links on the page to be actual cross-site (bar.com) | 117 // Rewrite selected links on the page to be actual cross-site (bar.com) |
| 117 // URLs. This does not use the /cross-site/ redirector, since that creates | 118 // URLs. This does not use the /cross-site/ redirector, since that creates |
| 118 // links that initially look same-site. | 119 // links that initially look same-site. |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 // error should not make us ignore future renderer-initiated navigations. | 993 // error should not make us ignore future renderer-initiated navigations. |
| 993 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ClickLinkAfter204Error) { | 994 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ClickLinkAfter204Error) { |
| 994 StartServer(); | 995 StartServer(); |
| 995 | 996 |
| 996 // Get the original SiteInstance for later comparison. | 997 // Get the original SiteInstance for later comparison. |
| 997 scoped_refptr<SiteInstance> orig_site_instance( | 998 scoped_refptr<SiteInstance> orig_site_instance( |
| 998 shell()->web_contents()->GetSiteInstance()); | 999 shell()->web_contents()->GetSiteInstance()); |
| 999 EXPECT_TRUE(orig_site_instance.get() != NULL); | 1000 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 1000 | 1001 |
| 1001 // Load a cross-site page that fails with a 204 error. | 1002 // Load a cross-site page that fails with a 204 error. |
| 1002 EXPECT_TRUE(NavigateToURLAndExpectNoCommit(shell(), | 1003 EXPECT_TRUE( |
| 1003 GetCrossSiteURL("nocontent"))); | 1004 NavigateToURLAndExpectNoCommit(shell(), GetCrossSiteURL("/nocontent"))); |
| 1004 | 1005 |
| 1005 // We should still be looking at the normal page. Because we started from a | 1006 // We should still be looking at the normal page. Because we started from a |
| 1006 // blank new tab, the typed URL will still be visible until the user clears it | 1007 // blank new tab, the typed URL will still be visible until the user clears it |
| 1007 // manually. The last committed URL will be the previous page. | 1008 // manually. The last committed URL will be the previous page. |
| 1008 scoped_refptr<SiteInstance> post_nav_site_instance( | 1009 scoped_refptr<SiteInstance> post_nav_site_instance( |
| 1009 shell()->web_contents()->GetSiteInstance()); | 1010 shell()->web_contents()->GetSiteInstance()); |
| 1010 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 1011 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
| 1011 EXPECT_EQ("/nocontent", | 1012 EXPECT_EQ("/nocontent", |
| 1012 shell()->web_contents()->GetVisibleURL().path()); | 1013 shell()->web_contents()->GetVisibleURL().path()); |
| 1013 EXPECT_FALSE( | 1014 EXPECT_FALSE( |
| 1014 shell()->web_contents()->GetController().GetLastCommittedEntry()); | 1015 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
| 1015 | 1016 |
| 1016 // Renderer-initiated navigations should work. | 1017 // Renderer-initiated navigations should work. |
| 1017 base::string16 expected_title = ASCIIToUTF16("Title Of Awesomeness"); | 1018 base::string16 expected_title = ASCIIToUTF16("Title Of Awesomeness"); |
| 1018 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 1019 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 1019 GURL url = test_server()->GetURL("files/title2.html"); | 1020 GURL url = embedded_test_server()->GetURL("/title2.html"); |
| 1020 EXPECT_TRUE(ExecuteScript( | 1021 EXPECT_TRUE(ExecuteScript( |
| 1021 shell()->web_contents(), | 1022 shell()->web_contents(), |
| 1022 base::StringPrintf("location.href = '%s'", url.spec().c_str()))); | 1023 base::StringPrintf("location.href = '%s'", url.spec().c_str()))); |
| 1023 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 1024 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 1024 | 1025 |
| 1025 // Opens in same tab. | 1026 // Opens in same tab. |
| 1026 EXPECT_EQ(1u, Shell::windows().size()); | 1027 EXPECT_EQ(1u, Shell::windows().size()); |
| 1027 EXPECT_EQ("/files/title2.html", | 1028 EXPECT_EQ("/title2.html", |
| 1028 shell()->web_contents()->GetLastCommittedURL().path()); | 1029 shell()->web_contents()->GetLastCommittedURL().path()); |
| 1029 | 1030 |
| 1030 // Should have the same SiteInstance. | 1031 // Should have the same SiteInstance. |
| 1031 scoped_refptr<SiteInstance> new_site_instance( | 1032 scoped_refptr<SiteInstance> new_site_instance( |
| 1032 shell()->web_contents()->GetSiteInstance()); | 1033 shell()->web_contents()->GetSiteInstance()); |
| 1033 EXPECT_EQ(orig_site_instance, new_site_instance); | 1034 EXPECT_EQ(orig_site_instance, new_site_instance); |
| 1034 } | 1035 } |
| 1035 | 1036 |
| 1036 // Test for crbug.com/9682. We should show the URL for a pending renderer- | 1037 // Test for crbug.com/9682. We should show the URL for a pending renderer- |
| 1037 // initiated navigation in a new tab, until the content of the initial | 1038 // initiated navigation in a new tab, until the content of the initial |
| 1038 // about:blank page is modified by another window. At that point, we should | 1039 // about:blank page is modified by another window. At that point, we should |
| 1039 // revert to showing about:blank to prevent a URL spoof. | 1040 // revert to showing about:blank to prevent a URL spoof. |
| 1040 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ShowLoadingURLUntilSpoof) { | 1041 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ShowLoadingURLUntilSpoof) { |
| 1041 ASSERT_TRUE(test_server()->Start()); | 1042 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1042 | 1043 |
| 1043 // Load a page that can open a URL that won't commit in a new window. | 1044 // Load a page that can open a URL that won't commit in a new window. |
| 1044 NavigateToURL( | 1045 NavigateToURL(shell(), |
| 1045 shell(), test_server()->GetURL("files/click-nocontent-link.html")); | 1046 embedded_test_server()->GetURL("/click-nocontent-link.html")); |
| 1046 WebContents* orig_contents = shell()->web_contents(); | 1047 WebContents* orig_contents = shell()->web_contents(); |
| 1047 | 1048 |
| 1048 // Click a /nocontent link that opens in a new window but never commits. | 1049 // Click a /nocontent link that opens in a new window but never commits. |
| 1049 ShellAddedObserver new_shell_observer; | 1050 ShellAddedObserver new_shell_observer; |
| 1050 bool success = false; | 1051 bool success = false; |
| 1051 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1052 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1052 orig_contents, | 1053 orig_contents, |
| 1053 "window.domAutomationController.send(clickNoContentTargetedLink());", | 1054 "window.domAutomationController.send(clickNoContentTargetedLink());", |
| 1054 &success)); | 1055 &success)); |
| 1055 EXPECT_TRUE(success); | 1056 EXPECT_TRUE(success); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1081 // bar. | 1082 // bar. |
| 1082 EXPECT_FALSE(contents->GetController().GetVisibleEntry()); | 1083 EXPECT_FALSE(contents->GetController().GetVisibleEntry()); |
| 1083 } | 1084 } |
| 1084 | 1085 |
| 1085 // Test for crbug.com/9682. We should not show the URL for a pending renderer- | 1086 // Test for crbug.com/9682. We should not show the URL for a pending renderer- |
| 1086 // initiated navigation in a new tab if it is not the initial navigation. In | 1087 // initiated navigation in a new tab if it is not the initial navigation. In |
| 1087 // this case, the renderer will not notify us of a modification, so we cannot | 1088 // this case, the renderer will not notify us of a modification, so we cannot |
| 1088 // show the pending URL without allowing a spoof. | 1089 // show the pending URL without allowing a spoof. |
| 1089 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1090 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1090 DontShowLoadingURLIfNotInitialNav) { | 1091 DontShowLoadingURLIfNotInitialNav) { |
| 1091 ASSERT_TRUE(test_server()->Start()); | 1092 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1092 | 1093 |
| 1093 // Load a page that can open a URL that won't commit in a new window. | 1094 // Load a page that can open a URL that won't commit in a new window. |
| 1094 NavigateToURL( | 1095 NavigateToURL(shell(), |
| 1095 shell(), test_server()->GetURL("files/click-nocontent-link.html")); | 1096 embedded_test_server()->GetURL("/click-nocontent-link.html")); |
| 1096 WebContents* orig_contents = shell()->web_contents(); | 1097 WebContents* orig_contents = shell()->web_contents(); |
| 1097 | 1098 |
| 1098 // Click a /nocontent link that opens in a new window but never commits. | 1099 // Click a /nocontent link that opens in a new window but never commits. |
| 1099 // By using an onclick handler that first creates the window, the slow | 1100 // By using an onclick handler that first creates the window, the slow |
| 1100 // navigation is not considered an initial navigation. | 1101 // navigation is not considered an initial navigation. |
| 1101 ShellAddedObserver new_shell_observer; | 1102 ShellAddedObserver new_shell_observer; |
| 1102 bool success = false; | 1103 bool success = false; |
| 1103 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1104 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 1104 orig_contents, | 1105 orig_contents, |
| 1105 "window.domAutomationController.send(" | 1106 "window.domAutomationController.send(" |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 RestoreFileAccessForHistoryNavigation | 1708 RestoreFileAccessForHistoryNavigation |
| 1708 #endif | 1709 #endif |
| 1709 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1710 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1710 MAYBE_RestoreFileAccessForHistoryNavigation) { | 1711 MAYBE_RestoreFileAccessForHistoryNavigation) { |
| 1711 StartServer(); | 1712 StartServer(); |
| 1712 base::FilePath file; | 1713 base::FilePath file; |
| 1713 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); | 1714 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); |
| 1714 file = file.AppendASCII("bar"); | 1715 file = file.AppendASCII("bar"); |
| 1715 | 1716 |
| 1716 // Navigate to url and get it to reference a file in its PageState. | 1717 // Navigate to url and get it to reference a file in its PageState. |
| 1717 GURL url1(test_server()->GetURL("files/file_input.html")); | 1718 GURL url1(embedded_test_server()->GetURL("/file_input.html")); |
| 1718 NavigateToURL(shell(), url1); | 1719 NavigateToURL(shell(), url1); |
| 1719 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | 1720 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
| 1720 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); | 1721 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); |
| 1721 shell()->web_contents()->SetDelegate(delegate.get()); | 1722 shell()->web_contents()->SetDelegate(delegate.get()); |
| 1722 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 1723 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 1723 "document.getElementById('fileinput').click();")); | 1724 "document.getElementById('fileinput').click();")); |
| 1724 EXPECT_TRUE(delegate->file_chosen()); | 1725 EXPECT_TRUE(delegate->file_chosen()); |
| 1725 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1726 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1726 process_id, file)); | 1727 process_id, file)); |
| 1727 | 1728 |
| 1728 // Navigate to a different process without access to the file, and wait for | 1729 // Navigate to a different process without access to the file, and wait for |
| 1729 // the old process to exit. | 1730 // the old process to exit. |
| 1730 RenderProcessHostWatcher exit_observer( | 1731 RenderProcessHostWatcher exit_observer( |
| 1731 shell()->web_contents()->GetRenderProcessHost(), | 1732 shell()->web_contents()->GetRenderProcessHost(), |
| 1732 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 1733 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
| 1733 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); | 1734 NavigateToURL(shell(), GetCrossSiteURL("/title1.html")); |
| 1734 exit_observer.Wait(); | 1735 exit_observer.Wait(); |
| 1735 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1736 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1736 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); | 1737 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); |
| 1737 | 1738 |
| 1738 // Ensure that the file ended up in the PageState of the previous entry. | 1739 // Ensure that the file ended up in the PageState of the previous entry. |
| 1739 NavigationEntry* prev_entry = | 1740 NavigationEntry* prev_entry = |
| 1740 shell()->web_contents()->GetController().GetEntryAtIndex(0); | 1741 shell()->web_contents()->GetController().GetEntryAtIndex(0); |
| 1741 EXPECT_EQ(url1, prev_entry->GetURL()); | 1742 EXPECT_EQ(url1, prev_entry->GetURL()); |
| 1742 const std::vector<base::FilePath>& files = | 1743 const std::vector<base::FilePath>& files = |
| 1743 prev_entry->GetPageState().GetReferencedFiles(); | 1744 prev_entry->GetPageState().GetReferencedFiles(); |
| 1744 ASSERT_EQ(1U, files.size()); | 1745 ASSERT_EQ(1U, files.size()); |
| 1745 EXPECT_EQ(file, files.at(0)); | 1746 EXPECT_EQ(file, files.at(0)); |
| 1746 | 1747 |
| 1747 // Go back, ending up in a different RenderProcessHost than before. | 1748 // Go back, ending up in a different RenderProcessHost than before. |
| 1748 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); | 1749 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); |
| 1749 shell()->web_contents()->GetController().GoBack(); | 1750 shell()->web_contents()->GetController().GoBack(); |
| 1750 back_nav_load_observer.Wait(); | 1751 back_nav_load_observer.Wait(); |
| 1751 EXPECT_NE(process_id, | 1752 EXPECT_NE(process_id, |
| 1752 shell()->web_contents()->GetRenderProcessHost()->GetID()); | 1753 shell()->web_contents()->GetRenderProcessHost()->GetID()); |
| 1753 | 1754 |
| 1754 // Ensure that the file access still exists in the new process ID. | 1755 // Ensure that the file access still exists in the new process ID. |
| 1755 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1756 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1756 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); | 1757 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); |
| 1757 | 1758 |
| 1758 // Navigate to a same site page to trigger a PageState update and ensure the | 1759 // Navigate to a same site page to trigger a PageState update and ensure the |
| 1759 // renderer is not killed. | 1760 // renderer is not killed. |
| 1760 EXPECT_TRUE( | 1761 EXPECT_TRUE( |
| 1761 NavigateToURL(shell(), test_server()->GetURL("files/title2.html"))); | 1762 NavigateToURL(shell(), embedded_test_server()->GetURL("/title2.html"))); |
| 1762 } | 1763 } |
| 1763 | 1764 |
| 1764 // Test for http://crbug.com/441966. | 1765 // Test for http://crbug.com/441966. |
| 1765 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 1766 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 1766 RestoreSubframeFileAccessForHistoryNavigation) { | 1767 RestoreSubframeFileAccessForHistoryNavigation) { |
| 1767 StartServer(); | 1768 StartServer(); |
| 1768 base::FilePath file; | 1769 base::FilePath file; |
| 1769 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); | 1770 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file)); |
| 1770 file = file.AppendASCII("bar"); | 1771 file = file.AppendASCII("bar"); |
| 1771 | 1772 |
| 1772 // Navigate to url and get it to reference a file in its PageState. | 1773 // Navigate to url and get it to reference a file in its PageState. |
| 1773 GURL url1(test_server()->GetURL("files/file_input_subframe.html")); | 1774 GURL url1(embedded_test_server()->GetURL("/file_input_subframe.html")); |
| 1774 NavigateToURL(shell(), url1); | 1775 NavigateToURL(shell(), url1); |
| 1775 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | 1776 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 1776 FrameTreeNode* root = wc->GetFrameTree()->root(); | 1777 FrameTreeNode* root = wc->GetFrameTree()->root(); |
| 1777 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); | 1778 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
| 1778 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); | 1779 scoped_ptr<FileChooserDelegate> delegate(new FileChooserDelegate(file)); |
| 1779 shell()->web_contents()->SetDelegate(delegate.get()); | 1780 shell()->web_contents()->SetDelegate(delegate.get()); |
| 1780 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 1781 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), |
| 1781 "document.getElementById('fileinput').click();")); | 1782 "document.getElementById('fileinput').click();")); |
| 1782 EXPECT_TRUE(delegate->file_chosen()); | 1783 EXPECT_TRUE(delegate->file_chosen()); |
| 1783 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1784 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1784 process_id, file)); | 1785 process_id, file)); |
| 1785 | 1786 |
| 1786 // Navigate to a different process without access to the file, and wait for | 1787 // Navigate to a different process without access to the file, and wait for |
| 1787 // the old process to exit. | 1788 // the old process to exit. |
| 1788 RenderProcessHostWatcher exit_observer( | 1789 RenderProcessHostWatcher exit_observer( |
| 1789 shell()->web_contents()->GetRenderProcessHost(), | 1790 shell()->web_contents()->GetRenderProcessHost(), |
| 1790 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 1791 RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
| 1791 NavigateToURL(shell(), GetCrossSiteURL("files/title1.html")); | 1792 NavigateToURL(shell(), GetCrossSiteURL("/title1.html")); |
| 1792 exit_observer.Wait(); | 1793 exit_observer.Wait(); |
| 1793 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 1794 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 1794 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); | 1795 shell()->web_contents()->GetRenderProcessHost()->GetID(), file)); |
| 1795 | 1796 |
| 1796 // Ensure that the file ended up in the PageState of the previous entry. | 1797 // Ensure that the file ended up in the PageState of the previous entry. |
| 1797 NavigationEntry* prev_entry = | 1798 NavigationEntry* prev_entry = |
| 1798 shell()->web_contents()->GetController().GetEntryAtIndex(0); | 1799 shell()->web_contents()->GetController().GetEntryAtIndex(0); |
| 1799 EXPECT_EQ(url1, prev_entry->GetURL()); | 1800 EXPECT_EQ(url1, prev_entry->GetURL()); |
| 1800 const std::vector<base::FilePath>& files = | 1801 const std::vector<base::FilePath>& files = |
| 1801 prev_entry->GetPageState().GetReferencedFiles(); | 1802 prev_entry->GetPageState().GetReferencedFiles(); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 popup_root->current_frame_host()->render_view_host()->IsRenderViewLive()); | 2208 popup_root->current_frame_host()->render_view_host()->IsRenderViewLive()); |
| 2208 | 2209 |
| 2209 // Navigate the main tab to the site of the popup. This will cause the | 2210 // Navigate the main tab to the site of the popup. This will cause the |
| 2210 // RenderView for b.com in the main tab to be recreated. If the issue | 2211 // RenderView for b.com in the main tab to be recreated. If the issue |
| 2211 // is not fixed, this will result in process crash and failing test. | 2212 // is not fixed, this will result in process crash and failing test. |
| 2212 EXPECT_TRUE(NavigateToURL( | 2213 EXPECT_TRUE(NavigateToURL( |
| 2213 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); | 2214 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); |
| 2214 } | 2215 } |
| 2215 | 2216 |
| 2216 } // namespace content | 2217 } // namespace content |
| OLD | NEW |