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_store.h" |
| 6 |
| 7 #include "components/download/internal/entry.h" |
| 8 |
| 9 namespace download { |
| 10 namespace test { |
| 11 |
| 12 TestStore::TestStore() |
| 13 : ready_(false), init_called_(false), destroy_called_(false) {} |
| 14 |
| 15 TestStore::~TestStore() {} |
| 16 |
| 17 bool TestStore::IsInitialized() { |
| 18 return ready_; |
| 19 } |
| 20 |
| 21 void TestStore::Initialize(InitCallback callback) { |
| 22 init_called_ = true; |
| 23 init_callback_ = std::move(callback); |
| 24 } |
| 25 |
| 26 void TestStore::Destroy(StoreCallback callback) { |
| 27 destroy_called_ = true; |
| 28 destroy_callback_ = std::move(callback); |
| 29 } |
| 30 |
| 31 void TestStore::Update(const Entry& entry, StoreCallback callback) { |
| 32 updated_entries_.push_back(entry); |
| 33 update_callback_ = std::move(callback); |
| 34 } |
| 35 |
| 36 void TestStore::Remove(const std::string& guid, StoreCallback callback) { |
| 37 removed_entries_.push_back(guid); |
| 38 remove_callback_ = std::move(callback); |
| 39 } |
| 40 |
| 41 // Callback trigger methods. |
| 42 void TestStore::TriggerInit(bool success, |
| 43 std::unique_ptr<std::vector<Entry>> entries) { |
| 44 ready_ = success; |
| 45 DCHECK(init_callback_); |
| 46 std::move(init_callback_).Run(success, std::move(entries)); |
| 47 } |
| 48 |
| 49 void TestStore::TriggerDestroy(bool success) { |
| 50 DCHECK(destroy_callback_); |
| 51 std::move(destroy_callback_).Run(success); |
| 52 } |
| 53 |
| 54 void TestStore::TriggerUpdate(bool success) { |
| 55 DCHECK(update_callback_); |
| 56 std::move(update_callback_).Run(success); |
| 57 } |
| 58 |
| 59 void TestStore::TriggerRemove(bool success) { |
| 60 DCHECK(remove_callback_); |
| 61 std::move(remove_callback_).Run(success); |
| 62 } |
| 63 |
| 64 const Entry* TestStore::LastUpdatedEntry() const { |
| 65 return &updated_entries_.back(); |
| 66 } |
| 67 |
| 68 std::string TestStore::LastRemovedEntry() const { |
| 69 return removed_entries_.back(); |
| 70 } |
| 71 |
| 72 } // namespace test |
| 73 } // namespace download |
OLD | NEW |