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 "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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/test/test_file_util.h" | 12 #include "base/test/test_file_util.h" |
13 #include "content/browser/browser_thread.h" | 13 #include "content/test/test_browser_thread.h" |
14 #include "net/base/file_stream.h" | 14 #include "net/base/file_stream.h" |
15 #include "net/base/mock_file_stream.h" | 15 #include "net/base/mock_file_stream.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kTestData1[] = "Let's write some data to the file!\n"; | 21 const char kTestData1[] = "Let's write some data to the file!\n"; |
22 const char kTestData2[] = "Writing more data.\n"; | 22 const char kTestData2[] = "Writing more data.\n"; |
23 const char kTestData3[] = "Final line."; | 23 const char kTestData3[] = "Final line."; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Expect the file to be in progress. | 155 // Expect the file to be in progress. |
156 bool expect_in_progress_; | 156 bool expect_in_progress_; |
157 | 157 |
158 private: | 158 private: |
159 // Keep track of what data should be saved to the disk file. | 159 // Keep track of what data should be saved to the disk file. |
160 std::string expected_data_; | 160 std::string expected_data_; |
161 bool expected_error_; | 161 bool expected_error_; |
162 | 162 |
163 // Mock file thread to satisfy debug checks in BaseFile. | 163 // Mock file thread to satisfy debug checks in BaseFile. |
164 MessageLoop message_loop_; | 164 MessageLoop message_loop_; |
165 BrowserThread file_thread_; | 165 content::TestBrowserThread file_thread_; |
166 }; | 166 }; |
167 | 167 |
168 // Test the most basic scenario: just create the object and do a sanity check | 168 // Test the most basic scenario: just create the object and do a sanity check |
169 // on all its accessors. This is actually a case that rarely happens | 169 // on all its accessors. This is actually a case that rarely happens |
170 // in production, where we would at least Initialize it. | 170 // in production, where we would at least Initialize it. |
171 TEST_F(BaseFileTest, CreateDestroy) { | 171 TEST_F(BaseFileTest, CreateDestroy) { |
172 EXPECT_EQ(FilePath().value(), base_file_->full_path().value()); | 172 EXPECT_EQ(FilePath().value(), base_file_->full_path().value()); |
173 } | 173 } |
174 | 174 |
175 // Cancel the download explicitly. | 175 // Cancel the download explicitly. |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 394 |
395 // Write into the file. | 395 // Write into the file. |
396 EXPECT_NE(net::OK, AppendDataToFile(kTestData1)); | 396 EXPECT_NE(net::OK, AppendDataToFile(kTestData1)); |
397 | 397 |
398 base_file_->Finish(); | 398 base_file_->Finish(); |
399 base_file_->Detach(); | 399 base_file_->Detach(); |
400 expect_file_survives_ = true; | 400 expect_file_survives_ = true; |
401 } | 401 } |
402 | 402 |
403 } // namespace | 403 } // namespace |
OLD | NEW |