Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Unified Diff: components/offline_pages/offline_page_test_store.h

Issue 1504243002: [Offline pages] Refactoring helper classes out from offline_page_model_unittest.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing gn build and addressing comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/offline_page_test_store.h
diff --git a/components/offline_pages/offline_page_test_store.h b/components/offline_pages/offline_page_test_store.h
new file mode 100644
index 0000000000000000000000000000000000000000..f24ac3c41f18bd9320d44236ab2071a7d6b2c64a
--- /dev/null
+++ b/components/offline_pages/offline_page_test_store.h
@@ -0,0 +1,66 @@
+// Copyright 2015 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.
+
+#ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_
+#define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_
+
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/single_thread_task_runner.h"
+#include "components/offline_pages/offline_page_item.h"
+#include "components/offline_pages/offline_page_metadata_store.h"
+
+namespace offline_pages {
+
+// Offline page store to be used for testing purposes. It stores offline pages
+// in memory. All callbacks are posted immediately through a provided
+// |task_runner|.
+class OfflinePageTestStore : public OfflinePageMetadataStore {
+ public:
+ enum class TestScenario {
+ SUCCESSFUL,
+ WRITE_FAILED,
+ LOAD_FAILED,
+ REMOVE_FAILED,
+ };
+
+ explicit OfflinePageTestStore(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
+ explicit OfflinePageTestStore(const OfflinePageTestStore& other_store);
+ ~OfflinePageTestStore() override;
+
+ // OfflinePageMetadataStore overrides:
+ void Load(const LoadCallback& callback) override;
+ void AddOrUpdateOfflinePage(const OfflinePageItem& offline_page,
+ const UpdateCallback& callback) override;
+ void RemoveOfflinePages(const std::vector<int64>& bookmark_ids,
+ const UpdateCallback& callback) override;
+ void Reset(const ResetCallback& callback) override;
+
+ void UpdateLastAccessTime(int64 bookmark_id,
+ const base::Time& last_access_time);
+
+ const OfflinePageItem& last_saved_page() const { return last_saved_page_; }
+
+ void set_test_scenario(TestScenario scenario) { scenario_ = scenario; };
+
+ const std::vector<OfflinePageItem>& offline_pages() const {
+ return offline_pages_;
+ }
+
+ private:
+ OfflinePageItem last_saved_page_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ TestScenario scenario_;
+
+ std::vector<OfflinePageItem> offline_pages_;
+
+ DISALLOW_ASSIGN(OfflinePageTestStore);
+};
+
+} // namespace offline_pages
+
+#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_TEST_STORE_H_
« no previous file with comments | « components/offline_pages/offline_page_test_archiver.cc ('k') | components/offline_pages/offline_page_test_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698