| Index: components/download/internal/test/test_download_driver.cc
|
| diff --git a/components/download/internal/test/test_download_driver.cc b/components/download/internal/test/test_download_driver.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..78a127cbb60b0b91c53bbad59a6539fa7a424117
|
| --- /dev/null
|
| +++ b/components/download/internal/test/test_download_driver.cc
|
| @@ -0,0 +1,78 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/download/internal/test/test_download_driver.h"
|
| +
|
| +#include "base/files/file_path.h"
|
| +#include "components/download/public/download_params.h"
|
| +#include "net/http/http_response_headers.h"
|
| +
|
| +namespace download {
|
| +
|
| +TestDownloadDriver::TestDownloadDriver() : is_ready_(false), client_(nullptr) {}
|
| +
|
| +TestDownloadDriver::~TestDownloadDriver() = default;
|
| +
|
| +void TestDownloadDriver::MakeReady() {
|
| + is_ready_ = true;
|
| + DCHECK(client_);
|
| + if (client_)
|
| + client_->OnDriverReady();
|
| +}
|
| +
|
| +void TestDownloadDriver::NotifyDownloadUpdate(const DriverEntry& entry) {
|
| + if (client_) {
|
| + entries_[entry.guid] = entry;
|
| + client_->OnDriverReady();
|
| + }
|
| +}
|
| +
|
| +void TestDownloadDriver::NotifyDownloadFailed(const DriverEntry& entry,
|
| + int reason) {
|
| + if (client_) {
|
| + entries_[entry.guid] = entry;
|
| + client_->OnDownloadFailed(entry, reason);
|
| + }
|
| +}
|
| +
|
| +void TestDownloadDriver::NotifyDownloadSucceeded(const DriverEntry& entry,
|
| + const base::FilePath& path) {
|
| + if (client_) {
|
| + entries_[entry.guid] = entry;
|
| + client_->OnDownloadSucceeded(entry, path);
|
| + }
|
| +}
|
| +
|
| +void TestDownloadDriver::Initialize(DownloadDriver::Client* client) {
|
| + DCHECK(!client_);
|
| + client_ = client;
|
| +}
|
| +
|
| +void TestDownloadDriver::Start(const DownloadParams& params) {
|
| + DriverEntry entry;
|
| + entry.guid = params.guid;
|
| + entry.state = DriverEntry::State::IN_PROGRESS;
|
| + entry.paused = false;
|
| + entry.bytes_downloaded = 0;
|
| + entry.expected_total_size = 0;
|
| + entry.response_headers =
|
| + make_scoped_refptr(new net::HttpResponseHeaders("HTTP/1.1 200"));
|
| + entries_[params.guid] = entry;
|
| +
|
| + if (client_)
|
| + client_->OnDownloadCreated(entry);
|
| +}
|
| +
|
| +void TestDownloadDriver::Cancel(const std::string& guid) {}
|
| +
|
| +void TestDownloadDriver::Pause(const std::string& guid) {}
|
| +
|
| +void TestDownloadDriver::Resume(const std::string& guid) {}
|
| +
|
| +DriverEntry TestDownloadDriver::Find(const std::string& guid) {
|
| + auto it = entries_.find(guid);
|
| + return it != entries_.end() ? it->second : DriverEntry();
|
| +}
|
| +
|
| +} // namespace downloads
|
|
|