OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/download/internal/test/test_download_driver.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "components/download/public/download_params.h" |
| 9 #include "net/http/http_response_headers.h" |
| 10 |
| 11 namespace download { |
| 12 |
| 13 TestDownloadDriver::TestDownloadDriver() : is_ready_(false), client_(nullptr) {} |
| 14 |
| 15 TestDownloadDriver::~TestDownloadDriver() = default; |
| 16 |
| 17 void TestDownloadDriver::MakeReady() { |
| 18 is_ready_ = true; |
| 19 DCHECK(client_); |
| 20 if (client_) |
| 21 client_->OnDriverReady(); |
| 22 } |
| 23 |
| 24 void TestDownloadDriver::NotifyDownloadUpdate(const DriverEntry& entry) { |
| 25 if (client_) { |
| 26 entries_[entry.guid] = entry; |
| 27 client_->OnDriverReady(); |
| 28 } |
| 29 } |
| 30 |
| 31 void TestDownloadDriver::NotifyDownloadFailed(const DriverEntry& entry, |
| 32 int reason) { |
| 33 if (client_) { |
| 34 entries_[entry.guid] = entry; |
| 35 client_->OnDownloadFailed(entry, reason); |
| 36 } |
| 37 } |
| 38 |
| 39 void TestDownloadDriver::NotifyDownloadSucceeded(const DriverEntry& entry, |
| 40 const base::FilePath& path) { |
| 41 if (client_) { |
| 42 entries_[entry.guid] = entry; |
| 43 client_->OnDownloadSucceeded(entry, path); |
| 44 } |
| 45 } |
| 46 |
| 47 void TestDownloadDriver::Initialize(DownloadDriver::Client* client) { |
| 48 DCHECK(!client_); |
| 49 client_ = client; |
| 50 } |
| 51 |
| 52 void TestDownloadDriver::Start(const DownloadParams& params) { |
| 53 DriverEntry entry; |
| 54 entry.guid = params.guid; |
| 55 entry.state = DriverEntry::State::IN_PROGRESS; |
| 56 entry.paused = false; |
| 57 entry.bytes_downloaded = 0; |
| 58 entry.expected_total_size = 0; |
| 59 entry.response_headers = |
| 60 make_scoped_refptr(new net::HttpResponseHeaders("HTTP/1.1 200")); |
| 61 entries_[params.guid] = entry; |
| 62 |
| 63 if (client_) |
| 64 client_->OnDownloadCreated(entry); |
| 65 } |
| 66 |
| 67 void TestDownloadDriver::Cancel(const std::string& guid) {} |
| 68 |
| 69 void TestDownloadDriver::Pause(const std::string& guid) {} |
| 70 |
| 71 void TestDownloadDriver::Resume(const std::string& guid) {} |
| 72 |
| 73 DriverEntry TestDownloadDriver::Find(const std::string& guid) { |
| 74 auto it = entries_.find(guid); |
| 75 return it != entries_.end() ? it->second : DriverEntry(); |
| 76 } |
| 77 |
| 78 } // namespace downloads |
OLD | NEW |