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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/offline_pages/offline_page_test_store.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "components/offline_pages/offline_page_test_store.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace offline_pages {
12
13 OfflinePageTestStore::OfflinePageTestStore(
14 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
15 : task_runner_(task_runner), scenario_(TestScenario::SUCCESSFUL) {}
16
17 OfflinePageTestStore::OfflinePageTestStore(
18 const OfflinePageTestStore& other_store)
19 : task_runner_(other_store.task_runner_),
20 scenario_(other_store.scenario_),
21 offline_pages_(other_store.offline_pages_) {}
22
23 OfflinePageTestStore::~OfflinePageTestStore() {}
24
25 void OfflinePageTestStore::Load(const LoadCallback& callback) {
26 OfflinePageMetadataStore::LoadStatus load_status;
27 if (scenario_ == TestScenario::LOAD_FAILED) {
28 load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED;
29 offline_pages_.clear();
30 } else {
31 load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED;
32 }
33 task_runner_->PostTask(FROM_HERE,
34 base::Bind(callback, load_status, offline_pages_));
35 }
36
37 void OfflinePageTestStore::AddOrUpdateOfflinePage(
38 const OfflinePageItem& offline_page,
39 const UpdateCallback& callback) {
40 last_saved_page_ = offline_page;
41 bool result = scenario_ != TestScenario::WRITE_FAILED;
42 if (result)
43 offline_pages_.push_back(offline_page);
44 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
45 }
46
47 void OfflinePageTestStore::RemoveOfflinePages(
48 const std::vector<int64>& bookmark_ids,
49 const UpdateCallback& callback) {
50 ASSERT_FALSE(bookmark_ids.empty());
51 bool result = false;
52 if (scenario_ != TestScenario::REMOVE_FAILED) {
53 for (auto iter = offline_pages_.begin(); iter != offline_pages_.end();
54 ++iter) {
55 if (iter->bookmark_id == bookmark_ids[0]) {
56 offline_pages_.erase(iter);
57 result = true;
58 break;
59 }
60 }
61 }
62
63 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
64 }
65
66 void OfflinePageTestStore::Reset(const ResetCallback& callback) {
67 offline_pages_.clear();
68 task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
69 }
70
71 void OfflinePageTestStore::UpdateLastAccessTime(
72 int64 bookmark_id,
73 const base::Time& last_access_time) {
74 for (auto& offline_page : offline_pages_) {
75 if (offline_page.bookmark_id == bookmark_id) {
76 offline_page.last_access_time = last_access_time;
77 return;
78 }
79 }
80 }
81
82 } // namespace offline_pages
OLDNEW
« 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