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_impl.h" |
8 #include "content/browser/download/download_create_info.h" | 9 #include "content/browser/download/download_create_info.h" |
9 #include "content/browser/download/download_file.h" | 10 #include "content/browser/download/download_file.h" |
10 #include "content/browser/download/download_id.h" | 11 #include "content/browser/download/download_id.h" |
11 #include "content/browser/download/download_id_factory.h" | 12 #include "content/browser/download/download_id_factory.h" |
12 #include "content/browser/download/download_manager.h" | 13 #include "content/browser/download/download_manager.h" |
13 #include "content/browser/download/download_request_handle.h" | 14 #include "content/browser/download/download_request_handle.h" |
14 #include "content/browser/download/download_status_updater.h" | 15 #include "content/browser/download/download_status_updater.h" |
15 #include "content/browser/download/mock_download_manager.h" | 16 #include "content/browser/download/mock_download_manager.h" |
16 #include "content/browser/download/mock_download_manager_delegate.h" | 17 #include "content/browser/download/mock_download_manager_delegate.h" |
17 #include "content/test/test_browser_thread.h" | |
18 #include "net/base/file_stream.h" | 18 #include "net/base/file_stream.h" |
19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
| 22 using content::BrowserThreadImpl; |
| 23 |
22 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; | 24 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; |
23 | 25 |
24 class DownloadFileTest : public testing::Test { | 26 class DownloadFileTest : public testing::Test { |
25 public: | 27 public: |
26 | 28 |
27 static const char* kTestData1; | 29 static const char* kTestData1; |
28 static const char* kTestData2; | 30 static const char* kTestData2; |
29 static const char* kTestData3; | 31 static const char* kTestData3; |
30 static const char* kDataHash; | 32 static const char* kDataHash; |
31 static const int32 kDummyDownloadId; | 33 static const int32 kDummyDownloadId; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 108 |
107 linked_ptr<net::FileStream> file_stream_; | 109 linked_ptr<net::FileStream> file_stream_; |
108 | 110 |
109 // DownloadFile instance we are testing. | 111 // DownloadFile instance we are testing. |
110 scoped_ptr<DownloadFile> download_file_; | 112 scoped_ptr<DownloadFile> download_file_; |
111 | 113 |
112 private: | 114 private: |
113 MessageLoop loop_; | 115 MessageLoop loop_; |
114 scoped_refptr<DownloadIdFactory> id_factory_; | 116 scoped_refptr<DownloadIdFactory> id_factory_; |
115 // UI thread. | 117 // UI thread. |
116 content::TestBrowserThread ui_thread_; | 118 BrowserThreadImpl ui_thread_; |
117 // File thread to satisfy debug checks in DownloadFile. | 119 // File thread to satisfy debug checks in DownloadFile. |
118 content::TestBrowserThread file_thread_; | 120 BrowserThreadImpl file_thread_; |
119 | 121 |
120 // Keep track of what data should be saved to the disk file. | 122 // Keep track of what data should be saved to the disk file. |
121 std::string expected_data_; | 123 std::string expected_data_; |
122 }; | 124 }; |
123 | 125 |
124 const char* DownloadFileTest::kTestData1 = | 126 const char* DownloadFileTest::kTestData1 = |
125 "Let's write some data to the file!\n"; | 127 "Let's write some data to the file!\n"; |
126 const char* DownloadFileTest::kTestData2 = "Writing more data.\n"; | 128 const char* DownloadFileTest::kTestData2 = "Writing more data.\n"; |
127 const char* DownloadFileTest::kTestData3 = "Final line."; | 129 const char* DownloadFileTest::kTestData3 = "Final line."; |
128 const char* DownloadFileTest::kDataHash = | 130 const char* DownloadFileTest::kDataHash = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // Check the files. | 193 // Check the files. |
192 EXPECT_FALSE(file_util::PathExists(path_3)); | 194 EXPECT_FALSE(file_util::PathExists(path_3)); |
193 EXPECT_TRUE(file_util::PathExists(path_4)); | 195 EXPECT_TRUE(file_util::PathExists(path_4)); |
194 | 196 |
195 // Check the hash. | 197 // Check the hash. |
196 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); | 198 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); |
197 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); | 199 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); |
198 | 200 |
199 DestroyDownloadFile(&download_file_, 0); | 201 DestroyDownloadFile(&download_file_, 0); |
200 } | 202 } |
OLD | NEW |