OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "chrome/browser/download/download_create_info.h" | 9 #include "chrome/browser/download/download_create_info.h" |
10 #include "chrome/browser/download/download_file.h" | 10 #include "chrome/browser/download/download_file.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 "CBF68BF10F8003DB86B31343AFAC8C7175BD03FB5FC905650F8C80AF087443A8"; | 121 "CBF68BF10F8003DB86B31343AFAC8C7175BD03FB5FC905650F8C80AF087443A8"; |
122 | 122 |
123 const int32 DownloadFileTest::kDummyDownloadId = 23; | 123 const int32 DownloadFileTest::kDummyDownloadId = 23; |
124 const int DownloadFileTest::kDummyChildId = 3; | 124 const int DownloadFileTest::kDummyChildId = 3; |
125 const int DownloadFileTest::kDummyRequestId = 67; | 125 const int DownloadFileTest::kDummyRequestId = 67; |
126 | 126 |
127 // Rename the file before any data is downloaded, after some has, after it all | 127 // Rename the file before any data is downloaded, after some has, after it all |
128 // has, and after it's closed. | 128 // has, and after it's closed. |
129 TEST_F(DownloadFileTest, RenameFileFinal) { | 129 TEST_F(DownloadFileTest, RenameFileFinal) { |
130 CreateDownloadFile(&download_file_, 0); | 130 CreateDownloadFile(&download_file_, 0); |
131 ASSERT_TRUE(download_file_->Initialize(true)); | 131 ScopedTempDir temp_dir; |
| 132 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 133 ASSERT_TRUE(download_file_->Initialize(true, temp_dir.path())); |
132 FilePath initial_path(download_file_->full_path()); | 134 FilePath initial_path(download_file_->full_path()); |
133 EXPECT_TRUE(file_util::PathExists(initial_path)); | 135 EXPECT_TRUE(file_util::PathExists(initial_path)); |
134 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); | 136 FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); |
135 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); | 137 FilePath path_2(initial_path.InsertBeforeExtensionASCII("_2")); |
136 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); | 138 FilePath path_3(initial_path.InsertBeforeExtensionASCII("_3")); |
137 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); | 139 FilePath path_4(initial_path.InsertBeforeExtensionASCII("_4")); |
138 | 140 |
139 // Rename the file before downloading any data. | 141 // Rename the file before downloading any data. |
140 EXPECT_TRUE(download_file_->Rename(path_1)); | 142 EXPECT_TRUE(download_file_->Rename(path_1)); |
141 FilePath renamed_path = download_file_->full_path(); | 143 FilePath renamed_path = download_file_->full_path(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Check the files. | 185 // Check the files. |
184 EXPECT_FALSE(file_util::PathExists(path_3)); | 186 EXPECT_FALSE(file_util::PathExists(path_3)); |
185 EXPECT_TRUE(file_util::PathExists(path_4)); | 187 EXPECT_TRUE(file_util::PathExists(path_4)); |
186 | 188 |
187 // Check the hash. | 189 // Check the hash. |
188 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); | 190 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); |
189 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); | 191 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); |
190 | 192 |
191 DestroyDownloadFile(&download_file_, 0); | 193 DestroyDownloadFile(&download_file_, 0); |
192 } | 194 } |
OLD | NEW |