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/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "content/browser/browser_thread.h" | |
9 #include "content/browser/download/download_create_info.h" | 8 #include "content/browser/download/download_create_info.h" |
10 #include "content/browser/download/download_file.h" | 9 #include "content/browser/download/download_file.h" |
11 #include "content/browser/download/download_manager.h" | 10 #include "content/browser/download/download_manager.h" |
12 #include "content/browser/download/download_request_handle.h" | 11 #include "content/browser/download/download_request_handle.h" |
13 #include "content/browser/download/download_status_updater.h" | 12 #include "content/browser/download/download_status_updater.h" |
14 #include "content/browser/download/mock_download_manager.h" | 13 #include "content/browser/download/mock_download_manager.h" |
15 #include "content/browser/download/mock_download_manager_delegate.h" | 14 #include "content/browser/download/mock_download_manager_delegate.h" |
| 15 #include "content/test/test_browser_thread.h" |
16 #include "net/base/file_stream.h" | 16 #include "net/base/file_stream.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 class DownloadFileTest : public testing::Test { | 20 class DownloadFileTest : public testing::Test { |
21 public: | 21 public: |
22 | 22 |
23 static const char* kTestData1; | 23 static const char* kTestData1; |
24 static const char* kTestData2; | 24 static const char* kTestData2; |
25 static const char* kTestData3; | 25 static const char* kTestData3; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 scoped_refptr<DownloadManager> download_manager_; | 98 scoped_refptr<DownloadManager> download_manager_; |
99 | 99 |
100 linked_ptr<net::FileStream> file_stream_; | 100 linked_ptr<net::FileStream> file_stream_; |
101 | 101 |
102 // DownloadFile instance we are testing. | 102 // DownloadFile instance we are testing. |
103 scoped_ptr<DownloadFile> download_file_; | 103 scoped_ptr<DownloadFile> download_file_; |
104 | 104 |
105 private: | 105 private: |
106 MessageLoop loop_; | 106 MessageLoop loop_; |
107 // UI thread. | 107 // UI thread. |
108 BrowserThread ui_thread_; | 108 content::TestBrowserThread ui_thread_; |
109 // File thread to satisfy debug checks in DownloadFile. | 109 // File thread to satisfy debug checks in DownloadFile. |
110 BrowserThread file_thread_; | 110 content::TestBrowserThread file_thread_; |
111 | 111 |
112 // Keep track of what data should be saved to the disk file. | 112 // Keep track of what data should be saved to the disk file. |
113 std::string expected_data_; | 113 std::string expected_data_; |
114 }; | 114 }; |
115 | 115 |
116 const char* DownloadFileTest::kTestData1 = | 116 const char* DownloadFileTest::kTestData1 = |
117 "Let's write some data to the file!\n"; | 117 "Let's write some data to the file!\n"; |
118 const char* DownloadFileTest::kTestData2 = "Writing more data.\n"; | 118 const char* DownloadFileTest::kTestData2 = "Writing more data.\n"; |
119 const char* DownloadFileTest::kTestData3 = "Final line."; | 119 const char* DownloadFileTest::kTestData3 = "Final line."; |
120 const char* DownloadFileTest::kDataHash = | 120 const char* DownloadFileTest::kDataHash = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Check the files. | 183 // Check the files. |
184 EXPECT_FALSE(file_util::PathExists(path_3)); | 184 EXPECT_FALSE(file_util::PathExists(path_3)); |
185 EXPECT_TRUE(file_util::PathExists(path_4)); | 185 EXPECT_TRUE(file_util::PathExists(path_4)); |
186 | 186 |
187 // Check the hash. | 187 // Check the hash. |
188 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); | 188 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); |
189 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); | 189 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); |
190 | 190 |
191 DestroyDownloadFile(&download_file_, 0); | 191 DestroyDownloadFile(&download_file_, 0); |
192 } | 192 } |
OLD | NEW |