| 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 "content/browser/download/base_file.h" | 5 #include "content/browser/download/base_file.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 ASSERT_TRUE(InitializeFile()); | 382 ASSERT_TRUE(InitializeFile()); |
| 383 // Write some data | 383 // Write some data |
| 384 ASSERT_TRUE(AppendDataToFile(kTestData1)); | 384 ASSERT_TRUE(AppendDataToFile(kTestData1)); |
| 385 ASSERT_TRUE(AppendDataToFile(kTestData2)); | 385 ASSERT_TRUE(AppendDataToFile(kTestData2)); |
| 386 // Get the hash state and file name. | 386 // Get the hash state and file name. |
| 387 std::string hash_state; | 387 std::string hash_state; |
| 388 hash_state = base_file_->GetHashState(); | 388 hash_state = base_file_->GetHashState(); |
| 389 // Finish the file. | 389 // Finish the file. |
| 390 base_file_->Finish(); | 390 base_file_->Finish(); |
| 391 | 391 |
| 392 FilePath new_file_path(temp_dir_.path().Append( |
| 393 FilePath(FILE_PATH_LITERAL("second_file")))); |
| 394 |
| 395 ASSERT_TRUE(file_util::CopyFile(base_file_->full_path(), new_file_path)); |
| 396 |
| 392 // Create another file | 397 // Create another file |
| 393 BaseFile second_file(FilePath(), | 398 BaseFile second_file(new_file_path, |
| 394 GURL(), | 399 GURL(), |
| 395 GURL(), | 400 GURL(), |
| 396 base_file_->bytes_so_far(), | 401 base_file_->bytes_so_far(), |
| 397 true, | 402 true, |
| 398 hash_state, | 403 hash_state, |
| 399 scoped_ptr<net::FileStream>(), | 404 scoped_ptr<net::FileStream>(), |
| 400 net::BoundNetLog()); | 405 net::BoundNetLog()); |
| 401 ASSERT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, | 406 ASSERT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 402 second_file.Initialize(temp_dir_.path())); | 407 second_file.Initialize(FilePath())); |
| 403 std::string data(kTestData3); | 408 std::string data(kTestData3); |
| 404 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, | 409 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 405 second_file.AppendDataToFile(data.data(), data.size())); | 410 second_file.AppendDataToFile(data.data(), data.size())); |
| 406 second_file.Finish(); | 411 second_file.Finish(); |
| 407 | 412 |
| 408 std::string hash; | 413 std::string hash; |
| 409 EXPECT_TRUE(second_file.GetHash(&hash)); | 414 EXPECT_TRUE(second_file.GetHash(&hash)); |
| 410 // This will fail until getting the hash state is supported in SecureHash. | 415 // This will fail until getting the hash state is supported in SecureHash. |
| 411 EXPECT_STREQ(expected_hash_hex.c_str(), | 416 EXPECT_STREQ(expected_hash_hex.c_str(), |
| 412 base::HexEncode(hash.data(), hash.size()).c_str()); | 417 base::HexEncode(hash.data(), hash.size()).c_str()); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 FilePath temp_file; | 665 FilePath temp_file; |
| 661 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 666 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), |
| 662 &temp_file)); | 667 &temp_file)); |
| 663 ASSERT_FALSE(temp_file.empty()); | 668 ASSERT_FALSE(temp_file.empty()); |
| 664 EXPECT_STREQ(temp_file.DirName().value().c_str(), | 669 EXPECT_STREQ(temp_file.DirName().value().c_str(), |
| 665 base_file_->full_path().DirName().value().c_str()); | 670 base_file_->full_path().DirName().value().c_str()); |
| 666 base_file_->Finish(); | 671 base_file_->Finish(); |
| 667 } | 672 } |
| 668 | 673 |
| 669 } // namespace content | 674 } // namespace content |
| OLD | NEW |