| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
| 9 #include "chrome/browser/download/base_file.h" | 9 #include "chrome/browser/download/base_file.h" |
| 10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const char kTestData1[] = "Let's write some data to the file!\n"; | 15 const char kTestData1[] = "Let's write some data to the file!\n"; |
| 16 const char kTestData2[] = "Writing more data.\n"; | 16 const char kTestData2[] = "Writing more data.\n"; |
| 17 const char kTestData3[] = "Final line."; | 17 const char kTestData3[] = "Final line."; |
| 18 | 18 |
| 19 class BaseFileTest : public testing::Test { | 19 class BaseFileTest : public testing::Test { |
| 20 public: | 20 public: |
| 21 BaseFileTest() : file_thread_(ChromeThread::FILE, &message_loop_) { | 21 BaseFileTest() : file_thread_(ChromeThread::FILE, &message_loop_) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 virtual void SetUp() { | 24 virtual void SetUp() { |
| 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 26 base_file_.reset(new BaseFile(FilePath(), GURL(), GURL(), 0, file_stream_)); | 26 base_file_.reset(new BaseFile(FilePath(), GURL(), GURL(), file_stream_)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 virtual void TearDown() { | 29 virtual void TearDown() { |
| 30 EXPECT_FALSE(base_file_->in_progress()); | 30 EXPECT_FALSE(base_file_->in_progress()); |
| 31 EXPECT_EQ(static_cast<int64>(expected_data_.size()), | 31 EXPECT_EQ(static_cast<int64>(expected_data_.size()), |
| 32 base_file_->bytes_so_far()); | 32 base_file_->bytes_so_far()); |
| 33 | 33 |
| 34 if (!expected_data_.empty()) { | 34 if (!expected_data_.empty()) { |
| 35 // Make sure the data has been properly written to disk. | 35 // Make sure the data has been properly written to disk. |
| 36 std::string disk_data; | 36 std::string disk_data; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 EXPECT_TRUE(file_util::PathExists(new_path)); | 145 EXPECT_TRUE(file_util::PathExists(new_path)); |
| 146 | 146 |
| 147 AppendDataToFile(kTestData2); | 147 AppendDataToFile(kTestData2); |
| 148 | 148 |
| 149 base_file_->Finish(); | 149 base_file_->Finish(); |
| 150 | 150 |
| 151 EXPECT_TRUE(base_file_->path_renamed()); | 151 EXPECT_TRUE(base_file_->path_renamed()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace | 154 } // namespace |
| OLD | NEW |