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

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

Issue 2080223002: Revert of Fixing renderer's access to a file from HTTP POST (after a xsite transfer). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory>
6
7 #include "base/command_line.h" 5 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h" 6 #include "base/macros.h"
12 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
13 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/loader/resource_dispatcher_host_impl.h" 8 #include "content/browser/loader/resource_dispatcher_host_impl.h"
15 #include "content/public/browser/navigation_entry.h" 9 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/resource_dispatcher_host_delegate.h" 10 #include "content/public/browser/resource_dispatcher_host_delegate.h"
18 #include "content/public/browser/resource_throttle.h" 11 #include "content/public/browser/resource_throttle.h"
19 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
21 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
22 #include "content/public/test/content_browser_test_utils.h" 15 #include "content/public/test/content_browser_test_utils.h"
23 #include "content/public/test/test_navigation_observer.h" 16 #include "content/public/test/test_navigation_observer.h"
24 #include "content/shell/browser/shell.h" 17 #include "content/shell/browser/shell.h"
25 #include "content/shell/browser/shell_content_browser_client.h" 18 #include "content/shell/browser/shell_content_browser_client.h"
26 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" 19 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
27 #include "content/test/content_browser_test_utils_internal.h"
28 #include "net/base/escape.h" 20 #include "net/base/escape.h"
29 #include "net/dns/mock_host_resolver.h" 21 #include "net/dns/mock_host_resolver.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
32 #include "net/url_request/url_request_status.h" 24 #include "net/url_request/url_request_status.h"
33 #include "testing/gmock/include/gmock/gmock-matchers.h"
34 #include "url/gurl.h" 25 #include "url/gurl.h"
35 26
36 namespace content { 27 namespace content {
37 28
38 // Tracks a single request for a specified URL, and allows waiting until the 29 // Tracks a single request for a specified URL, and allows waiting until the
39 // request is destroyed, and then inspecting whether it completed successfully. 30 // request is destroyed, and then inspecting whether it completed successfully.
40 class TrackingResourceDispatcherHostDelegate 31 class TrackingResourceDispatcherHostDelegate
41 : public ShellResourceDispatcherHostDelegate { 32 : public ShellResourceDispatcherHostDelegate {
42 public: 33 public:
43 TrackingResourceDispatcherHostDelegate() : throttle_created_(false) { 34 TrackingResourceDispatcherHostDelegate() : throttle_created_(false) {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 EXPECT_EQ(1, controller.GetEntryCount()); 411 EXPECT_EQ(1, controller.GetEntryCount());
421 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 412 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
422 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); 413 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
423 414
424 // Make sure the request for url2 did not complete. 415 // Make sure the request for url2 did not complete.
425 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); 416 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted());
426 417
427 shell()->web_contents()->SetDelegate(old_delegate); 418 shell()->web_contents()->SetDelegate(old_delegate);
428 } 419 }
429 420
430 // Test that verifies that a cross-process transfer retains ability to read
431 // files encapsulated by HTTP POST body that is forwarded to the new renderer.
432 // Invalid handling of this scenario has been suspected as the cause of at least
433 // some of the renderer kills tracked in https://crbug.com/613260.
434 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, PostWithFileData) {
435 // Navigate to the page with form that posts via 307 redirection to
436 // |redirect_target_url| (cross-site from |form_url|). Using 307 (rather than
437 // 302) redirection is important to preserve the HTTP method and POST body.
438 GURL form_url(embedded_test_server()->GetURL(
439 "a.com", "/form_that_posts_cross_site.html"));
440 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall"));
441 EXPECT_TRUE(NavigateToURL(shell(), form_url));
442
443 // Prepare a file to upload.
444 base::ScopedTempDir temp_dir;
445 base::FilePath file_path;
446 std::string file_content("test-file-content");
447 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
448 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path));
449 ASSERT_LT(
450 0, base::WriteFile(file_path, file_content.data(), file_content.size()));
451
452 // Fill out the form to refer to the test file.
453 std::unique_ptr<FileChooserDelegate> delegate(
454 new FileChooserDelegate(file_path));
455 shell()->web_contents()->SetDelegate(delegate.get());
456 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
457 "document.getElementById('file').click();"));
458 EXPECT_TRUE(delegate->file_chosen());
459
460 // Remember the old process id for a sanity check below.
461 int old_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
462
463 // Submit the form.
464 TestNavigationObserver form_post_observer(shell()->web_contents(), 1);
465 EXPECT_TRUE(
466 ExecuteScript(shell(), "document.getElementById('file-form').submit();"));
467 form_post_observer.Wait();
468
469 // Verify that we arrived at the expected, redirected location.
470 EXPECT_EQ(redirect_target_url,
471 shell()->web_contents()->GetLastCommittedURL());
472
473 // Verify that the test really verifies access of a *new* renderer process.
474 int new_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
475 ASSERT_NE(new_process_id, old_process_id);
476
477 // MAIN VERIFICATION: Check if the new renderer process is able to read the
478 // file.
479 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
480 new_process_id, file_path));
481
482 // Verify that POST body got preserved by 307 redirect. This expectation
483 // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7
484 std::string actual_page_body;
485 EXPECT_TRUE(ExecuteScriptAndExtractString(
486 shell()->web_contents(),
487 "window.domAutomationController.send("
488 "document.getElementsByTagName('pre')[0].innerText);",
489 &actual_page_body));
490 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content));
491 EXPECT_THAT(actual_page_body,
492 ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe()));
493 EXPECT_THAT(actual_page_body,
494 ::testing::HasSubstr("form-data; name=\"file\""));
495 }
496
497 } // namespace content 421 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698