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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::ThreadRestrictions::ScopedAllowIO allow_io_for_temp_dir; |
445 base::ScopedTempDir temp_dir; | 445 base::ScopedTempDir temp_dir; |
446 base::FilePath file_path; | 446 base::FilePath file_path; |
447 std::string file_content("test-file-content"); | 447 std::string file_content("test-file-content"); |
448 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 448 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
449 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path)); | 449 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &file_path)); |
450 ASSERT_LT( | 450 ASSERT_LT( |
451 0, base::WriteFile(file_path, file_content.data(), file_content.size())); | 451 0, base::WriteFile(file_path, file_content.data(), file_content.size())); |
452 | 452 |
453 // Fill out the form to refer to the test file. | 453 // Fill out the form to refer to the test file. |
454 std::unique_ptr<FileChooserDelegate> delegate( | 454 std::unique_ptr<FileChooserDelegate> delegate( |
455 new FileChooserDelegate(file_path)); | 455 new FileChooserDelegate(file_path)); |
456 shell()->web_contents()->SetDelegate(delegate.get()); | 456 shell()->web_contents()->SetDelegate(delegate.get()); |
457 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 457 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
458 "document.getElementById('file').click();")); | 458 "document.getElementById('file').click();")); |
459 EXPECT_TRUE(delegate->file_chosen()); | 459 EXPECT_TRUE(delegate->file_chosen()); |
(...skipping 29 matching lines...) Expand all Loading... |
489 "document.getElementsByTagName('pre')[0].innerText);", | 489 "document.getElementsByTagName('pre')[0].innerText);", |
490 &actual_page_body)); | 490 &actual_page_body)); |
491 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content)); | 491 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content)); |
492 EXPECT_THAT(actual_page_body, | 492 EXPECT_THAT(actual_page_body, |
493 ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe())); | 493 ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe())); |
494 EXPECT_THAT(actual_page_body, | 494 EXPECT_THAT(actual_page_body, |
495 ::testing::HasSubstr("form-data; name=\"file\"")); | 495 ::testing::HasSubstr("form-data; name=\"file\"")); |
496 } | 496 } |
497 | 497 |
498 } // namespace content | 498 } // namespace content |
OLD | NEW |