| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/time/time.h" | 5 #include "base/time/time.h" |
| 6 #include "components/offline_pages/client_namespace_constants.h" | 6 #include "components/offline_pages/client_namespace_constants.h" |
| 7 #include "components/offline_pages/client_policy_controller.h" | 7 #include "components/offline_pages/client_policy_controller.h" |
| 8 #include "components/offline_pages/offline_page_client_policy.h" | 8 #include "components/offline_pages/offline_page_client_policy.h" |
| 9 #include "components/offline_pages/offline_page_item.h" | 9 #include "components/offline_pages/offline_page_item.h" |
| 10 #include "components/offline_pages/offline_page_model_query.h" | 10 #include "components/offline_pages/offline_page_model_query.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 class OfflinePageModelQueryTest : public testing::Test { | 31 class OfflinePageModelQueryTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 OfflinePageModelQueryTest(); | 33 OfflinePageModelQueryTest(); |
| 34 ~OfflinePageModelQueryTest() override; | 34 ~OfflinePageModelQueryTest() override; |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 ClientPolicyController policy_; | 37 ClientPolicyController policy_; |
| 38 OfflinePageModelQueryBuilder builder_; | 38 OfflinePageModelQueryBuilder builder_; |
| 39 | 39 |
| 40 const OfflinePageItem expired_page() { | |
| 41 OfflinePageItem expiredTestItem(GURL("https://ktestitem1.com"), 3, | |
| 42 kClientId1, base::FilePath(), 3); | |
| 43 expiredTestItem.expiration_time = base::Time::Now(); | |
| 44 | |
| 45 return expiredTestItem; | |
| 46 } | |
| 47 | |
| 48 const OfflinePageItem download_page() { | 40 const OfflinePageItem download_page() { |
| 49 return OfflinePageItem(GURL("https://download.com"), 4, | 41 return OfflinePageItem(GURL("https://download.com"), 4, |
| 50 {kDownloadNamespace, "id1"}, base::FilePath(), 4); | 42 {kDownloadNamespace, "id1"}, base::FilePath(), 4); |
| 51 } | 43 } |
| 52 | 44 |
| 53 const OfflinePageItem original_tab_page() { | 45 const OfflinePageItem original_tab_page() { |
| 54 return OfflinePageItem(GURL("https://download.com"), 5, | 46 return OfflinePageItem(GURL("https://download.com"), 5, |
| 55 {kLastNNamespace, "id1"}, base::FilePath(), 5); | 47 {kLastNNamespace, "id1"}, base::FilePath(), 5); |
| 56 } | 48 } |
| 57 | 49 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 74 kUnlimitedPages, kUnlimitedPages) | 66 kUnlimitedPages, kUnlimitedPages) |
| 75 .SetIsOnlyShownInOriginalTab(true)); | 67 .SetIsOnlyShownInOriginalTab(true)); |
| 76 } | 68 } |
| 77 | 69 |
| 78 OfflinePageModelQueryTest::~OfflinePageModelQueryTest() {} | 70 OfflinePageModelQueryTest::~OfflinePageModelQueryTest() {} |
| 79 | 71 |
| 80 TEST_F(OfflinePageModelQueryTest, DefaultValues) { | 72 TEST_F(OfflinePageModelQueryTest, DefaultValues) { |
| 81 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build(&policy_); | 73 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build(&policy_); |
| 82 | 74 |
| 83 EXPECT_NE(nullptr, query.get()); | 75 EXPECT_NE(nullptr, query.get()); |
| 84 EXPECT_FALSE(query->GetAllowExpired()); | |
| 85 EXPECT_EQ(Requirement::UNSET, query->GetRestrictedToOfflineIds().first); | 76 EXPECT_EQ(Requirement::UNSET, query->GetRestrictedToOfflineIds().first); |
| 86 EXPECT_FALSE(query->GetRestrictedToNamespaces().first); | 77 EXPECT_FALSE(query->GetRestrictedToNamespaces().first); |
| 87 | 78 |
| 88 EXPECT_TRUE(query->Matches(kTestItem1)); | 79 EXPECT_TRUE(query->Matches(kTestItem1)); |
| 89 EXPECT_TRUE(query->Matches(kTestItem2)); | 80 EXPECT_TRUE(query->Matches(kTestItem2)); |
| 90 EXPECT_FALSE(query->Matches(expired_page())); | |
| 91 } | 81 } |
| 92 | 82 |
| 93 TEST_F(OfflinePageModelQueryTest, OfflinePageIdsSet_Exclude) { | 83 TEST_F(OfflinePageModelQueryTest, OfflinePageIdsSet_Exclude) { |
| 94 std::vector<int64_t> ids = {1, 4, 9, 16}; | 84 std::vector<int64_t> ids = {1, 4, 9, 16}; |
| 95 builder_.SetOfflinePageIds(Requirement::EXCLUDE_MATCHING, ids); | 85 builder_.SetOfflinePageIds(Requirement::EXCLUDE_MATCHING, ids); |
| 96 | 86 |
| 97 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build(&policy_); | 87 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build(&policy_); |
| 98 std::pair<Requirement, std::set<int64_t>> offline_id_restriction = | 88 std::pair<Requirement, std::set<int64_t>> offline_id_restriction = |
| 99 query->GetRestrictedToOfflineIds(); | 89 query->GetRestrictedToOfflineIds(); |
| 100 EXPECT_EQ(Requirement::EXCLUDE_MATCHING, offline_id_restriction.first); | 90 EXPECT_EQ(Requirement::EXCLUDE_MATCHING, offline_id_restriction.first); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 ASSERT_EQ(urls2.size(), urls_out.size()); | 271 ASSERT_EQ(urls2.size(), urls_out.size()); |
| 282 for (auto url : urls2) { | 272 for (auto url : urls2) { |
| 283 EXPECT_EQ(1U, urls_out.count(url)) << "Did not find " << url | 273 EXPECT_EQ(1U, urls_out.count(url)) << "Did not find " << url |
| 284 << "in query restrictions."; | 274 << "in query restrictions."; |
| 285 } | 275 } |
| 286 | 276 |
| 287 EXPECT_FALSE(query->Matches(kTestItem1)); | 277 EXPECT_FALSE(query->Matches(kTestItem1)); |
| 288 EXPECT_TRUE(query->Matches(kTestItem2)); | 278 EXPECT_TRUE(query->Matches(kTestItem2)); |
| 289 } | 279 } |
| 290 | 280 |
| 291 TEST_F(OfflinePageModelQueryTest, AllowExpired) { | |
| 292 std::unique_ptr<OfflinePageModelQuery> query = | |
| 293 builder_.AllowExpiredPages(true).Build(&policy_); | |
| 294 | |
| 295 EXPECT_NE(nullptr, query.get()); | |
| 296 EXPECT_TRUE(query->GetAllowExpired()); | |
| 297 | |
| 298 EXPECT_TRUE(query->Matches(kTestItem1)); | |
| 299 EXPECT_TRUE(query->Matches(kTestItem2)); | |
| 300 EXPECT_TRUE(query->Matches(expired_page())); | |
| 301 } | |
| 302 | |
| 303 TEST_F(OfflinePageModelQueryTest, RequireSupportedByDownload_Only) { | 281 TEST_F(OfflinePageModelQueryTest, RequireSupportedByDownload_Only) { |
| 304 builder_.RequireSupportedByDownload(Requirement::INCLUDE_MATCHING); | 282 builder_.RequireSupportedByDownload(Requirement::INCLUDE_MATCHING); |
| 305 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build(&policy_); | 283 std::unique_ptr<OfflinePageModelQuery> query = builder_.Build(&policy_); |
| 306 | 284 |
| 307 auto restriction = query->GetRestrictedToNamespaces(); | 285 auto restriction = query->GetRestrictedToNamespaces(); |
| 308 std::set<std::string> namespaces_allowed = restriction.second; | 286 std::set<std::string> namespaces_allowed = restriction.second; |
| 309 bool restricted_to_namespaces = restriction.first; | 287 bool restricted_to_namespaces = restriction.first; |
| 310 EXPECT_TRUE(restricted_to_namespaces); | 288 EXPECT_TRUE(restricted_to_namespaces); |
| 311 | 289 |
| 312 for (const std::string& name_space : namespaces_allowed) { | 290 for (const std::string& name_space : namespaces_allowed) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 auto restriction = query->GetRestrictedToNamespaces(); | 390 auto restriction = query->GetRestrictedToNamespaces(); |
| 413 std::set<std::string> namespaces_allowed = restriction.second; | 391 std::set<std::string> namespaces_allowed = restriction.second; |
| 414 bool restricted_to_namespaces = restriction.first; | 392 bool restricted_to_namespaces = restriction.first; |
| 415 EXPECT_TRUE(restricted_to_namespaces); | 393 EXPECT_TRUE(restricted_to_namespaces); |
| 416 | 394 |
| 417 EXPECT_TRUE(namespaces_allowed.count(kTestNamespace) == 1); | 395 EXPECT_TRUE(namespaces_allowed.count(kTestNamespace) == 1); |
| 418 EXPECT_FALSE(query->Matches(recent_page())); | 396 EXPECT_FALSE(query->Matches(recent_page())); |
| 419 } | 397 } |
| 420 | 398 |
| 421 } // namespace offline_pages | 399 } // namespace offline_pages |
| OLD | NEW |