summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/base_file_unittest.cc
diff options
context:
space:
mode:
authorahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-24 20:34:16 +0000
committerahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-24 20:34:16 +0000
commitf592032de5bc7cedc3fe009bd92646941399347a (patch)
tree204c054287fb1a43682c3a5b6bd299b7be80076b /chrome/browser/download/base_file_unittest.cc
parent2f1779f75be4a5286a1020f7e8972d271d20c2b2 (diff)
downloadchromium_src-f592032de5bc7cedc3fe009bd92646941399347a.zip
chromium_src-f592032de5bc7cedc3fe009bd92646941399347a.tar.gz
chromium_src-f592032de5bc7cedc3fe009bd92646941399347a.tar.bz2
Merging the safe and dangerous download paths.
Manual testing matrix: +--------------------------------------+------+-------+-------------+-------------+ | |Accept/Decline| Cancelled | | | Test |Before| After |Before|After | Completed | | |Full download |Full download| | +--------------------------------------+------+-------+-------------+-------------+ |Drag & Drop | N/A | N/A | Y | +--------------------------------------+------+-------+-------------+-------------+ |Safe | N/A | | | Y | +--------------------------------------+------+-------+-------------+-------------+ |Safe | N/A | Y | N/A | | +--------------------------------------+------+-------+-------------+-------------+ |Safe with uniquification | N/A | | N/A | Y | +--------------------------------------+------+-------+-------------+-------------+ |Safe with uniquification | N/A | Y | N/A | | +--------------------------------------+------+-------+-------------+-------------+ |Dangerous Accepted | Y | | N/A | Y | +--------------------------------------+------+-------+-------------+-------------+ |Dangerous Accepted | | Y | N/A | Y | +--------------------------------------+------+-------+-------------+-------------+ |Dangerous Accepted with uniquification| Y | | N/A | Y | +--------------------------------------+------+-------+-------------+-------------+ |Dangerous Accepted with uniquification| | Y | N/A | Y | +--------------------------------------+------+-------+-------------+-------------+ |Dangerous Declined | Y | | N/A | N/A | +--------------------------------------+------+-------+-------------+-------------+ |Dangerous Declined | | Y | N/A | N/A | +--------------------------------------+------+-------+-------------+-------------+ I couldn't figure out how to get Drag & Drop to work in Windows. All I got was a URL shortcut when I tried. BUG=49394, 49568, 75277 TEST=Passes all download tests. Passes all tests in the above matrix. Review URL: http://codereview.chromium.org/6588020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/base_file_unittest.cc')
-rw-r--r--chrome/browser/download/base_file_unittest.cc59
1 files changed, 56 insertions, 3 deletions
diff --git a/chrome/browser/download/base_file_unittest.cc b/chrome/browser/download/base_file_unittest.cc
index c6176fb..5eeb685 100644
--- a/chrome/browser/download/base_file_unittest.cc
+++ b/chrome/browser/download/base_file_unittest.cc
@@ -19,7 +19,9 @@ const char kTestData3[] = "Final line.";
class BaseFileTest : public testing::Test {
public:
- BaseFileTest() : file_thread_(BrowserThread::FILE, &message_loop_) {
+ BaseFileTest()
+ : expect_file_survives_(false),
+ file_thread_(BrowserThread::FILE, &message_loop_) {
}
virtual void SetUp() {
@@ -33,17 +35,20 @@ class BaseFileTest : public testing::Test {
EXPECT_EQ(static_cast<int64>(expected_data_.size()),
base_file_->bytes_so_far());
+ FilePath full_path = base_file_->full_path();
+
if (!expected_data_.empty()) {
// Make sure the data has been properly written to disk.
std::string disk_data;
- EXPECT_TRUE(file_util::ReadFileToString(base_file_->full_path(),
- &disk_data));
+ EXPECT_TRUE(file_util::ReadFileToString(full_path, &disk_data));
EXPECT_EQ(expected_data_, disk_data);
}
// Make sure the mock BrowserThread outlives the BaseFile to satisfy
// thread checks inside it.
base_file_.reset();
+
+ EXPECT_EQ(expect_file_survives_, file_util::PathExists(full_path));
}
void AppendDataToFile(const std::string& data) {
@@ -63,6 +68,9 @@ class BaseFileTest : public testing::Test {
// Temporary directory for renamed downloads.
ScopedTempDir temp_dir_;
+ // Expect the file to survive deletion of the BaseFile instance.
+ bool expect_file_survives_;
+
private:
// Keep track of what data should be saved to the disk file.
std::string expected_data_;
@@ -88,6 +96,51 @@ TEST_F(BaseFileTest, Cancel) {
EXPECT_NE(FilePath().value(), base_file_->full_path().value());
}
+// Write data to the file and detach it, so it doesn't get deleted
+// automatically when base_file_ is destructed.
+TEST_F(BaseFileTest, WriteAndDetach) {
+ ASSERT_TRUE(base_file_->Initialize(false));
+ AppendDataToFile(kTestData1);
+ base_file_->Finish();
+ base_file_->Detach();
+ expect_file_survives_ = true;
+}
+
+// Write data to the file and detach it, and calculate its sha256 hash.
+TEST_F(BaseFileTest, WriteWithHashAndDetach) {
+ ASSERT_TRUE(base_file_->Initialize(true));
+ AppendDataToFile(kTestData1);
+ base_file_->Finish();
+
+ std::string hash;
+ base_file_->GetSha256Hash(&hash);
+ EXPECT_EQ("0B2D3F3F7943AD64B860DF94D05CB56A8A97C6EC5768B5B70B930C5AA7FA9ADE",
+ base::HexEncode(hash.data(), hash.size()));
+
+ base_file_->Detach();
+ expect_file_survives_ = true;
+}
+
+// Rename the file after writing to it, then detach.
+TEST_F(BaseFileTest, WriteThenRenameAndDetach) {
+ ASSERT_TRUE(base_file_->Initialize(false));
+
+ FilePath initial_path(base_file_->full_path());
+ EXPECT_TRUE(file_util::PathExists(initial_path));
+ FilePath new_path(temp_dir_.path().AppendASCII("NewFile"));
+ EXPECT_FALSE(file_util::PathExists(new_path));
+
+ AppendDataToFile(kTestData1);
+
+ EXPECT_TRUE(base_file_->Rename(new_path));
+ EXPECT_FALSE(file_util::PathExists(initial_path));
+ EXPECT_TRUE(file_util::PathExists(new_path));
+
+ base_file_->Finish();
+ base_file_->Detach();
+ expect_file_survives_ = true;
+}
+
// Write data to the file once.
TEST_F(BaseFileTest, SingleWrite) {
ASSERT_TRUE(base_file_->Initialize(false));