| 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
|
|
|