Index: content/browser/frame_host/render_frame_host_manager_browsertest.cc |
diff --git a/content/browser/frame_host/render_frame_host_manager_browsertest.cc b/content/browser/frame_host/render_frame_host_manager_browsertest.cc |
index 10fa48b1d89ab1bf1d4abe58a18622aa1ab53adf..340d2e1b6ea5aa36b88c12b72b551e5b436f5747 100644 |
--- a/content/browser/frame_host/render_frame_host_manager_browsertest.cc |
+++ b/content/browser/frame_host/render_frame_host_manager_browsertest.cc |
@@ -5,9 +5,12 @@ |
#include <stddef.h> |
#include <stdint.h> |
+#include <memory> |
#include <set> |
#include "base/command_line.h" |
+#include "base/files/file_util.h" |
+#include "base/files/scoped_temp_dir.h" |
#include "base/json/json_reader.h" |
#include "base/location.h" |
#include "base/memory/ref_counted.h" |
@@ -2815,4 +2818,72 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
EXPECT_EQ(title, entry->GetTitle()); |
} |
+// Test that verifies that a cross-process transfer retains ability to read |
+// files encapsulated by HTTP POST body that is forwarded to the new renderer. |
+// Invalid handling of this scenario has been suspected as the cause of at least |
+// some of the renderer kills tracked in https://crbug.com/613260. |
+IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, PostWithFileData) { |
+ // Navigate to the page with form that posts via 307 redirection to |
Charlie Reis
2016/06/16 20:18:00
Can you elaborate a bit that 307 preserves the POS
Łukasz Anforowicz
2016/06/16 22:05:04
Done.
|
+ // |redirect_target_url| (cross-site from |form_url|). |
+ StartEmbeddedServer(); |
+ GURL form_url(embedded_test_server()->GetURL( |
+ "a.com", "/form_that_posts_cross_site.html")); |
+ GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall")); |
+ EXPECT_TRUE(NavigateToURL(shell(), form_url)); |
+ |
+ // Prepare a file to upload. |
+ base::ScopedTempDir temp_dir; |
+ base::FilePath file_path; |
+ std::string file_content("test-file-content"); |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path)); |
+ ASSERT_LT( |
+ 0, base::WriteFile(file_path, file_content.data(), file_content.size())); |
+ |
+ // Fill out the form to refer to the test file. |
+ std::unique_ptr<FileChooserDelegate> delegate( |
+ new FileChooserDelegate(file_path)); |
+ shell()->web_contents()->SetDelegate(delegate.get()); |
+ EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
+ "document.getElementById('file').click();")); |
+ EXPECT_TRUE(delegate->file_chosen()); |
+ |
+ // Remember the old process id for a sanity check below. |
+ int old_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
+ |
+ // Submit the form. |
+ TestNavigationObserver form_post_observer(shell()->web_contents(), 1); |
+ EXPECT_TRUE( |
+ ExecuteScript(shell(), "document.getElementById('file-form').submit();")); |
+ form_post_observer.Wait(); |
+ |
+ // Verify that we arrived at the expected, redirected location. |
+ EXPECT_EQ(redirect_target_url, |
+ shell()->web_contents()->GetLastCommittedURL()); |
+ |
+ // Verify that the test really verifies access of a *new* renderer process. |
+ int new_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID(); |
+ if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) |
Charlie Reis
2016/06/16 20:18:00
This test is actually about transfers, right? May
Łukasz Anforowicz
2016/06/16 22:05:04
Good point. Done.
Note that this required extrac
Charlie Reis
2016/06/16 22:20:00
Acknowledged.
|
+ ASSERT_NE(new_process_id, old_process_id); |
+ |
+ // MAIN VERIFICATION: Check if the new renderer process is able to read the |
+ // file. |
+ EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
+ new_process_id, file_path)); |
+ |
+ // Verify that POST body got preserved by 307 redirect. This expectation |
+ // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7 |
+ std::string actual_page_body; |
+ EXPECT_TRUE(ExecuteScriptAndExtractString( |
+ shell()->web_contents(), |
+ "window.domAutomationController.send(" |
+ "document.getElementsByTagName('pre')[0].innerText);", |
+ &actual_page_body)); |
+ EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content)); |
+ EXPECT_THAT(actual_page_body, |
+ ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe())); |
+ EXPECT_THAT(actual_page_body, |
+ ::testing::HasSubstr("form-data; name=\"file\"")); |
+} |
+ |
} // namespace content |