OLD | NEW |
---|---|
(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 "base/bind.h" | |
8 #include "base/time/time.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; | |
12 | |
13 namespace offline_pages { | |
14 | |
15 namespace { | |
16 const char kBookmarkNamespace[] = "bookmark"; | |
17 const char kLastNNamespace[] = "last_n"; | |
18 const char kUndefinedNamespace[] = "undefined"; | |
19 const OfflinePageClientPolicy kExpectedBookmarkPolicy = { | |
fgorski
2016/05/03 04:43:07
not used.
romax
2016/05/03 17:42:21
Acknowledged.
| |
20 "bookmark", | |
21 {LifetimeType::TEMPORARY, base::TimeDelta::FromDays(7), kUnlimitedPages}}; | |
22 | |
23 bool isTemporary(const OfflinePageClientPolicy& policy) { | |
24 // Check if policy has a expire period > 0 or a limited number | |
25 // of pages allowed. | |
26 return (policy.lifetime_policy.page_limit > kUnlimitedPages || | |
27 !policy.lifetime_policy.expiration_period.is_zero()); | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 class ClientPolicyControllerTest : public testing::Test { | |
33 public: | |
34 ClientPolicyControllerTest(); | |
35 ~ClientPolicyControllerTest() override; | |
36 | |
37 ClientPolicyController* controller() { return controller_.get(); } | |
38 | |
39 // testing::Test | |
40 void SetUp() override; | |
41 void TearDown() override; | |
42 | |
43 private: | |
44 std::unique_ptr<ClientPolicyController> controller_; | |
45 }; | |
46 | |
47 ClientPolicyControllerTest::ClientPolicyControllerTest() {} | |
fgorski
2016/05/03 04:43:07
I think you can skip this and definition.
romax
2016/05/03 17:42:21
Acknowledged.
| |
48 | |
49 ClientPolicyControllerTest::~ClientPolicyControllerTest() {} | |
50 | |
51 void ClientPolicyControllerTest::SetUp() { | |
52 controller_.reset(new ClientPolicyController()); | |
53 } | |
54 | |
55 void ClientPolicyControllerTest::TearDown() { | |
fgorski
2016/05/03 04:43:07
do you really need this?
romax
2016/05/03 17:42:21
i dont think it's necessary but good to have.
| |
56 controller_.reset(); | |
57 } | |
58 | |
59 TEST_F(ClientPolicyControllerTest, FallbackTest) { | |
60 OfflinePageClientPolicy policy = controller()->GetPolicy(kUndefinedNamespace); | |
61 EXPECT_EQ(policy.name_space, kDefaultNamespace); | |
62 EXPECT_TRUE(isTemporary(policy)); | |
63 } | |
64 | |
65 TEST_F(ClientPolicyControllerTest, GetPredefinedPolicy) { | |
66 OfflinePageClientPolicy policy = controller()->GetPolicy(kBookmarkNamespace); | |
67 EXPECT_EQ(policy.name_space, "bookmark"); | |
fgorski
2016/05/03 04:43:07
nit: kBookmark...
romax
2016/05/03 17:42:21
Done.
| |
68 EXPECT_TRUE(isTemporary(policy)); | |
69 } | |
70 | |
71 TEST_F(ClientPolicyControllerTest, CheckLastNDefined) { | |
72 OfflinePageClientPolicy policy = controller()->GetPolicy(kLastNNamespace); | |
73 EXPECT_EQ(policy.name_space, "last_n"); | |
fgorski
2016/05/03 04:43:07
nit: kLastN...
romax
2016/05/03 17:42:21
Done.
| |
74 EXPECT_TRUE(isTemporary(policy)); | |
75 } | |
76 | |
77 } // namespace offline_pages | |
OLD | NEW |