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

Unified Diff: components/offline_pages/offline_page_test_store.cc

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
« no previous file with comments | « components/offline_pages/offline_page_test_store.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/offline_page_test_store.cc
diff --git a/components/offline_pages/offline_page_test_store.cc b/components/offline_pages/offline_page_test_store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3a5b256e1fa97f5f0f338e2769107c0769913142
--- /dev/null
+++ b/components/offline_pages/offline_page_test_store.cc
@@ -0,0 +1,82 @@
+// 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.
+
+#include "components/offline_pages/offline_page_test_store.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace offline_pages {
+
+OfflinePageTestStore::OfflinePageTestStore(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
+ : task_runner_(task_runner), scenario_(TestScenario::SUCCESSFUL) {}
+
+OfflinePageTestStore::OfflinePageTestStore(
+ const OfflinePageTestStore& other_store)
+ : task_runner_(other_store.task_runner_),
+ scenario_(other_store.scenario_),
+ offline_pages_(other_store.offline_pages_) {}
+
+OfflinePageTestStore::~OfflinePageTestStore() {}
+
+void OfflinePageTestStore::Load(const LoadCallback& callback) {
+ OfflinePageMetadataStore::LoadStatus load_status;
+ if (scenario_ == TestScenario::LOAD_FAILED) {
+ load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED;
+ offline_pages_.clear();
+ } else {
+ load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED;
+ }
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(callback, load_status, offline_pages_));
+}
+
+void OfflinePageTestStore::AddOrUpdateOfflinePage(
+ const OfflinePageItem& offline_page,
+ const UpdateCallback& callback) {
+ last_saved_page_ = offline_page;
+ bool result = scenario_ != TestScenario::WRITE_FAILED;
+ if (result)
+ offline_pages_.push_back(offline_page);
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
+}
+
+void OfflinePageTestStore::RemoveOfflinePages(
+ const std::vector<int64>& bookmark_ids,
+ const UpdateCallback& callback) {
+ ASSERT_FALSE(bookmark_ids.empty());
+ bool result = false;
+ if (scenario_ != TestScenario::REMOVE_FAILED) {
+ for (auto iter = offline_pages_.begin(); iter != offline_pages_.end();
+ ++iter) {
+ if (iter->bookmark_id == bookmark_ids[0]) {
+ offline_pages_.erase(iter);
+ result = true;
+ break;
+ }
+ }
+ }
+
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
+}
+
+void OfflinePageTestStore::Reset(const ResetCallback& callback) {
+ offline_pages_.clear();
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
+}
+
+void OfflinePageTestStore::UpdateLastAccessTime(
+ int64 bookmark_id,
+ const base::Time& last_access_time) {
+ for (auto& offline_page : offline_pages_) {
+ if (offline_page.bookmark_id == bookmark_id) {
+ offline_page.last_access_time = last_access_time;
+ return;
+ }
+ }
+}
+
+} // namespace offline_pages
« no previous file with comments | « components/offline_pages/offline_page_test_store.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698