| OLD | NEW |
| 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> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, PostWithFileData) { | 434 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, PostWithFileData) { |
| 435 // Navigate to the page with form that posts via 307 redirection to | 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 | 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. | 437 // 302) redirection is important to preserve the HTTP method and POST body. |
| 438 GURL form_url(embedded_test_server()->GetURL( | 438 GURL form_url(embedded_test_server()->GetURL( |
| 439 "a.com", "/form_that_posts_cross_site.html")); | 439 "a.com", "/form_that_posts_cross_site.html")); |
| 440 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall")); | 440 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall")); |
| 441 EXPECT_TRUE(NavigateToURL(shell(), form_url)); | 441 EXPECT_TRUE(NavigateToURL(shell(), form_url)); |
| 442 | 442 |
| 443 // Prepare a file to upload. | 443 // Prepare a file to upload. |
| 444 base::ThreadRestrictions::ScopedAllowIO allow_io_for_temp_dir; |
| 444 base::ScopedTempDir temp_dir; | 445 base::ScopedTempDir temp_dir; |
| 445 base::FilePath file_path; | 446 base::FilePath file_path; |
| 446 std::string file_content("test-file-content"); | 447 std::string file_content("test-file-content"); |
| 447 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 448 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 448 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path)); | 449 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path)); |
| 449 ASSERT_LT( | 450 ASSERT_LT( |
| 450 0, base::WriteFile(file_path, file_content.data(), file_content.size())); | 451 0, base::WriteFile(file_path, file_content.data(), file_content.size())); |
| 451 | 452 |
| 452 // Fill out the form to refer to the test file. | 453 // Fill out the form to refer to the test file. |
| 453 std::unique_ptr<FileChooserDelegate> delegate( | 454 std::unique_ptr<FileChooserDelegate> delegate( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 "document.getElementsByTagName('pre')[0].innerText);", | 489 "document.getElementsByTagName('pre')[0].innerText);", |
| 489 &actual_page_body)); | 490 &actual_page_body)); |
| 490 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content)); | 491 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content)); |
| 491 EXPECT_THAT(actual_page_body, | 492 EXPECT_THAT(actual_page_body, |
| 492 ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe())); | 493 ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe())); |
| 493 EXPECT_THAT(actual_page_body, | 494 EXPECT_THAT(actual_page_body, |
| 494 ::testing::HasSubstr("form-data; name=\"file\"")); | 495 ::testing::HasSubstr("form-data; name=\"file\"")); |
| 495 } | 496 } |
| 496 | 497 |
| 497 } // namespace content | 498 } // namespace content |
| OLD | NEW |