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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/offline_page_model_query_unittest.cc
diff --git a/components/offline_pages/offline_page_model_query_unittest.cc b/components/offline_pages/offline_page_model_query_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3a7b5c9aef9ded2de8fc9d22ba3a3edc3dab1b24
--- /dev/null
+++ b/components/offline_pages/offline_page_model_query_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2016 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_model_query.h"
+#include "components/offline_pages/client_policy_controller.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace offline_pages {
+
+class OfflinePageModelQueryTest : public testing::Test {
+ public:
+ OfflinePageModelQueryTest();
+ ~OfflinePageModelQueryTest() override;
+
+ protected:
+ ClientPolicyController policy_;
+ OfflinePageModelQueryBuilder builder_;
+};
+
+OfflinePageModelQueryTest::OfflinePageModelQueryTest() : builder_(&policy_) {}
+
+OfflinePageModelQueryTest::~OfflinePageModelQueryTest() {}
+
+TEST_F(OfflinePageModelQueryTest, DefaultValues) {
+ std::unique_ptr<OfflinePageModelQuery> query = builder_.Build();
+
+ ASSERT_NE(nullptr, query.get());
+ ASSERT_FALSE(query->GetAllowExpired());
+ ASSERT_FALSE(query->GetRestrictedToOfflineIds(nullptr));
+ ASSERT_FALSE(query->GetRestrictedToNamespaces(nullptr));
+}
+
+TEST_F(OfflinePageModelQueryTest, OfflinePageIdsSet) {
+ std::vector<int64_t> ids = {1, 4, 9, 16};
+ builder_.SetOfflinePageIds(ids);
+
+ std::unique_ptr<OfflinePageModelQuery> query = builder_.Build();
+ std::set<int64_t> ids_out;
+ ASSERT_TRUE(query->GetRestrictedToOfflineIds(&ids_out));
+
+ ASSERT_EQ(ids.size(), ids_out.size());
+ for (auto id : ids) {
+ ASSERT_EQ(1U, ids_out.count(id)) << "Did not find " << id
+ << "in query restrictions.";
+ }
+}
+
+TEST_F(OfflinePageModelQueryTest, OfflinePageIdsIntersect) {
+ std::vector<int64_t> ids = {1, 4, 9, 16};
+ std::vector<int64_t> ids2 = {1, 2, 3, 4};
+
+ builder_.SetOfflinePageIds(ids);
+ builder_.SetOfflinePageIds(ids2);
+
+ std::vector<int64_t> expected = {1, 4};
+
+ std::unique_ptr<OfflinePageModelQuery> query = builder_.Build();
+ std::set<int64_t> ids_out;
+ ASSERT_TRUE(query->GetRestrictedToOfflineIds(&ids_out));
+
+ ASSERT_EQ(expected.size(), ids_out.size());
+ for (auto id : expected) {
+ ASSERT_EQ(1U, ids_out.count(id)) << "Did not find " << id
+ << "in query restrictions.";
+ }
+}
+
+TEST_F(OfflinePageModelQueryTest, FooTest) {}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698