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/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "chrome/browser/download/download_create_info.h" | 9 #include "chrome/browser/download/download_create_info.h" |
10 #include "chrome/browser/download/download_file.h" | 10 #include "chrome/browser/download/download_file.h" |
11 #include "chrome/browser/download/download_manager.h" | 11 #include "chrome/browser/download/download_manager.h" |
12 #include "chrome/browser/download/download_process_handle.h" | 12 #include "chrome/browser/download/download_request_handle.h" |
13 #include "chrome/browser/download/download_status_updater.h" | 13 #include "chrome/browser/download/download_status_updater.h" |
14 #include "chrome/browser/download/download_util.h" | 14 #include "chrome/browser/download/download_util.h" |
15 #include "chrome/browser/download/mock_download_manager.h" | 15 #include "chrome/browser/download/mock_download_manager.h" |
16 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
17 #include "net/base/file_stream.h" | 17 #include "net/base/file_stream.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 |
(...skipping 28 matching lines...) Expand all Loading... |
51 // message loop to delete it. | 51 // message loop to delete it. |
52 // So, drop the reference count to 0 and run the message loop once | 52 // So, drop the reference count to 0 and run the message loop once |
53 // to ensure that all resources are cleaned up before the test exits. | 53 // to ensure that all resources are cleaned up before the test exits. |
54 download_manager_ = NULL; | 54 download_manager_ = NULL; |
55 ui_thread_.message_loop()->RunAllPending(); | 55 ui_thread_.message_loop()->RunAllPending(); |
56 } | 56 } |
57 | 57 |
58 virtual void CreateDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { | 58 virtual void CreateDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { |
59 DownloadCreateInfo info; | 59 DownloadCreateInfo info; |
60 info.download_id = kDummyDownloadId + offset; | 60 info.download_id = kDummyDownloadId + offset; |
61 info.process_handle = | 61 // info.request_handle default constructed to null. |
62 DownloadProcessHandle(kDummyChildId, -1, kDummyRequestId - offset); | |
63 info.save_info.file_stream = file_stream_; | 62 info.save_info.file_stream = file_stream_; |
64 file->reset(new DownloadFile(&info, download_manager_)); | 63 file->reset(new DownloadFile(&info, download_manager_)); |
65 } | 64 } |
66 | 65 |
67 virtual void DestroyDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { | 66 virtual void DestroyDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { |
68 EXPECT_EQ(kDummyDownloadId + offset, (*file)->id()); | 67 EXPECT_EQ(kDummyDownloadId + offset, (*file)->id()); |
69 EXPECT_EQ(download_manager_, (*file)->GetDownloadManager()); | 68 EXPECT_EQ(download_manager_, (*file)->GetDownloadManager()); |
70 EXPECT_FALSE((*file)->in_progress()); | 69 EXPECT_FALSE((*file)->in_progress()); |
71 EXPECT_EQ(static_cast<int64>(expected_data_.size()), | 70 EXPECT_EQ(static_cast<int64>(expected_data_.size()), |
72 (*file)->bytes_so_far()); | 71 (*file)->bytes_so_far()); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Check the files. | 183 // Check the files. |
185 EXPECT_FALSE(file_util::PathExists(path_3)); | 184 EXPECT_FALSE(file_util::PathExists(path_3)); |
186 EXPECT_TRUE(file_util::PathExists(path_4)); | 185 EXPECT_TRUE(file_util::PathExists(path_4)); |
187 | 186 |
188 // Check the hash. | 187 // Check the hash. |
189 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); | 188 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); |
190 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); | 189 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); |
191 | 190 |
192 DestroyDownloadFile(&download_file_, 0); | 191 DestroyDownloadFile(&download_file_, 0); |
193 } | 192 } |
OLD | NEW |