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

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

Issue 9355050: Added read-only file error test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed some issues & consolidated code Created 8 years, 10 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
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 ASSERT_TRUE(test_server()->Start()); 683 ASSERT_TRUE(test_server()->Start());
684 std::vector<DownloadItem*> download_items; 684 std::vector<DownloadItem*> download_items;
685 GetDownloads(browser(), &download_items); 685 GetDownloads(browser(), &download_items);
686 ASSERT_TRUE(download_items.empty()); 686 ASSERT_TRUE(download_items.empty());
687 687
688 std::string server_path = "files/downloads/"; 688 std::string server_path = "files/downloads/";
689 server_path += download_info.url_name; 689 server_path += download_info.url_name;
690 GURL url = test_server()->GetURL(server_path); 690 GURL url = test_server()->GetURL(server_path);
691 ASSERT_TRUE(url.is_valid()); 691 ASSERT_TRUE(url.is_valid());
692 692
693 NullSelectFile(browser()); // Needed for read-only tests.
Randy Smith (Not in Mondays) 2012/02/24 19:16:15 This makes me uncomfortable, as it changes the beh
ahendrickson 2012/02/25 01:05:17 This makes the behavior what I wanted it to be in
Randy Smith (Not in Mondays) 2012/02/27 21:06:03 I don't see the comment; did you mean you'd add it
ahendrickson 2012/02/28 03:59:25 Yes, it got added after a merge with the parent. I
Randy Smith (Not in Mondays) 2012/03/01 20:37:14 Got it--thanks.
694
693 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 695 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
694 scoped_ptr<DownloadTestObserver> observer( 696 scoped_ptr<DownloadTestObserver> observer(
695 new DownloadTestObserver( 697 new DownloadTestObserver(
696 download_manager, 698 download_manager,
697 1, 699 1,
698 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ? 700 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ?
699 DownloadItem::COMPLETE : // Really done 701 DownloadItem::COMPLETE : // Really done
700 DownloadItem::INTERRUPTED, 702 DownloadItem::INTERRUPTED,
701 true, // Bail on select file 703 false, // Don't finish on select file
702 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 704 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
703 705
704 if (download_info.download_method == DOWNLOAD_DIRECT) { 706 if (download_info.download_method == DOWNLOAD_DIRECT) {
705 // Go directly to download. 707 // Go directly to download.
706 WebContents* web_contents = browser()->GetSelectedWebContents(); 708 WebContents* web_contents = browser()->GetSelectedWebContents();
707 ASSERT_TRUE(web_contents); 709 ASSERT_TRUE(web_contents);
708 DownloadSaveInfo save_info; 710 DownloadSaveInfo save_info;
709 save_info.prompt_for_save_location = false; 711 save_info.prompt_for_save_location = false;
710 712
711 DownloadManagerForBrowser(browser())->DownloadUrl( 713 DownloadManagerForBrowser(browser())->DownloadUrl(
712 url, GURL(""), "", false, -1, save_info, web_contents); 714 url, GURL(""), "", false, -1, save_info, web_contents);
713 } else { 715 } else {
714 // Navigate to URL normally, wait until done. 716 // Navigate to URL normally, wait until done.
715 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 717 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
716 url, 718 url,
717 1); 719 1);
718 } 720 }
719 721
720 if (download_info.show_download_item) 722 if (download_info.show_download_item)
721 observer->WaitForFinished(); 723 observer->WaitForFinished();
Randy Smith (Not in Mondays) 2012/02/27 21:06:03 If show_download_item isn't set, doesn't this mean
ahendrickson 2012/02/28 03:59:25 Any suggestions on what to wait for in this case?
ahendrickson 2012/03/01 15:18:18 I've addressed this in CL 9426029.
Randy Smith (Not in Mondays) 2012/03/01 20:37:14 And just confirming: That CL is going in first? I
ahendrickson 2012/03/02 17:51:57 You are correct. That CL has changed to 9570005 h
722 724
723 // Validate that the correct file was downloaded. 725 // Validate that the correct file was downloaded.
724 download_items.clear(); 726 download_items.clear();
725 GetDownloads(browser(), &download_items); 727 GetDownloads(browser(), &download_items);
Randy Smith (Not in Mondays) 2012/02/27 21:06:03 This won't see downloads before they're put into t
ahendrickson 2012/02/28 03:59:25 The !show_download_item won't have anything insert
726 size_t item_count = download_info.show_download_item ? 1 : 0; 728 size_t item_count = download_info.show_download_item ? 1 : 0;
727 ASSERT_EQ(item_count, download_items.size()); 729 ASSERT_EQ(item_count, download_items.size());
728 730
729 if (download_info.show_download_item) { 731 if (download_info.show_download_item) {
730 DownloadItem* item = download_items[0]; 732 DownloadItem* item = download_items[0];
731 ASSERT_EQ(url, item->GetOriginalUrl()); 733 ASSERT_EQ(url, item->GetOriginalUrl());
732 734
733 ASSERT_EQ(download_info.reason, item->GetLastReason()); 735 ASSERT_EQ(download_info.reason, item->GetLastReason());
736
737 if (item->GetLastReason() == DOWNLOAD_INTERRUPT_REASON_NONE) {
Randy Smith (Not in Mondays) 2012/02/27 21:06:03 What does this test mean? That we weren't interru
ahendrickson 2012/02/28 03:59:25 It means that the download succeeded in the end.
Randy Smith (Not in Mondays) 2012/03/01 20:37:14 Why not test against state COMPLETED? It seems cl
ahendrickson 2012/03/02 17:51:57 Done.
738 // Clean up the file, in case it ended up in the My Documents folder.
739 FilePath destination_folder = GetDownloadDirectory(browser());
740 FilePath my_downloaded_file = item->GetTargetFilePath();
741 EXPECT_TRUE(file_util::PathExists(my_downloaded_file));
742 EXPECT_TRUE(file_util::Delete(my_downloaded_file, false));
743
744 // If it's not where we asked it to be, it should be in the
745 // My Documents folder.
746 if (my_downloaded_file.value().find(destination_folder.value()) ==
747 std::string::npos) {
748 FilePath my_docs_folder;
749 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DOCUMENTS,
750 &my_docs_folder));
751 EXPECT_EQ(0u,
752 my_downloaded_file.value().find(my_docs_folder.value()));
753 }
754 }
734 } 755 }
735 } 756 }
736 757
758 // Attempts to download a file to a read-only folder, based on information
759 // in |download_info|.
760 void DownloadFileToReadonlyFolder(const DownloadInfo& download_info) {
761 ASSERT_TRUE(InitialSetup(false)); // Creates temporary download folder.
762
763 // Make the test folder unwritable.
764 FilePath destination_folder = GetDownloadDirectory(browser());
765 DVLOG(1) << " " << __FUNCTION__ << "()"
766 << " folder = '" << destination_folder.value() << "'";
767 size_t perm_length = 0;
768 void* original_permissions =
769 file_util::GetPermissionInfo(destination_folder, &perm_length);
770 EXPECT_TRUE(original_permissions != NULL);
771 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder));
772
773 DownloadFileCheckErrors(download_info);
774
775 EXPECT_TRUE(file_util::RestorePermissionInfo(destination_folder,
776 original_permissions,
777 perm_length));
778 }
737 private: 779 private:
738 // Location of the test data. 780 // Location of the test data.
739 FilePath test_dir_; 781 FilePath test_dir_;
740 782
741 // Location of the downloads directory for these tests 783 // Location of the downloads directory for these tests
742 ScopedTempDir downloads_directory_; 784 ScopedTempDir downloads_directory_;
743 }; 785 };
744 786
745 // NOTES: 787 // NOTES:
746 // 788 //
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 "zip_file_not_found.zip", 2053 "zip_file_not_found.zip",
2012 DOWNLOAD_NAVIGATE, 2054 DOWNLOAD_NAVIGATE,
2013 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2055 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2014 false 2056 false
2015 }; 2057 };
2016 2058
2017 // Do initial setup. 2059 // Do initial setup.
2018 ASSERT_TRUE(InitialSetup(false)); 2060 ASSERT_TRUE(InitialSetup(false));
2019 DownloadFileCheckErrors(download_info); 2061 DownloadFileCheckErrors(download_info);
2020 } 2062 }
2063
2064 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderDirect) {
Randy Smith (Not in Mondays) 2012/02/24 19:16:15 Shouldn't both of these tests actively confirm tha
ahendrickson 2012/02/25 01:05:17 They do, in line 751.
Randy Smith (Not in Mondays) 2012/02/27 21:06:03 That test (presuming I'm reading it correctly) is
ahendrickson 2012/02/28 03:59:25 Ah, I see. I don't have access to the information
2065 DownloadInfo download_info = {
2066 "a_zip_file.zip",
2067 DOWNLOAD_DIRECT,
2068 // This passes because we switch to the My Documents folder.
2069 DOWNLOAD_INTERRUPT_REASON_NONE,
2070 true
2071 };
2072
2073 DownloadFileToReadonlyFolder(download_info);
2074 }
2075
2076 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolderNavigate) {
2077 DownloadInfo download_info = {
2078 "a_zip_file.zip",
2079 DOWNLOAD_NAVIGATE,
2080 // This passes because we switch to the My Documents folder.
2081 DOWNLOAD_INTERRUPT_REASON_NONE,
2082 true
2083 };
2084
2085 DownloadFileToReadonlyFolder(download_info);
2086 }
OLDNEW
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698