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

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: 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
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) {
jianli 2015/12/07 23:19:01 suggest to flip the if test for easier understandi
fgorski 2015/12/08 00:33:56 Done.
28 load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED;
29 } else {
30 load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED;
31 offline_pages_.clear();
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) {
jianli 2015/12/07 23:19:01 nit: brackets not needed
fgorski 2015/12/08 00:33:56 Done.
43 offline_pages_.push_back(offline_page);
44 }
45 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
46 }
47
48 void OfflinePageTestStore::RemoveOfflinePages(
49 const std::vector<int64>& bookmark_ids,
50 const UpdateCallback& callback) {
51 ASSERT_FALSE(bookmark_ids.empty());
52 bool result = false;
53 if (scenario_ != TestScenario::REMOVE_FAILED) {
54 for (auto iter = offline_pages_.begin(); iter != offline_pages_.end();
55 ++iter) {
56 if (iter->bookmark_id == bookmark_ids[0]) {
57 offline_pages_.erase(iter);
58 result = true;
59 break;
60 }
61 }
62 }
63
64 task_runner_->PostTask(FROM_HERE, base::Bind(callback, result));
65 }
66
67 void OfflinePageTestStore::Reset(const ResetCallback& callback) {
68 offline_pages_.clear();
69 task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
70 }
71
72 void OfflinePageTestStore::UpdateLastAccessTime(
73 int64 bookmark_id,
74 const base::Time& last_access_time) {
75 for (auto& offline_page : offline_pages_) {
76 if (offline_page.bookmark_id == bookmark_id) {
77 offline_page.last_access_time = last_access_time;
78 return;
79 }
80 }
81 }
82
83 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698