| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 content::BrowserContext::GetDownloadManager(browser()->profile()), | 396 content::BrowserContext::GetDownloadManager(browser()->profile()), |
| 397 loop_runner->QuitClosure()); | 397 loop_runner->QuitClosure()); |
| 398 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 398 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 399 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 399 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 400 loop_runner->Run(); | 400 loop_runner->Run(); |
| 401 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); | 401 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); |
| 402 persisted.WaitForPersisted(); | 402 persisted.WaitForPersisted(); |
| 403 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 403 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 404 EXPECT_TRUE(base::PathExists(full_file_name)); | 404 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 405 EXPECT_FALSE(base::PathExists(dir)); | 405 EXPECT_FALSE(base::PathExists(dir)); |
| 406 EXPECT_TRUE(file_util::ContentsEqual(test_dir_.Append(base::FilePath( | 406 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( |
| 407 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); | 407 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); |
| 408 } | 408 } |
| 409 | 409 |
| 410 // http://crbug.com/162323 | 410 // http://crbug.com/162323 |
| 411 // http://crbug.com/163931 | 411 // http://crbug.com/163931 |
| 412 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyCancel) { | 412 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyCancel) { |
| 413 GURL url = NavigateToMockURL("a"); | 413 GURL url = NavigateToMockURL("a"); |
| 414 DownloadManager* manager(GetDownloadManager()); | 414 DownloadManager* manager(GetDownloadManager()); |
| 415 std::vector<DownloadItem*> downloads; | 415 std::vector<DownloadItem*> downloads; |
| 416 manager->GetAllDownloads(&downloads); | 416 manager->GetAllDownloads(&downloads); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 520 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 521 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 521 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 522 loop_runner->Run(); | 522 loop_runner->Run(); |
| 523 ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url)); | 523 ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url)); |
| 524 persisted.WaitForPersisted(); | 524 persisted.WaitForPersisted(); |
| 525 | 525 |
| 526 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 526 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 527 | 527 |
| 528 EXPECT_TRUE(base::PathExists(full_file_name)); | 528 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 529 EXPECT_FALSE(base::PathExists(dir)); | 529 EXPECT_FALSE(base::PathExists(dir)); |
| 530 EXPECT_TRUE(file_util::ContentsEqual( | 530 EXPECT_TRUE(base::ContentsEqual( |
| 531 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name), | 531 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name), |
| 532 full_file_name)); | 532 full_file_name)); |
| 533 } | 533 } |
| 534 | 534 |
| 535 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 535 // Disabled on Windows due to flakiness. http://crbug.com/162323 |
| 536 // TODO(linux_aura) http://crbug.com/163931 | 536 // TODO(linux_aura) http://crbug.com/163931 |
| 537 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) | 537 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) |
| 538 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML | 538 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML |
| 539 #else | 539 #else |
| 540 #define MAYBE_SaveCompleteHTML SaveCompleteHTML | 540 #define MAYBE_SaveCompleteHTML SaveCompleteHTML |
| (...skipping 14 matching lines...) Expand all Loading... |
| 555 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( | 555 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( |
| 556 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 556 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 557 loop_runner->Run(); | 557 loop_runner->Run(); |
| 558 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); | 558 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); |
| 559 persisted.WaitForPersisted(); | 559 persisted.WaitForPersisted(); |
| 560 | 560 |
| 561 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 561 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 562 | 562 |
| 563 EXPECT_TRUE(base::PathExists(full_file_name)); | 563 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 564 EXPECT_TRUE(base::PathExists(dir)); | 564 EXPECT_TRUE(base::PathExists(dir)); |
| 565 EXPECT_TRUE(file_util::TextContentsEqual( | 565 EXPECT_TRUE(base::TextContentsEqual( |
| 566 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 566 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 567 full_file_name)); | 567 full_file_name)); |
| 568 EXPECT_TRUE(file_util::ContentsEqual( | 568 EXPECT_TRUE(base::ContentsEqual( |
| 569 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), | 569 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), |
| 570 dir.AppendASCII("1.png"))); | 570 dir.AppendASCII("1.png"))); |
| 571 EXPECT_TRUE(file_util::ContentsEqual( | 571 EXPECT_TRUE(base::ContentsEqual( |
| 572 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), | 572 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), |
| 573 dir.AppendASCII("1.css"))); | 573 dir.AppendASCII("1.css"))); |
| 574 } | 574 } |
| 575 | 575 |
| 576 // Invoke a save page during the initial navigation. | 576 // Invoke a save page during the initial navigation. |
| 577 // (Regression test for http://crbug.com/156538). | 577 // (Regression test for http://crbug.com/156538). |
| 578 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 578 // Disabled on Windows due to flakiness. http://crbug.com/162323 |
| 579 // TODO(linux_aura) http://crbug.com/163931 | 579 // TODO(linux_aura) http://crbug.com/163931 |
| 580 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) | 580 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) |
| 581 #define MAYBE_SaveDuringInitialNavigationIncognito DISABLED_SaveDuringInitialNav
igationIncognito | 581 #define MAYBE_SaveDuringInitialNavigationIncognito DISABLED_SaveDuringInitialNav
igationIncognito |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 653 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 654 | 654 |
| 655 loop_runner->Run(); | 655 loop_runner->Run(); |
| 656 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); | 656 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); |
| 657 persisted.WaitForPersisted(); | 657 persisted.WaitForPersisted(); |
| 658 | 658 |
| 659 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 659 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 660 | 660 |
| 661 EXPECT_TRUE(base::PathExists(full_file_name)); | 661 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 662 EXPECT_TRUE(base::PathExists(dir)); | 662 EXPECT_TRUE(base::PathExists(dir)); |
| 663 EXPECT_TRUE(file_util::TextContentsEqual( | 663 EXPECT_TRUE(base::TextContentsEqual( |
| 664 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 664 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
| 665 full_file_name)); | 665 full_file_name)); |
| 666 EXPECT_TRUE(file_util::ContentsEqual( | 666 EXPECT_TRUE(base::ContentsEqual( |
| 667 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), | 667 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), |
| 668 dir.AppendASCII("1.png"))); | 668 dir.AppendASCII("1.png"))); |
| 669 EXPECT_TRUE(file_util::ContentsEqual( | 669 EXPECT_TRUE(base::ContentsEqual( |
| 670 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), | 670 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), |
| 671 dir.AppendASCII("1.css"))); | 671 dir.AppendASCII("1.css"))); |
| 672 } | 672 } |
| 673 | 673 |
| 674 // Disabled on Windows due to flakiness. http://crbug.com/162323 | 674 // Disabled on Windows due to flakiness. http://crbug.com/162323 |
| 675 // TODO(linux_aura) http://crbug.com/163931 | 675 // TODO(linux_aura) http://crbug.com/163931 |
| 676 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) | 676 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) |
| 677 #define MAYBE_RemoveFromList DISABLED_RemoveFromList | 677 #define MAYBE_RemoveFromList DISABLED_RemoveFromList |
| 678 #else | 678 #else |
| 679 #define MAYBE_RemoveFromList RemoveFromList | 679 #define MAYBE_RemoveFromList RemoveFromList |
| (...skipping 25 matching lines...) Expand all Loading... |
| 705 manager->GetAllDownloads(&downloads); | 705 manager->GetAllDownloads(&downloads); |
| 706 ASSERT_EQ(1UL, downloads.size()); | 706 ASSERT_EQ(1UL, downloads.size()); |
| 707 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId()); | 707 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId()); |
| 708 | 708 |
| 709 EXPECT_EQ(manager->RemoveAllDownloads(), 1); | 709 EXPECT_EQ(manager->RemoveAllDownloads(), 1); |
| 710 | 710 |
| 711 removed.WaitForRemoved(); | 711 removed.WaitForRemoved(); |
| 712 | 712 |
| 713 EXPECT_TRUE(base::PathExists(full_file_name)); | 713 EXPECT_TRUE(base::PathExists(full_file_name)); |
| 714 EXPECT_FALSE(base::PathExists(dir)); | 714 EXPECT_FALSE(base::PathExists(dir)); |
| 715 EXPECT_TRUE(file_util::ContentsEqual(test_dir_.Append(base::FilePath( | 715 EXPECT_TRUE(base::ContentsEqual(test_dir_.Append(base::FilePath( |
| 716 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); | 716 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); |
| 717 } | 717 } |
| 718 | 718 |
| 719 // This tests that a webpage with the title "test.exe" is saved as | 719 // This tests that a webpage with the title "test.exe" is saved as |
| 720 // "test.exe.htm". | 720 // "test.exe.htm". |
| 721 // We probably don't care to handle this on Linux or Mac. | 721 // We probably don't care to handle this on Linux or Mac. |
| 722 #if defined(OS_WIN) | 722 #if defined(OS_WIN) |
| 723 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { | 723 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { |
| 724 const base::FilePath file_name(FILE_PATH_LITERAL("c.htm")); | 724 const base::FilePath file_name(FILE_PATH_LITERAL("c.htm")); |
| 725 base::FilePath download_dir = | 725 base::FilePath download_dir = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 GetDownloadManager())->DownloadPath(); | 807 GetDownloadManager())->DownloadPath(); |
| 808 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); | 808 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); |
| 809 ASSERT_TRUE(base::PathExists(filename)); | 809 ASSERT_TRUE(base::PathExists(filename)); |
| 810 std::string contents; | 810 std::string contents; |
| 811 EXPECT_TRUE(file_util::ReadFileToString(filename, &contents)); | 811 EXPECT_TRUE(file_util::ReadFileToString(filename, &contents)); |
| 812 EXPECT_EQ("foo", contents); | 812 EXPECT_EQ("foo", contents); |
| 813 } | 813 } |
| 814 | 814 |
| 815 } // namespace | 815 } // namespace |
| 816 | 816 |
| OLD | NEW |