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

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

Issue 2415473003: Query API: Introduces an OfflinePageModelQuery object. (Closed)
Patch Set: Stop making a new client policy controller, have a dangling pointer. Created 4 years, 2 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
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_model_query.h"
6 #include "components/offline_pages/client_policy_controller.h"
7
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace offline_pages {
11
12 class OfflinePageModelQueryTest : public testing::Test {
13 public:
14 OfflinePageModelQueryTest();
15 ~OfflinePageModelQueryTest() override;
16
17 protected:
18 ClientPolicyController policy_;
19 OfflinePageModelQueryBuilder builder_;
20 };
21
22 OfflinePageModelQueryTest::OfflinePageModelQueryTest() : builder_(&policy_) {}
23
24 OfflinePageModelQueryTest::~OfflinePageModelQueryTest() {}
25
26 TEST_F(OfflinePageModelQueryTest, DefaultValues) {
27 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build();
28
29 ASSERT_NE(nullptr, query.get());
30 ASSERT_FALSE(query->GetAllowExpired());
31 ASSERT_FALSE(query->GetRestrictedToOfflineIds(nullptr));
32 ASSERT_FALSE(query->GetRestrictedToNamespaces(nullptr));
33 }
34
35 TEST_F(OfflinePageModelQueryTest, OfflinePageIdsSet) {
36 std::vector<int64_t> ids = {1, 4, 9, 16};
37 builder_.SetOfflinePageIds(ids);
38
39 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build();
40 std::set<int64_t> ids_out;
41 ASSERT_TRUE(query->GetRestrictedToOfflineIds(&ids_out));
42
43 ASSERT_EQ(ids.size(), ids_out.size());
44 for (auto id : ids) {
45 ASSERT_EQ(1U, ids_out.count(id)) << "Did not find " << id
46 << "in query restrictions.";
47 }
48 }
49
50 TEST_F(OfflinePageModelQueryTest, OfflinePageIdsIntersect) {
51 std::vector<int64_t> ids = {1, 4, 9, 16};
52 std::vector<int64_t> ids2 = {1, 2, 3, 4};
53
54 builder_.SetOfflinePageIds(ids);
55 builder_.SetOfflinePageIds(ids2);
56
57 std::vector<int64_t> expected = {1, 4};
58
59 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build();
60 std::set<int64_t> ids_out;
61 ASSERT_TRUE(query->GetRestrictedToOfflineIds(&ids_out));
62
63 ASSERT_EQ(expected.size(), ids_out.size());
64 for (auto id : expected) {
65 ASSERT_EQ(1U, ids_out.count(id)) << "Did not find " << id
66 << "in query restrictions.";
67 }
68 }
69
70 TEST_F(OfflinePageModelQueryTest, FooTest) {}
71
72 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698