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

Side by Side Diff: chrome/browser/download/save_page_browsertest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 new content::MessageLoopRunner); 394 new content::MessageLoopRunner);
395 SavePackageFinishedObserver observer( 395 SavePackageFinishedObserver observer(
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(file_util::PathExists(full_file_name)); 404 EXPECT_TRUE(base::PathExists(full_file_name));
405 EXPECT_FALSE(file_util::PathExists(dir)); 405 EXPECT_FALSE(base::PathExists(dir));
406 EXPECT_TRUE(file_util::ContentsEqual(test_dir_.Append(base::FilePath( 406 EXPECT_TRUE(file_util::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 // Disabled on Windows due to flakiness. http://crbug.com/162323 410 // Disabled on Windows due to flakiness. http://crbug.com/162323
411 // TODO(linux_aura) http://crbug.com/163931 411 // TODO(linux_aura) http://crbug.com/163931
412 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA)) 412 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA))
413 #define MAYBE_SaveHTMLOnlyCancel DISABLED_SaveHTMLOnlyCancel 413 #define MAYBE_SaveHTMLOnlyCancel DISABLED_SaveHTMLOnlyCancel
414 #else 414 #else
415 #define MAYBE_SaveHTMLOnlyCancel SaveHTMLOnlyCancel 415 #define MAYBE_SaveHTMLOnlyCancel SaveHTMLOnlyCancel
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, 462 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir,
463 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 463 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
464 std::vector<DownloadItem*> items; 464 std::vector<DownloadItem*> items;
465 creation_observer.WaitForDownloadItem(&items); 465 creation_observer.WaitForDownloadItem(&items);
466 ASSERT_TRUE(items.size() == 1); 466 ASSERT_TRUE(items.size() == 1);
467 467
468 // Close the tab; does this cancel the download? 468 // Close the tab; does this cancel the download?
469 GetCurrentTab(browser())->Close(); 469 GetCurrentTab(browser())->Close();
470 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState()); 470 EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState());
471 471
472 EXPECT_FALSE(file_util::PathExists(full_file_name)); 472 EXPECT_FALSE(base::PathExists(full_file_name));
473 EXPECT_FALSE(file_util::PathExists(dir)); 473 EXPECT_FALSE(base::PathExists(dir));
474 } 474 }
475 475
476 // Disabled on Windows due to flakiness. http://crbug.com/162323 476 // Disabled on Windows due to flakiness. http://crbug.com/162323
477 // TODO(linux_aura) http://crbug.com/163931 477 // TODO(linux_aura) http://crbug.com/163931
478 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA)) 478 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA))
479 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly 479 #define MAYBE_SaveViewSourceHTMLOnly DISABLED_SaveViewSourceHTMLOnly
480 #else 480 #else
481 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly 481 #define MAYBE_SaveViewSourceHTMLOnly SaveViewSourceHTMLOnly
482 #endif 482 #endif
483 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) { 483 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, MAYBE_SaveViewSourceHTMLOnly) {
(...skipping 15 matching lines...) Expand all
499 content::BrowserContext::GetDownloadManager(browser()->profile()), 499 content::BrowserContext::GetDownloadManager(browser()->profile()),
500 loop_runner->QuitClosure()); 500 loop_runner->QuitClosure());
501 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, 501 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir,
502 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 502 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
503 loop_runner->Run(); 503 loop_runner->Run();
504 ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url)); 504 ASSERT_TRUE(VerifySavePackageExpectations(browser(), actual_page_url));
505 persisted.WaitForPersisted(); 505 persisted.WaitForPersisted();
506 506
507 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 507 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
508 508
509 EXPECT_TRUE(file_util::PathExists(full_file_name)); 509 EXPECT_TRUE(base::PathExists(full_file_name));
510 EXPECT_FALSE(file_util::PathExists(dir)); 510 EXPECT_FALSE(base::PathExists(dir));
511 EXPECT_TRUE(file_util::ContentsEqual( 511 EXPECT_TRUE(file_util::ContentsEqual(
512 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name), 512 test_dir_.Append(base::FilePath(kTestDir)).Append(file_name),
513 full_file_name)); 513 full_file_name));
514 } 514 }
515 515
516 // Disabled on Windows due to flakiness. http://crbug.com/162323 516 // Disabled on Windows due to flakiness. http://crbug.com/162323
517 // TODO(linux_aura) http://crbug.com/163931 517 // TODO(linux_aura) http://crbug.com/163931
518 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA)) 518 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA))
519 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML 519 #define MAYBE_SaveCompleteHTML DISABLED_SaveCompleteHTML
520 #else 520 #else
(...skipping 13 matching lines...) Expand all
534 content::BrowserContext::GetDownloadManager(browser()->profile()), 534 content::BrowserContext::GetDownloadManager(browser()->profile()),
535 loop_runner->QuitClosure()); 535 loop_runner->QuitClosure());
536 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( 536 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(
537 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 537 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
538 loop_runner->Run(); 538 loop_runner->Run();
539 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 539 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
540 persisted.WaitForPersisted(); 540 persisted.WaitForPersisted();
541 541
542 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 542 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
543 543
544 EXPECT_TRUE(file_util::PathExists(full_file_name)); 544 EXPECT_TRUE(base::PathExists(full_file_name));
545 EXPECT_TRUE(file_util::PathExists(dir)); 545 EXPECT_TRUE(base::PathExists(dir));
546 EXPECT_TRUE(file_util::TextContentsEqual( 546 EXPECT_TRUE(file_util::TextContentsEqual(
547 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 547 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
548 full_file_name)); 548 full_file_name));
549 EXPECT_TRUE(file_util::ContentsEqual( 549 EXPECT_TRUE(file_util::ContentsEqual(
550 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), 550 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"),
551 dir.AppendASCII("1.png"))); 551 dir.AppendASCII("1.png")));
552 EXPECT_TRUE(file_util::ContentsEqual( 552 EXPECT_TRUE(file_util::ContentsEqual(
553 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), 553 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"),
554 dir.AppendASCII("1.css"))); 554 dir.AppendASCII("1.css")));
555 } 555 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 loop_runner->QuitClosure()); 632 loop_runner->QuitClosure());
633 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( 633 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(
634 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 634 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
635 635
636 loop_runner->Run(); 636 loop_runner->Run();
637 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 637 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
638 persisted.WaitForPersisted(); 638 persisted.WaitForPersisted();
639 639
640 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 640 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
641 641
642 EXPECT_TRUE(file_util::PathExists(full_file_name)); 642 EXPECT_TRUE(base::PathExists(full_file_name));
643 EXPECT_TRUE(file_util::PathExists(dir)); 643 EXPECT_TRUE(base::PathExists(dir));
644 EXPECT_TRUE(file_util::TextContentsEqual( 644 EXPECT_TRUE(file_util::TextContentsEqual(
645 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 645 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
646 full_file_name)); 646 full_file_name));
647 EXPECT_TRUE(file_util::ContentsEqual( 647 EXPECT_TRUE(file_util::ContentsEqual(
648 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"), 648 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.png"),
649 dir.AppendASCII("1.png"))); 649 dir.AppendASCII("1.png")));
650 EXPECT_TRUE(file_util::ContentsEqual( 650 EXPECT_TRUE(file_util::ContentsEqual(
651 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"), 651 test_dir_.Append(base::FilePath(kTestDir)).AppendASCII("1.css"),
652 dir.AppendASCII("1.css"))); 652 dir.AppendASCII("1.css")));
653 } 653 }
(...skipping 30 matching lines...) Expand all
684 DownloadManager* manager(GetDownloadManager()); 684 DownloadManager* manager(GetDownloadManager());
685 std::vector<DownloadItem*> downloads; 685 std::vector<DownloadItem*> downloads;
686 manager->GetAllDownloads(&downloads); 686 manager->GetAllDownloads(&downloads);
687 ASSERT_EQ(1UL, downloads.size()); 687 ASSERT_EQ(1UL, downloads.size());
688 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId()); 688 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId());
689 689
690 EXPECT_EQ(manager->RemoveAllDownloads(), 1); 690 EXPECT_EQ(manager->RemoveAllDownloads(), 1);
691 691
692 removed.WaitForRemoved(); 692 removed.WaitForRemoved();
693 693
694 EXPECT_TRUE(file_util::PathExists(full_file_name)); 694 EXPECT_TRUE(base::PathExists(full_file_name));
695 EXPECT_FALSE(file_util::PathExists(dir)); 695 EXPECT_FALSE(base::PathExists(dir));
696 EXPECT_TRUE(file_util::ContentsEqual(test_dir_.Append(base::FilePath( 696 EXPECT_TRUE(file_util::ContentsEqual(test_dir_.Append(base::FilePath(
697 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name)); 697 kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), full_file_name));
698 } 698 }
699 699
700 // This tests that a webpage with the title "test.exe" is saved as 700 // This tests that a webpage with the title "test.exe" is saved as
701 // "test.exe.htm". 701 // "test.exe.htm".
702 // We probably don't care to handle this on Linux or Mac. 702 // We probably don't care to handle this on Linux or Mac.
703 #if defined(OS_WIN) 703 #if defined(OS_WIN)
704 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) { 704 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, CleanFilenameFromPageTitle) {
705 const base::FilePath file_name(FILE_PATH_LITERAL("c.htm")); 705 const base::FilePath file_name(FILE_PATH_LITERAL("c.htm"));
706 base::FilePath download_dir = 706 base::FilePath download_dir =
707 DownloadPrefs::FromDownloadManager(GetDownloadManager())-> 707 DownloadPrefs::FromDownloadManager(GetDownloadManager())->
708 DownloadPath(); 708 DownloadPath();
709 base::FilePath full_file_name = 709 base::FilePath full_file_name =
710 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension); 710 download_dir.AppendASCII(std::string("test.exe") + kAppendedExtension);
711 base::FilePath dir = download_dir.AppendASCII("test.exe_files"); 711 base::FilePath dir = download_dir.AppendASCII("test.exe_files");
712 712
713 EXPECT_FALSE(file_util::PathExists(full_file_name)); 713 EXPECT_FALSE(base::PathExists(full_file_name));
714 GURL url = URLRequestMockHTTPJob::GetMockUrl( 714 GURL url = URLRequestMockHTTPJob::GetMockUrl(
715 base::FilePath(kTestDir).Append(file_name)); 715 base::FilePath(kTestDir).Append(file_name));
716 ui_test_utils::NavigateToURL(browser(), url); 716 ui_test_utils::NavigateToURL(browser(), url);
717 717
718 SavePackageFilePicker::SetShouldPromptUser(false); 718 SavePackageFilePicker::SetShouldPromptUser(false);
719 scoped_refptr<content::MessageLoopRunner> loop_runner( 719 scoped_refptr<content::MessageLoopRunner> loop_runner(
720 new content::MessageLoopRunner); 720 new content::MessageLoopRunner);
721 SavePackageFinishedObserver observer( 721 SavePackageFinishedObserver observer(
722 content::BrowserContext::GetDownloadManager(browser()->profile()), 722 content::BrowserContext::GetDownloadManager(browser()->profile()),
723 loop_runner->QuitClosure()); 723 loop_runner->QuitClosure());
724 chrome::SavePage(browser()); 724 chrome::SavePage(browser());
725 loop_runner->Run(); 725 loop_runner->Run();
726 726
727 EXPECT_TRUE(file_util::PathExists(full_file_name)); 727 EXPECT_TRUE(base::PathExists(full_file_name));
728 728
729 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); 729 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false));
730 EXPECT_TRUE(file_util::DieFileDie(dir, true)); 730 EXPECT_TRUE(file_util::DieFileDie(dir, true));
731 } 731 }
732 #endif 732 #endif
733 733
734 class SavePageAsMHTMLBrowserTest : public SavePageBrowserTest { 734 class SavePageAsMHTMLBrowserTest : public SavePageBrowserTest {
735 public: 735 public:
736 SavePageAsMHTMLBrowserTest() {} 736 SavePageAsMHTMLBrowserTest() {}
737 virtual ~SavePageAsMHTMLBrowserTest(); 737 virtual ~SavePageAsMHTMLBrowserTest();
(...skipping 22 matching lines...) Expand all
760 scoped_refptr<content::MessageLoopRunner> loop_runner( 760 scoped_refptr<content::MessageLoopRunner> loop_runner(
761 new content::MessageLoopRunner); 761 new content::MessageLoopRunner);
762 SavePackageFinishedObserver observer( 762 SavePackageFinishedObserver observer(
763 content::BrowserContext::GetDownloadManager(browser()->profile()), 763 content::BrowserContext::GetDownloadManager(browser()->profile()),
764 loop_runner->QuitClosure()); 764 loop_runner->QuitClosure());
765 chrome::SavePage(browser()); 765 chrome::SavePage(browser());
766 loop_runner->Run(); 766 loop_runner->Run();
767 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url)); 767 ASSERT_TRUE(VerifySavePackageExpectations(browser(), url));
768 persisted.WaitForPersisted(); 768 persisted.WaitForPersisted();
769 769
770 ASSERT_TRUE(file_util::PathExists(full_file_name)); 770 ASSERT_TRUE(base::PathExists(full_file_name));
771 int64 actual_file_size = -1; 771 int64 actual_file_size = -1;
772 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); 772 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size));
773 EXPECT_LE(kFileSizeMin, actual_file_size); 773 EXPECT_LE(kFileSizeMin, actual_file_size);
774 } 774 }
775 775
776 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) { 776 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageBrowserTest_NonMHTML) {
777 SavePackageFilePicker::SetShouldPromptUser(false); 777 SavePackageFilePicker::SetShouldPromptUser(false);
778 GURL url("data:text/plain,foo"); 778 GURL url("data:text/plain,foo");
779 ui_test_utils::NavigateToURL(browser(), url); 779 ui_test_utils::NavigateToURL(browser(), url);
780 scoped_refptr<content::MessageLoopRunner> loop_runner( 780 scoped_refptr<content::MessageLoopRunner> loop_runner(
781 new content::MessageLoopRunner); 781 new content::MessageLoopRunner);
782 SavePackageFinishedObserver observer( 782 SavePackageFinishedObserver observer(
783 content::BrowserContext::GetDownloadManager(browser()->profile()), 783 content::BrowserContext::GetDownloadManager(browser()->profile()),
784 loop_runner->QuitClosure()); 784 loop_runner->QuitClosure());
785 chrome::SavePage(browser()); 785 chrome::SavePage(browser());
786 loop_runner->Run(); 786 loop_runner->Run();
787 base::FilePath download_dir = DownloadPrefs::FromDownloadManager( 787 base::FilePath download_dir = DownloadPrefs::FromDownloadManager(
788 GetDownloadManager())->DownloadPath(); 788 GetDownloadManager())->DownloadPath();
789 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); 789 base::FilePath filename = download_dir.AppendASCII("dataurl.txt");
790 ASSERT_TRUE(file_util::PathExists(filename)); 790 ASSERT_TRUE(base::PathExists(filename));
791 std::string contents; 791 std::string contents;
792 EXPECT_TRUE(file_util::ReadFileToString(filename, &contents)); 792 EXPECT_TRUE(file_util::ReadFileToString(filename, &contents));
793 EXPECT_EQ("foo", contents); 793 EXPECT_EQ("foo", contents);
794 } 794 }
795 795
796 } // namespace 796 } // namespace
797 797
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698