| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "components/offline_pages/offline_page_item.h" |
| 14 #include "components/offline_pages/offline_page_metadata_store.h" |
| 15 |
| 16 namespace offline_pages { |
| 17 |
| 18 // Offline page store to be used for testing purposes. It stores offline pages |
| 19 // in memory. All callbacks are posted immediately through a provided |
| 20 // |task_runner|. |
| 21 class OfflinePageTestStore : public OfflinePageMetadataStore { |
| 22 public: |
| 23 enum class TestScenario { |
| 24 SUCCESSFUL, |
| 25 WRITE_FAILED, |
| 26 LOAD_FAILED, |
| 27 REMOVE_FAILED, |
| 28 }; |
| 29 |
| 30 explicit OfflinePageTestStore( |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 32 explicit OfflinePageTestStore(const OfflinePageTestStore& other_store); |
| 33 ~OfflinePageTestStore() override; |
| 34 |
| 35 // OfflinePageMetadataStore overrides: |
| 36 void Load(const LoadCallback& callback) override; |
| 37 void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page, |
| 38 const UpdateCallback& callback) override; |
| 39 void RemoveOfflinePages(const std::vector<int64>& bookmark_ids, |
| 40 const UpdateCallback& callback) override; |
| 41 void Reset(const ResetCallback& callback) override; |
| 42 |
| 43 void UpdateLastAccessTime(int64 bookmark_id, |
| 44 const base::Time& last_access_time); |
| 45 |
| 46 const OfflinePageItem& last_saved_page() const { return last_saved_page_; } |
| 47 |
| 48 void set_test_scenario(TestScenario scenario) { scenario_ = scenario; }; |
| 49 |
| 50 const std::vector<OfflinePageItem>& offline_pages() const { |
| 51 return offline_pages_; |
| 52 } |
| 53 |
| 54 private: |
| 55 OfflinePageItem last_saved_page_; |
| 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 57 TestScenario scenario_; |
| 58 |
| 59 std::vector<OfflinePageItem> offline_pages_; |
| 60 |
| 61 DISALLOW_ASSIGN(OfflinePageTestStore); |
| 62 }; |
| 63 |
| 64 } // namespace offline_pages |
| 65 |
| 66 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_ |
| OLD | NEW |