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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/test/test_file_util.h" | 23 #include "base/test/test_file_util.h" |
| 24 #include "base/threading/thread_restrictions.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 #include "chrome/app/chrome_command_ids.h" | 26 #include "chrome/app/chrome_command_ids.h" |
26 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 27 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
27 #include "chrome/browser/download/download_history.h" | 28 #include "chrome/browser/download/download_history.h" |
28 #include "chrome/browser/download/download_prefs.h" | 29 #include "chrome/browser/download/download_prefs.h" |
29 #include "chrome/browser/download/download_service.h" | 30 #include "chrome/browser/download/download_service.h" |
30 #include "chrome/browser/download/download_service_factory.h" | 31 #include "chrome/browser/download/download_service_factory.h" |
31 #include "chrome/browser/download/save_package_file_picker.h" | 32 #include "chrome/browser/download/save_package_file_picker.h" |
32 #include "chrome/browser/net/url_request_mock_util.h" | 33 #include "chrome/browser/net/url_request_mock_util.h" |
33 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 }; | 433 }; |
433 | 434 |
434 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 435 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
435 GURL url = NavigateToMockURL("a"); | 436 GURL url = NavigateToMockURL("a"); |
436 | 437 |
437 base::FilePath full_file_name, dir; | 438 base::FilePath full_file_name, dir; |
438 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, | 439 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, |
439 &full_file_name); | 440 &full_file_name); |
440 ASSERT_FALSE(HasFailure()); | 441 ASSERT_FALSE(HasFailure()); |
441 | 442 |
| 443 base::ThreadRestrictions::ScopedAllowIO allow_io; |
442 EXPECT_TRUE(base::PathExists(full_file_name)); | 444 EXPECT_TRUE(base::PathExists(full_file_name)); |
443 EXPECT_FALSE(base::PathExists(dir)); | 445 EXPECT_FALSE(base::PathExists(dir)); |
444 EXPECT_TRUE(base::ContentsEqual(GetTestDirFile("a.htm"), full_file_name)); | 446 EXPECT_TRUE(base::ContentsEqual(GetTestDirFile("a.htm"), full_file_name)); |
445 } | 447 } |
446 | 448 |
447 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 449 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
448 GURL url = NavigateToMockURL("a"); | 450 GURL url = NavigateToMockURL("a"); |
449 DownloadManager* manager(GetDownloadManager()); | 451 DownloadManager* manager(GetDownloadManager()); |
450 std::vector<DownloadItem*> downloads; | 452 std::vector<DownloadItem*> downloads; |
451 manager->GetAllDownloads(&downloads); | 453 manager->GetAllDownloads(&downloads); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 521 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
520 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 522 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
521 std::vector<DownloadItem*> items; | 523 std::vector<DownloadItem*> items; |
522 creation_observer.WaitForDownloadItem(&items); | 524 creation_observer.WaitForDownloadItem(&items); |
523 ASSERT_TRUE(items.size() == 1); | 525 ASSERT_TRUE(items.size() == 1); |
524 | 526 |
525 // Close the tab; does this cancel the download? | 527 // Close the tab; does this cancel the download? |
526 GetCurrentTab(browser())->Close(); | 528 GetCurrentTab(browser())->Close(); |
527 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); | 529 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); |
528 | 530 |
| 531 base::ThreadRestrictions::ScopedAllowIO allow_io; |
529 EXPECT_FALSE(base::PathExists(full_file_name)); | 532 EXPECT_FALSE(base::PathExists(full_file_name)); |
530 EXPECT_FALSE(base::PathExists(dir)); | 533 EXPECT_FALSE(base::PathExists(dir)); |
531 } | 534 } |
532 | 535 |
533 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { | 536 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { |
534 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); | 537 GURL mock_url = URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); |
535 GURL view_source_url = | 538 GURL view_source_url = |
536 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); | 539 GURL(content::kViewSourceScheme + std::string(":") + mock_url.spec()); |
537 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 540 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
538 "save_page/a.htm"); | 541 "save_page/a.htm"); |
539 ui_test_utils::NavigateToURL(browser(), view_source_url); | 542 ui_test_utils::NavigateToURL(browser(), view_source_url); |
540 | 543 |
541 base::FilePath full_file_name, dir; | 544 base::FilePath full_file_name, dir; |
542 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, | 545 SaveCurrentTab(actual_page_url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, |
543 &dir, &full_file_name); | 546 &dir, &full_file_name); |
544 ASSERT_FALSE(HasFailure()); | 547 ASSERT_FALSE(HasFailure()); |
545 | 548 |
| 549 base::ThreadRestrictions::ScopedAllowIO allow_io; |
546 EXPECT_TRUE(base::PathExists(full_file_name)); | 550 EXPECT_TRUE(base::PathExists(full_file_name)); |
547 EXPECT_FALSE(base::PathExists(dir)); | 551 EXPECT_FALSE(base::PathExists(dir)); |
548 EXPECT_TRUE(base::ContentsEqual(GetTestDirFile("a.htm"), full_file_name)); | 552 EXPECT_TRUE(base::ContentsEqual(GetTestDirFile("a.htm"), full_file_name)); |
549 } | 553 } |
550 | 554 |
551 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 555 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
552 GURL url = NavigateToMockURL("b"); | 556 GURL url = NavigateToMockURL("b"); |
553 | 557 |
554 base::FilePath full_file_name, dir; | 558 base::FilePath full_file_name, dir; |
555 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, "b", 3, &dir, | 559 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, "b", 3, &dir, |
556 &full_file_name); | 560 &full_file_name); |
557 ASSERT_FALSE(HasFailure()); | 561 ASSERT_FALSE(HasFailure()); |
558 | 562 |
| 563 base::ThreadRestrictions::ScopedAllowIO allow_io; |
559 EXPECT_TRUE(base::PathExists(full_file_name)); | 564 EXPECT_TRUE(base::PathExists(full_file_name)); |
560 EXPECT_TRUE(base::PathExists(dir)); | 565 EXPECT_TRUE(base::PathExists(dir)); |
561 | 566 |
562 EXPECT_EQ(ReadFileAndCollapseWhitespace(full_file_name), | 567 EXPECT_EQ(ReadFileAndCollapseWhitespace(full_file_name), |
563 ReadFileAndCollapseWhitespace(GetTestDirFile("b.saved1.htm"))); | 568 ReadFileAndCollapseWhitespace(GetTestDirFile("b.saved1.htm"))); |
564 EXPECT_TRUE( | 569 EXPECT_TRUE( |
565 base::ContentsEqual(GetTestDirFile("1.png"), dir.AppendASCII("1.png"))); | 570 base::ContentsEqual(GetTestDirFile("1.png"), dir.AppendASCII("1.png"))); |
566 EXPECT_EQ(ReadFileAndCollapseWhitespace(dir.AppendASCII("1.css")), | 571 EXPECT_EQ(ReadFileAndCollapseWhitespace(dir.AppendASCII("1.css")), |
567 ReadFileAndCollapseWhitespace(GetTestDirFile("1.css"))); | 572 ReadFileAndCollapseWhitespace(GetTestDirFile("1.css"))); |
568 } | 573 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 SavePackageFinishedObserver observer( | 629 SavePackageFinishedObserver observer( |
625 content::BrowserContext::GetDownloadManager(browser()->profile()), | 630 content::BrowserContext::GetDownloadManager(browser()->profile()), |
626 loop_runner->QuitClosure()); | 631 loop_runner->QuitClosure()); |
627 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( | 632 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( |
628 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 633 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
629 | 634 |
630 loop_runner->Run(); | 635 loop_runner->Run(); |
631 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); | 636 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); |
632 persisted.WaitForPersisted(); | 637 persisted.WaitForPersisted(); |
633 | 638 |
| 639 base::ThreadRestrictions::ScopedAllowIO allow_io; |
634 EXPECT_TRUE(base::PathExists(full_file_name)); | 640 EXPECT_TRUE(base::PathExists(full_file_name)); |
635 EXPECT_TRUE(base::PathExists(dir)); | 641 EXPECT_TRUE(base::PathExists(dir)); |
636 | 642 |
637 EXPECT_EQ(ReadFileAndCollapseWhitespace(full_file_name), | 643 EXPECT_EQ(ReadFileAndCollapseWhitespace(full_file_name), |
638 ReadFileAndCollapseWhitespace(GetTestDirFile("b.saved2.htm"))); | 644 ReadFileAndCollapseWhitespace(GetTestDirFile("b.saved2.htm"))); |
639 EXPECT_TRUE( | 645 EXPECT_TRUE( |
640 base::ContentsEqual(GetTestDirFile("1.png"), dir.AppendASCII("1.png"))); | 646 base::ContentsEqual(GetTestDirFile("1.png"), dir.AppendASCII("1.png"))); |
641 EXPECT_EQ(ReadFileAndCollapseWhitespace(dir.AppendASCII("1.css")), | 647 EXPECT_EQ(ReadFileAndCollapseWhitespace(dir.AppendASCII("1.css")), |
642 ReadFileAndCollapseWhitespace(GetTestDirFile("1.css"))); | 648 ReadFileAndCollapseWhitespace(GetTestDirFile("1.css"))); |
643 } | 649 } |
644 | 650 |
645 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 651 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
646 GURL url = NavigateToMockURL("a"); | 652 GURL url = NavigateToMockURL("a"); |
647 | 653 |
648 base::FilePath full_file_name, dir; | 654 base::FilePath full_file_name, dir; |
649 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, | 655 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_ONLY_HTML, "a", 1, &dir, |
650 &full_file_name); | 656 &full_file_name); |
651 ASSERT_FALSE(HasFailure()); | 657 ASSERT_FALSE(HasFailure()); |
652 | 658 |
653 DownloadManager* manager(GetDownloadManager()); | 659 DownloadManager* manager(GetDownloadManager()); |
654 std::vector<DownloadItem*> downloads; | 660 std::vector<DownloadItem*> downloads; |
655 manager->GetAllDownloads(&downloads); | 661 manager->GetAllDownloads(&downloads); |
656 ASSERT_EQ(1UL, downloads.size()); | 662 ASSERT_EQ(1UL, downloads.size()); |
657 | 663 |
658 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId()); | 664 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId()); |
659 downloads[0]->Remove(); | 665 downloads[0]->Remove(); |
660 removed.WaitForRemoved(); | 666 removed.WaitForRemoved(); |
661 | 667 |
| 668 base::ThreadRestrictions::ScopedAllowIO allow_io; |
662 EXPECT_TRUE(base::PathExists(full_file_name)); | 669 EXPECT_TRUE(base::PathExists(full_file_name)); |
663 EXPECT_FALSE(base::PathExists(dir)); | 670 EXPECT_FALSE(base::PathExists(dir)); |
664 EXPECT_TRUE(base::ContentsEqual(GetTestDirFile("a.htm"), full_file_name)); | 671 EXPECT_TRUE(base::ContentsEqual(GetTestDirFile("a.htm"), full_file_name)); |
665 } | 672 } |
666 | 673 |
667 // This tests that a webpage with the title "test.exe" is saved as | 674 // This tests that a webpage with the title "test.exe" is saved as |
668 // "test.exe.htm". | 675 // "test.exe.htm". |
669 // We probably don't care to handle this on Linux or Mac. | 676 // We probably don't care to handle this on Linux or Mac. |
670 #if defined(OS_WIN) | 677 #if defined(OS_WIN) |
671 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { | 678 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { |
672 base::FilePath download_dir = | 679 base::FilePath download_dir = |
673 DownloadPrefs::FromDownloadManager(GetDownloadManager())-> | 680 DownloadPrefs::FromDownloadManager(GetDownloadManager())-> |
674 DownloadPath(); | 681 DownloadPath(); |
675 base::FilePath full_file_name = | 682 base::FilePath full_file_name = |
676 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); | 683 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); |
677 base::FilePath dir = download_dir.AppendASCII("test.exe_files"); | 684 base::FilePath dir = download_dir.AppendASCII("test.exe_files"); |
678 | 685 |
| 686 base::ThreadRestrictions::ScopedAllowIO allow_io; |
679 EXPECT_FALSE(base::PathExists(full_file_name)); | 687 EXPECT_FALSE(base::PathExists(full_file_name)); |
680 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/c.htm"); | 688 GURL url = URLRequestMockHTTPJob::GetMockUrl("save_page/c.htm"); |
681 ui_test_utils::NavigateToURL(browser(), url); | 689 ui_test_utils::NavigateToURL(browser(), url); |
682 | 690 |
683 SavePackageFilePicker::SetShouldPromptUser(false); | 691 SavePackageFilePicker::SetShouldPromptUser(false); |
684 scoped_refptr<content::MessageLoopRunner> loop_runner( | 692 scoped_refptr<content::MessageLoopRunner> loop_runner( |
685 new content::MessageLoopRunner); | 693 new content::MessageLoopRunner); |
686 SavePackageFinishedObserver observer( | 694 SavePackageFinishedObserver observer( |
687 content::BrowserContext::GetDownloadManager(browser()->profile()), | 695 content::BrowserContext::GetDownloadManager(browser()->profile()), |
688 loop_runner->QuitClosure()); | 696 loop_runner->QuitClosure()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 scoped_refptr<content::MessageLoopRunner> loop_runner( | 733 scoped_refptr<content::MessageLoopRunner> loop_runner( |
726 new content::MessageLoopRunner); | 734 new content::MessageLoopRunner); |
727 SavePackageFinishedObserver observer( | 735 SavePackageFinishedObserver observer( |
728 content::BrowserContext::GetDownloadManager(browser()->profile()), | 736 content::BrowserContext::GetDownloadManager(browser()->profile()), |
729 loop_runner->QuitClosure()); | 737 loop_runner->QuitClosure()); |
730 chrome::SavePage(browser()); | 738 chrome::SavePage(browser()); |
731 loop_runner->Run(); | 739 loop_runner->Run(); |
732 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); | 740 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); |
733 persisted.WaitForPersisted(); | 741 persisted.WaitForPersisted(); |
734 | 742 |
| 743 base::ThreadRestrictions::ScopedAllowIO allow_io; |
735 ASSERT_TRUE(base::PathExists(full_file_name)); | 744 ASSERT_TRUE(base::PathExists(full_file_name)); |
736 int64_t actual_file_size = -1; | 745 int64_t actual_file_size = -1; |
737 EXPECT_TRUE(base::GetFileSize(full_file_name, &actual_file_size)); | 746 EXPECT_TRUE(base::GetFileSize(full_file_name, &actual_file_size)); |
738 EXPECT_LE(kFileSizeMin, actual_file_size); | 747 EXPECT_LE(kFileSizeMin, actual_file_size); |
739 | 748 |
740 std::string contents; | 749 std::string contents; |
741 EXPECT_TRUE(base::ReadFileToString(full_file_name, &contents)); | 750 EXPECT_TRUE(base::ReadFileToString(full_file_name, &contents)); |
742 // Test for a CSS encoded character. This used to use HTML encoding. | 751 // Test for a CSS encoded character. This used to use HTML encoding. |
743 EXPECT_THAT(contents, HasSubstr("content: \"\\e003 \\e004 b\"")); | 752 EXPECT_THAT(contents, HasSubstr("content: \"\\e003 \\e004 b\"")); |
744 } | 753 } |
745 | 754 |
746 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) { | 755 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) { |
747 SavePackageFilePicker::SetShouldPromptUser(false); | 756 SavePackageFilePicker::SetShouldPromptUser(false); |
748 GURL url("data:text/plain,foo"); | 757 GURL url("data:text/plain,foo"); |
749 ui_test_utils::NavigateToURL(browser(), url); | 758 ui_test_utils::NavigateToURL(browser(), url); |
750 scoped_refptr<content::MessageLoopRunner> loop_runner( | 759 scoped_refptr<content::MessageLoopRunner> loop_runner( |
751 new content::MessageLoopRunner); | 760 new content::MessageLoopRunner); |
752 SavePackageFinishedObserver observer( | 761 SavePackageFinishedObserver observer( |
753 content::BrowserContext::GetDownloadManager(browser()->profile()), | 762 content::BrowserContext::GetDownloadManager(browser()->profile()), |
754 loop_runner->QuitClosure()); | 763 loop_runner->QuitClosure()); |
755 chrome::SavePage(browser()); | 764 chrome::SavePage(browser()); |
756 loop_runner->Run(); | 765 loop_runner->Run(); |
757 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( | 766 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( |
758 GetDownloadManager())->DownloadPath(); | 767 GetDownloadManager())->DownloadPath(); |
759 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); | 768 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); |
| 769 base::ThreadRestrictions::ScopedAllowIO allow_io; |
760 ASSERT_TRUE(base::PathExists(filename)); | 770 ASSERT_TRUE(base::PathExists(filename)); |
761 std::string contents; | 771 std::string contents; |
762 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); | 772 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); |
763 EXPECT_EQ("foo", contents); | 773 EXPECT_EQ("foo", contents); |
764 } | 774 } |
765 | 775 |
766 // If a save-page-complete operation results in creating subresources that would | 776 // If a save-page-complete operation results in creating subresources that would |
767 // otherwise be considered dangerous, such files should get a .download | 777 // otherwise be considered dangerous, such files should get a .download |
768 // extension appended so that they won't be accidentally executed by the user. | 778 // extension appended so that they won't be accidentally executed by the user. |
769 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DangerousSubresources) { | 779 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DangerousSubresources) { |
770 GURL url = | 780 GURL url = |
771 URLRequestMockHTTPJob::GetMockUrl("/save_page/dubious-subresources.html"); | 781 URLRequestMockHTTPJob::GetMockUrl("/save_page/dubious-subresources.html"); |
772 | 782 |
773 ui_test_utils::NavigateToURL(browser(), url); | 783 ui_test_utils::NavigateToURL(browser(), url); |
774 base::FilePath full_file_name, dir; | 784 base::FilePath full_file_name, dir; |
775 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 785 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
776 "dubious-subresources", 2, &dir, &full_file_name); | 786 "dubious-subresources", 2, &dir, &full_file_name); |
777 ASSERT_FALSE(HasFailure()); | 787 ASSERT_FALSE(HasFailure()); |
778 | 788 |
| 789 base::ThreadRestrictions::ScopedAllowIO allow_io; |
779 EXPECT_TRUE(base::PathExists(full_file_name)); | 790 EXPECT_TRUE(base::PathExists(full_file_name)); |
780 EXPECT_TRUE(base::PathExists(dir.AppendASCII("not-a-crx.crx.download"))); | 791 EXPECT_TRUE(base::PathExists(dir.AppendASCII("not-a-crx.crx.download"))); |
781 } | 792 } |
782 | 793 |
783 // Test that we don't crash when the page contains an iframe that | 794 // Test that we don't crash when the page contains an iframe that |
784 // was handled as a download (http://crbug.com/42212). | 795 // was handled as a download (http://crbug.com/42212). |
785 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveDownloadableIFrame) { | 796 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveDownloadableIFrame) { |
786 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 797 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
787 "downloads/iframe-src-is-a-download.htm"); | 798 "downloads/iframe-src-is-a-download.htm"); |
788 | 799 |
(...skipping 14 matching lines...) Expand all Loading... |
803 GetDownloadManager()->GetAllDownloads(&downloads); | 814 GetDownloadManager()->GetAllDownloads(&downloads); |
804 for (auto* download : downloads) | 815 for (auto* download : downloads) |
805 download->Remove(); | 816 download->Remove(); |
806 } | 817 } |
807 | 818 |
808 base::FilePath full_file_name, dir; | 819 base::FilePath full_file_name, dir; |
809 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 820 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
810 "iframe-src-is-a-download", 3, &dir, &full_file_name); | 821 "iframe-src-is-a-download", 3, &dir, &full_file_name); |
811 ASSERT_FALSE(HasFailure()); | 822 ASSERT_FALSE(HasFailure()); |
812 | 823 |
| 824 base::ThreadRestrictions::ScopedAllowIO allow_io; |
813 EXPECT_TRUE(base::PathExists(full_file_name)); | 825 EXPECT_TRUE(base::PathExists(full_file_name)); |
814 EXPECT_TRUE(base::PathExists(dir.AppendASCII("thisdayinhistory.html"))); | 826 EXPECT_TRUE(base::PathExists(dir.AppendASCII("thisdayinhistory.html"))); |
815 EXPECT_TRUE(base::PathExists(dir.AppendASCII("no-such-file.html"))); | 827 EXPECT_TRUE(base::PathExists(dir.AppendASCII("no-such-file.html"))); |
816 } | 828 } |
817 | 829 |
818 // Test that file: URI won't be saved when referred to from an HTTP page. | 830 // Test that file: URI won't be saved when referred to from an HTTP page. |
819 // See also https://crbug.com/616429. | 831 // See also https://crbug.com/616429. |
820 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveUnauthorizedResource) { | 832 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveUnauthorizedResource) { |
821 GURL url = NavigateToMockURL("unauthorized-access"); | 833 GURL url = NavigateToMockURL("unauthorized-access"); |
822 | 834 |
823 // Create a test file (that the web page should not have access to). | 835 // Create a test file (that the web page should not have access to). |
| 836 base::ThreadRestrictions::ScopedAllowIO allow_io; |
824 base::ScopedTempDir temp_dir2; | 837 base::ScopedTempDir temp_dir2; |
825 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 838 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
826 base::FilePath file_path = | 839 base::FilePath file_path = |
827 temp_dir2.GetPath().Append(FILE_PATH_LITERAL("should-not-save.jpg")); | 840 temp_dir2.GetPath().Append(FILE_PATH_LITERAL("should-not-save.jpg")); |
828 std::string file_content("fake-jpg"); | 841 std::string file_content("fake-jpg"); |
829 ASSERT_LT( | 842 ASSERT_LT( |
830 0, base::WriteFile(file_path, file_content.data(), file_content.size())); | 843 0, base::WriteFile(file_path, file_content.data(), file_content.size())); |
831 | 844 |
832 // Refer to the test file from the test page. | 845 // Refer to the test file from the test page. |
833 GURL file_url = net::FilePathToFileURL(file_path); | 846 GURL file_url = net::FilePathToFileURL(file_path); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 IN_PROC_BROWSER_TEST_F(SavePageSitePerProcessBrowserTest, SaveAsCompleteHtml) { | 894 IN_PROC_BROWSER_TEST_F(SavePageSitePerProcessBrowserTest, SaveAsCompleteHtml) { |
882 GURL url( | 895 GURL url( |
883 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); | 896 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); |
884 ui_test_utils::NavigateToURL(browser(), url); | 897 ui_test_utils::NavigateToURL(browser(), url); |
885 | 898 |
886 base::FilePath full_file_name, dir; | 899 base::FilePath full_file_name, dir; |
887 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 900 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
888 "frames-xsite-complete-html", 5, &dir, &full_file_name); | 901 "frames-xsite-complete-html", 5, &dir, &full_file_name); |
889 ASSERT_FALSE(HasFailure()); | 902 ASSERT_FALSE(HasFailure()); |
890 | 903 |
| 904 base::ThreadRestrictions::ScopedAllowIO allow_io; |
891 EXPECT_TRUE(base::DirectoryExists(dir)); | 905 EXPECT_TRUE(base::DirectoryExists(dir)); |
892 base::FilePath expected_files[] = { | 906 base::FilePath expected_files[] = { |
893 full_file_name, | 907 full_file_name, |
894 dir.AppendASCII("a.html"), // From iframes.htm | 908 dir.AppendASCII("a.html"), // From iframes.htm |
895 dir.AppendASCII("b.html"), // From iframes.htm | 909 dir.AppendASCII("b.html"), // From iframes.htm |
896 dir.AppendASCII("1.css"), // From b.htm | 910 dir.AppendASCII("1.css"), // From b.htm |
897 dir.AppendASCII("1.png"), // Deduplicated from iframes.htm and b.htm. | 911 dir.AppendASCII("1.png"), // Deduplicated from iframes.htm and b.htm. |
898 }; | 912 }; |
899 for (auto file_path : expected_files) { | 913 for (auto file_path : expected_files) { |
900 EXPECT_TRUE(base::PathExists(file_path)) << "Does " << file_path.value() | 914 EXPECT_TRUE(base::PathExists(file_path)) << "Does " << file_path.value() |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 GURL url( | 955 GURL url( |
942 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); | 956 embedded_test_server()->GetURL("a.com", "/save_page/frames-xsite.htm")); |
943 ui_test_utils::NavigateToURL(browser(), url); | 957 ui_test_utils::NavigateToURL(browser(), url); |
944 | 958 |
945 base::FilePath full_file_name, dir; | 959 base::FilePath full_file_name, dir; |
946 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_MHTML, "frames-xsite-mhtml", | 960 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_MHTML, "frames-xsite-mhtml", |
947 -1, &dir, &full_file_name); | 961 -1, &dir, &full_file_name); |
948 ASSERT_FALSE(HasFailure()); | 962 ASSERT_FALSE(HasFailure()); |
949 | 963 |
950 std::string mhtml; | 964 std::string mhtml; |
951 ASSERT_TRUE(base::ReadFileToString(full_file_name, &mhtml)); | 965 { |
| 966 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 967 ASSERT_TRUE(base::ReadFileToString(full_file_name, &mhtml)); |
| 968 } |
952 | 969 |
953 // Verify content of main frame, subframes and some savable resources. | 970 // Verify content of main frame, subframes and some savable resources. |
954 EXPECT_THAT( | 971 EXPECT_THAT( |
955 mhtml, | 972 mhtml, |
956 HasSubstr("frames-xsite.htm: 896fd88d-a77a-4f46-afd8-24db7d5af9c2")); | 973 HasSubstr("frames-xsite.htm: 896fd88d-a77a-4f46-afd8-24db7d5af9c2")); |
957 EXPECT_THAT(mhtml, HasSubstr("a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2")); | 974 EXPECT_THAT(mhtml, HasSubstr("a.htm: 1b8aae2b-e164-462f-bd5b-98aa366205f2")); |
958 EXPECT_THAT(mhtml, HasSubstr("b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa")); | 975 EXPECT_THAT(mhtml, HasSubstr("b.htm: 3a35f7fa-96a9-4487-9f18-4470263907fa")); |
959 EXPECT_THAT(mhtml, HasSubstr("font-size: 20px;")) | 976 EXPECT_THAT(mhtml, HasSubstr("font-size: 20px;")) |
960 << "Verifying if content from 1.css is present"; | 977 << "Verifying if content from 1.css is present"; |
961 | 978 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 break; | 1024 break; |
1008 } | 1025 } |
1009 } | 1026 } |
1010 EXPECT_TRUE(did_kill_a_process); | 1027 EXPECT_TRUE(did_kill_a_process); |
1011 | 1028 |
1012 // Main verification is that we don't hang and time out when saving. | 1029 // Main verification is that we don't hang and time out when saving. |
1013 base::FilePath full_file_name, dir; | 1030 base::FilePath full_file_name, dir; |
1014 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 1031 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
1015 "frames-xsite-complete-html", 5, &dir, &full_file_name); | 1032 "frames-xsite-complete-html", 5, &dir, &full_file_name); |
1016 ASSERT_FALSE(HasFailure()); | 1033 ASSERT_FALSE(HasFailure()); |
| 1034 base::ThreadRestrictions::ScopedAllowIO allow_io; |
1017 EXPECT_TRUE(base::DirectoryExists(dir)); | 1035 EXPECT_TRUE(base::DirectoryExists(dir)); |
1018 EXPECT_TRUE(base::PathExists(full_file_name)); | 1036 EXPECT_TRUE(base::PathExists(full_file_name)); |
1019 } | 1037 } |
1020 | 1038 |
1021 // Test suite that verifies that the frame tree "looks" the same before | 1039 // Test suite that verifies that the frame tree "looks" the same before |
1022 // and after a save-page-as. | 1040 // and after a save-page-as. |
1023 class SavePageOriginalVsSavedComparisonTest | 1041 class SavePageOriginalVsSavedComparisonTest |
1024 : public SavePageSitePerProcessBrowserTest, | 1042 : public SavePageSitePerProcessBrowserTest, |
1025 public ::testing::WithParamInterface<content::SavePageType> { | 1043 public ::testing::WithParamInterface<content::SavePageType> { |
1026 protected: | 1044 protected: |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 TestOriginalVsSavedPage(save_page_type, url, 1, 1, expected_substrings); | 1348 TestOriginalVsSavedPage(save_page_type, url, 1, 1, expected_substrings); |
1331 } | 1349 } |
1332 | 1350 |
1333 INSTANTIATE_TEST_CASE_P( | 1351 INSTANTIATE_TEST_CASE_P( |
1334 SaveType, | 1352 SaveType, |
1335 SavePageOriginalVsSavedComparisonTest, | 1353 SavePageOriginalVsSavedComparisonTest, |
1336 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 1354 ::testing::Values(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
1337 content::SAVE_PAGE_TYPE_AS_MHTML)); | 1355 content::SAVE_PAGE_TYPE_AS_MHTML)); |
1338 | 1356 |
1339 } // namespace | 1357 } // namespace |
OLD | NEW |