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

Side by Side Diff: components/offline_pages/offline_page_storage_manager_unittest.cc

Issue 1947323002: [Offline Pages] Implement OfflinePageStorageManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing gyp builds. Created 4 years, 7 months 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_storage_manager.cc ('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 2016 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_storage_manager.h"
6
7 #include <stdint.h>
8
9 #include "base/bind.h"
10 #include "base/files/file_path.h"
11 #include "base/time/time.h"
12 #include "components/offline_pages/client_policy_controller.h"
13 #include "components/offline_pages/offline_page_item.h"
14 #include "components/offline_pages/offline_page_model.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult;
18
19 namespace offline_pages {
20
21 namespace {
22 const char kTestClientNamespace[] = "CLIENT_NAMESPACE";
23 const GURL kTestUrl("http://example.com");
24 const GURL kTestUrl2("http://other.page.com");
25 const base::FilePath kFilePath(std::string("TEST_FILEPATH");
fgorski 2016/05/09 20:20:38 you need to use a file path literal for this to wo
26 const ClientId kTestClientId1(kTestClientNamespace, "1234");
27 const ClientId kTestClientId2(kTestClientNamespace, "5678");
28 const int64_t kTestFileSize = 876543LL;
29 const int64_t kOfflineId = 1234LL;
30 const int64_t kOfflineId2 = 2345LL;
31 } // namespace
32
33 class OfflinePageTestModel : public OfflinePageModel {
34 public:
35 OfflinePageTestModel() : policy_controller_(new ClientPolicyController()) {
36 // Manually adding pages for the fake model.
37 // Only the first page is expired.
38 pages_.clear();
39 pages_.push_back(OfflinePageItem(kTestUrl, kOfflineId, kTestClientId1,
40 kFilePath, kTestFileSize));
41 pages_.push_back(OfflinePageItem(kTestUrl2, kOfflineId2, kTestClientId2,
42 kFilePath, kTestFileSize));
43 base::Time now = base::Time::Now();
44 pages_[0].last_access_time = now - base::TimeDelta::FromDays(10);
45 pages_[1].last_access_time = now;
46 }
47
48 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override {
49 callback.Run(pages_);
50 }
51
52 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
53 const DeletePageCallback& callback) override {
54 callback.Run(DeletePageResult::SUCCESS);
55 }
56
57 ClientPolicyController* GetPolicyController() override {
58 return policy_controller_.get();
59 }
60
61 bool is_loaded() const override { return true; }
62
63 private:
64 std::vector<OfflinePageItem> pages_;
65
66 std::unique_ptr<ClientPolicyController> policy_controller_;
67 };
68
69 class OfflinePageStorageManagerTest : public testing::Test {
70 public:
71 OfflinePageStorageManagerTest();
72 OfflinePageStorageManager* manager() { return manager_.get(); }
73 void OnPagesCleared(int pages_cleared_count, DeletePageResult result);
74
75 // testing::Test
76 void SetUp() override;
77 void TearDown() override;
78
79 int last_cleared_page_count() const { return last_cleared_page_count_; }
80 DeletePageResult last_delete_page_result() const {
81 return last_delete_page_result_;
82 }
83
84 private:
85 std::unique_ptr<OfflinePageStorageManager> manager_;
86 std::unique_ptr<OfflinePageModel> model_;
87
88 int last_cleared_page_count_;
89 DeletePageResult last_delete_page_result_;
90 };
91
92 OfflinePageStorageManagerTest::OfflinePageStorageManagerTest()
93 : last_cleared_page_count_(0),
94 last_delete_page_result_(DeletePageResult::SUCCESS) {}
95
96 void OfflinePageStorageManagerTest::SetUp() {
97 model_.reset(new OfflinePageTestModel());
98 manager_.reset(new OfflinePageStorageManager(model_.get()));
99 }
100
101 void OfflinePageStorageManagerTest::TearDown() {
102 manager_.reset();
103 model_.reset();
104 }
105
106 void OfflinePageStorageManagerTest::OnPagesCleared(int pages_cleared_count,
107 DeletePageResult result) {
108 last_cleared_page_count_ = pages_cleared_count;
109 last_delete_page_result_ = result;
110 }
111
112 TEST_F(OfflinePageStorageManagerTest, TestClearPages) {
113 manager()->ClearPagesIfNeeded(base::Bind(
114 &OfflinePageStorageManagerTest::OnPagesCleared, base::Unretained(this)));
115 EXPECT_EQ(1, last_cleared_page_count());
116 EXPECT_EQ(DeletePageResult::SUCCESS, last_delete_page_result());
117 }
118
119 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_storage_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698