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

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

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: more rebase Created 4 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 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/client_policy_controller.h"
6
7 #include <algorithm>
8
9 #include "base/bind.h"
10 #include "base/time/time.h"
11 #include "components/offline_pages/client_namespace_constants.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
15
16 namespace offline_pages {
17
18 namespace {
19 const char kUndefinedNamespace[] = "undefined";
20
21 bool isTemporary(const OfflinePageClientPolicy& policy) {
22 return policy.lifetime_policy.lifetime_type == LifetimeType::TEMPORARY;
23 }
24 } // namespace
25
26 class ClientPolicyControllerTest : public testing::Test {
27 public:
28 ClientPolicyController* controller() { return controller_.get(); }
29
30 // testing::Test
31 void SetUp() override;
32 void TearDown() override;
33
34 protected:
35 void ExpectDownloadSupport(std::string name_space, bool expectation);
36 void ExpectRecentTab(std::string name_space, bool expectation);
37 void ExpectOnlyOriginalTab(std::string name_space, bool expectation);
38
39 private:
40 std::unique_ptr<ClientPolicyController> controller_;
41 };
42
43 void ClientPolicyControllerTest::SetUp() {
44 controller_.reset(new ClientPolicyController());
45 }
46
47 void ClientPolicyControllerTest::TearDown() {
48 controller_.reset();
49 }
50
51 void ClientPolicyControllerTest::ExpectDownloadSupport(std::string name_space,
52 bool expectation) {
53 std::vector<std::string> cache =
54 controller()->GetNamespacesSupportedByDownload();
55 auto result = std::find(cache.begin(), cache.end(), name_space);
56 EXPECT_EQ(expectation, result != cache.end());
57 EXPECT_EQ(expectation, controller()->IsSupportedByDownload(name_space));
58 }
59
60 void ClientPolicyControllerTest::ExpectRecentTab(std::string name_space,
61 bool expectation) {
62 std::vector<std::string> cache =
63 controller()->GetNamespacesShownAsRecentlyVisitedSite();
64 auto result = std::find(cache.begin(), cache.end(), name_space);
65 EXPECT_EQ(expectation, result != cache.end());
66 EXPECT_EQ(expectation,
67 controller()->IsShownAsRecentlyVisitedSite(name_space));
68 }
69
70 void ClientPolicyControllerTest::ExpectOnlyOriginalTab(std::string name_space,
71 bool expectation) {
72 std::vector<std::string> cache =
73 controller()->GetNamespacesRestrictedToOriginalTab();
74 auto result = std::find(cache.begin(), cache.end(), name_space);
75 EXPECT_EQ(expectation, result != cache.end());
76 EXPECT_EQ(expectation, controller()->IsRestrictedToOriginalTab(name_space));
77 }
78
79 TEST_F(ClientPolicyControllerTest, FallbackTest) {
80 OfflinePageClientPolicy policy = controller()->GetPolicy(kUndefinedNamespace);
81 EXPECT_EQ(policy.name_space, kDefaultNamespace);
82 EXPECT_TRUE(isTemporary(policy));
83 EXPECT_TRUE(controller()->IsRemovedOnCacheReset(kUndefinedNamespace));
84 ExpectDownloadSupport(kUndefinedNamespace, false);
85 ExpectRecentTab(kUndefinedNamespace, false);
86 ExpectOnlyOriginalTab(kUndefinedNamespace, false);
87 }
88
89 TEST_F(ClientPolicyControllerTest, CheckBookmarkDefined) {
90 OfflinePageClientPolicy policy = controller()->GetPolicy(kBookmarkNamespace);
91 EXPECT_EQ(policy.name_space, kBookmarkNamespace);
92 EXPECT_TRUE(isTemporary(policy));
93 EXPECT_TRUE(controller()->IsRemovedOnCacheReset(kBookmarkNamespace));
94 ExpectDownloadSupport(kBookmarkNamespace, false);
95 ExpectRecentTab(kBookmarkNamespace, false);
96 ExpectOnlyOriginalTab(kBookmarkNamespace, false);
97 }
98
99 TEST_F(ClientPolicyControllerTest, CheckLastNDefined) {
100 OfflinePageClientPolicy policy = controller()->GetPolicy(kLastNNamespace);
101 EXPECT_EQ(policy.name_space, kLastNNamespace);
102 EXPECT_TRUE(isTemporary(policy));
103 EXPECT_TRUE(controller()->IsRemovedOnCacheReset(kLastNNamespace));
104 ExpectDownloadSupport(kLastNNamespace, false);
105 ExpectRecentTab(kLastNNamespace, true);
106 ExpectOnlyOriginalTab(kLastNNamespace, true);
107 }
108
109 TEST_F(ClientPolicyControllerTest, CheckAsyncDefined) {
110 OfflinePageClientPolicy policy = controller()->GetPolicy(kAsyncNamespace);
111 EXPECT_EQ(policy.name_space, kAsyncNamespace);
112 EXPECT_FALSE(isTemporary(policy));
113 EXPECT_FALSE(controller()->IsRemovedOnCacheReset(kAsyncNamespace));
114 ExpectDownloadSupport(kAsyncNamespace, true);
115 ExpectRecentTab(kAsyncNamespace, false);
116 ExpectOnlyOriginalTab(kAsyncNamespace, false);
117 }
118
119 TEST_F(ClientPolicyControllerTest, CheckCCTDefined) {
120 OfflinePageClientPolicy policy = controller()->GetPolicy(kCCTNamespace);
121 EXPECT_EQ(policy.name_space, kCCTNamespace);
122 EXPECT_TRUE(isTemporary(policy));
123 EXPECT_TRUE(controller()->IsRemovedOnCacheReset(kCCTNamespace));
124 ExpectDownloadSupport(kCCTNamespace, false);
125 ExpectRecentTab(kCCTNamespace, false);
126 ExpectOnlyOriginalTab(kCCTNamespace, false);
127 }
128
129 TEST_F(ClientPolicyControllerTest, CheckDownloadDefined) {
130 OfflinePageClientPolicy policy = controller()->GetPolicy(kDownloadNamespace);
131 EXPECT_EQ(policy.name_space, kDownloadNamespace);
132 EXPECT_FALSE(isTemporary(policy));
133 EXPECT_FALSE(controller()->IsRemovedOnCacheReset(kDownloadNamespace));
134 ExpectDownloadSupport(kDownloadNamespace, true);
135 ExpectRecentTab(kDownloadNamespace, false);
136 ExpectOnlyOriginalTab(kDownloadNamespace, false);
137 }
138
139 TEST_F(ClientPolicyControllerTest, CheckNTPSuggestionsDefined) {
140 OfflinePageClientPolicy policy =
141 controller()->GetPolicy(kNTPSuggestionsNamespace);
142 EXPECT_EQ(policy.name_space, kNTPSuggestionsNamespace);
143 EXPECT_FALSE(isTemporary(policy));
144 EXPECT_TRUE(controller()->IsRemovedOnCacheReset(kNTPSuggestionsNamespace));
145 ExpectDownloadSupport(kNTPSuggestionsNamespace, true);
146 ExpectRecentTab(kNTPSuggestionsNamespace, false);
147 ExpectOnlyOriginalTab(kNTPSuggestionsNamespace, false);
148 }
149
150 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698