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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 2062523002: 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: One more test expectation. 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/session_history_browsertest.cc » ('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 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory>
8 #include <set> 9 #include <set>
9 10
10 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
11 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
12 #include "base/location.h" 15 #include "base/location.h"
13 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
14 #include "base/path_service.h" 17 #include "base/path_service.h"
15 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
17 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/values.h" 22 #include "base/values.h"
20 #include "build/build_config.h" 23 #include "build/build_config.h"
(...skipping 2728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2749 rfh_a->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 2752 rfh_a->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
2750 TestNavigationObserver commit_observer(web_contents); 2753 TestNavigationObserver commit_observer(web_contents);
2751 shell()->LoadURL(embedded_test_server()->GetURL("b.com", "/title1.html")); 2754 shell()->LoadURL(embedded_test_server()->GetURL("b.com", "/title1.html"));
2752 commit_observer.Wait(); 2755 commit_observer.Wait();
2753 exit_observer.Wait(); 2756 exit_observer.Wait();
2754 2757
2755 // Ensure the entry's title hasn't changed after the ignored commit. 2758 // Ensure the entry's title hasn't changed after the ignored commit.
2756 EXPECT_EQ(title, entry->GetTitle()); 2759 EXPECT_EQ(title, entry->GetTitle());
2757 } 2760 }
2758 2761
2762 // Test that verifies that a cross-process transfer retains ability to read
2763 // files encapsulated by HTTP POST body that is forwarded to the new renderer.
2764 // Invalid handling of this scenario has been suspected as the cause of at least
2765 // some of the renderer kills tracked in https://crbug.com/613260.
2766 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, PostWithFileData) {
2767 // Navigate to the page with form that posts via 307 redirection to
2768 // |redirect_target_url| (cross-site from |form_url|).
2769 StartEmbeddedServer();
2770 GURL form_url(embedded_test_server()->GetURL(
2771 "a.com", "/form_that_posts_cross_site.html"));
2772 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall"));
2773 EXPECT_TRUE(NavigateToURL(shell(), form_url));
2774
2775 // Prepare a file to upload.
2776 base::ScopedTempDir temp_dir;
2777 base::FilePath file_path;
2778 std::string file_content("test-file-content");
2779 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2780 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path));
2781 LOG(ERROR) << "Temporary file = " << file_path.value();
2782 ASSERT_LT(
2783 0, base::WriteFile(file_path, file_content.data(), file_content.size()));
2784
2785 // Fill out the form to refer to the test file.
2786 std::unique_ptr<FileChooserDelegate> delegate(
2787 new FileChooserDelegate(file_path));
2788 shell()->web_contents()->SetDelegate(delegate.get());
2789 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
2790 "document.getElementById('file').click();"));
2791 EXPECT_TRUE(delegate->file_chosen());
2792
2793 // Check if the original renderer process is able to read the file
2794 // (it shouldn't - it doesn't need to read the file; only the new
2795 // renderer process reads the file [for XSSAuditor purposes]).
2796 int old_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
2797 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2798 old_process_id, file_path));
Łukasz Anforowicz 2016/06/10 23:07:04 This test expectation fails today - sounds like an
2799
2800 // Submit the form.
2801 TestNavigationObserver form_post_observer(shell()->web_contents(), 1);
2802 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
2803 "document.getElementById('file-form').submit();"));
2804 form_post_observer.Wait();
2805
2806 // Verify that we arrived at the expected, redirected location.
2807 EXPECT_EQ(redirect_target_url,
2808 shell()->web_contents()->GetLastCommittedURL());
2809
2810 // Check if the new renderer process is able to read the file.
2811 int new_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
2812 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2813 new_process_id, file_path));
2814 // Check that the old renderer cannot read the file.
2815 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2816 old_process_id, file_path));
Łukasz Anforowicz 2016/06/10 23:07:04 This test expectation also fails today - it seems
2817
2818 // Verify that POST body got preserved by 307 redirect. This expectation
2819 // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7
2820 std::string actual_page_body;
2821 EXPECT_TRUE(ExecuteScriptAndExtractString(
2822 shell()->web_contents(),
2823 "window.domAutomationController.send("
2824 "document.getElementsByTagName('pre')[0].innerText);",
2825 &actual_page_body));
2826 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content));
2827 EXPECT_THAT(actual_page_body,
2828 ::testing::HasSubstr(file_path.BaseName().value()));
2829 EXPECT_THAT(actual_page_body,
2830 ::testing::HasSubstr("form-data; name=\"file\""));
2831 }
2832
2759 } // namespace content 2833 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/session_history_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698