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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
9 | 10 |
10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 #include "base/test/test_file_util.h" | 18 #include "base/test/test_file_util.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 537 } |
537 | 538 |
538 // Test that a failed write reports an error. | 539 // Test that a failed write reports an error. |
539 TEST_F(BaseFileTest, WriteWithError) { | 540 TEST_F(BaseFileTest, WriteWithError) { |
540 base::FilePath path; | 541 base::FilePath path; |
541 ASSERT_TRUE(base::CreateTemporaryFile(&path)); | 542 ASSERT_TRUE(base::CreateTemporaryFile(&path)); |
542 | 543 |
543 // Pass a file handle which was opened without the WRITE flag. | 544 // Pass a file handle which was opened without the WRITE flag. |
544 // This should result in an error when writing. | 545 // This should result in an error when writing. |
545 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ); | 546 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ); |
546 base_file_.reset(new BaseFile(path, | 547 base_file_.reset(new BaseFile(path, GURL(), GURL(), 0, false, std::string(), |
547 GURL(), | 548 std::move(file), net::BoundNetLog())); |
548 GURL(), | |
549 0, | |
550 false, | |
551 std::string(), | |
552 file.Pass(), | |
553 net::BoundNetLog())); | |
554 ASSERT_TRUE(InitializeFile()); | 549 ASSERT_TRUE(InitializeFile()); |
555 #if defined(OS_WIN) | 550 #if defined(OS_WIN) |
556 set_expected_error(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); | 551 set_expected_error(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); |
557 #elif defined (OS_POSIX) | 552 #elif defined (OS_POSIX) |
558 set_expected_error(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 553 set_expected_error(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
559 #endif | 554 #endif |
560 ASSERT_FALSE(AppendDataToFile(kTestData1)); | 555 ASSERT_FALSE(AppendDataToFile(kTestData1)); |
561 base_file_->Finish(); | 556 base_file_->Finish(); |
562 } | 557 } |
563 | 558 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 684 |
690 const char kData[] = "hello"; | 685 const char kData[] = "hello"; |
691 const int kDataLength = static_cast<int>(arraysize(kData) - 1); | 686 const int kDataLength = static_cast<int>(arraysize(kData) - 1); |
692 ASSERT_EQ(kDataLength, base::WriteFile(full_path, kData, kDataLength)); | 687 ASSERT_EQ(kDataLength, base::WriteFile(full_path, kData, kDataLength)); |
693 // The file that we created here should stick around when the BaseFile is | 688 // The file that we created here should stick around when the BaseFile is |
694 // destroyed during TearDown. | 689 // destroyed during TearDown. |
695 expect_file_survives_ = true; | 690 expect_file_survives_ = true; |
696 } | 691 } |
697 | 692 |
698 } // namespace content | 693 } // namespace content |
OLD | NEW |