Chromium Code Reviews| Index: components/offline_pages/client_policy_controller_unittest.cc |
| diff --git a/components/offline_pages/client_policy_controller_unittest.cc b/components/offline_pages/client_policy_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1d60d248acabf685e3736eac299e288d8d9896f2 |
| --- /dev/null |
| +++ b/components/offline_pages/client_policy_controller_unittest.cc |
| @@ -0,0 +1,77 @@ |
| +// 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/client_policy_controller.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/time/time.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; |
| + |
| +namespace offline_pages { |
| + |
| +namespace { |
| +const char kBookmarkNamespace[] = "bookmark"; |
| +const char kLastNNamespace[] = "last_n"; |
| +const char kUndefinedNamespace[] = "undefined"; |
| +const OfflinePageClientPolicy kExpectedBookmarkPolicy = { |
|
fgorski
2016/05/03 04:43:07
not used.
romax
2016/05/03 17:42:21
Acknowledged.
|
| + "bookmark", |
| + {LifetimeType::TEMPORARY, base::TimeDelta::FromDays(7), kUnlimitedPages}}; |
| + |
| +bool isTemporary(const OfflinePageClientPolicy& policy) { |
| + // Check if policy has a expire period > 0 or a limited number |
| + // of pages allowed. |
| + return (policy.lifetime_policy.page_limit > kUnlimitedPages || |
| + !policy.lifetime_policy.expiration_period.is_zero()); |
| +} |
| + |
| +} // namespace |
| + |
| +class ClientPolicyControllerTest : public testing::Test { |
| + public: |
| + ClientPolicyControllerTest(); |
| + ~ClientPolicyControllerTest() override; |
| + |
| + ClientPolicyController* controller() { return controller_.get(); } |
| + |
| + // testing::Test |
| + void SetUp() override; |
| + void TearDown() override; |
| + |
| + private: |
| + std::unique_ptr<ClientPolicyController> controller_; |
| +}; |
| + |
| +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.
|
| + |
| +ClientPolicyControllerTest::~ClientPolicyControllerTest() {} |
| + |
| +void ClientPolicyControllerTest::SetUp() { |
| + controller_.reset(new ClientPolicyController()); |
| +} |
| + |
| +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.
|
| + controller_.reset(); |
| +} |
| + |
| +TEST_F(ClientPolicyControllerTest, FallbackTest) { |
| + OfflinePageClientPolicy policy = controller()->GetPolicy(kUndefinedNamespace); |
| + EXPECT_EQ(policy.name_space, kDefaultNamespace); |
| + EXPECT_TRUE(isTemporary(policy)); |
| +} |
| + |
| +TEST_F(ClientPolicyControllerTest, GetPredefinedPolicy) { |
| + OfflinePageClientPolicy policy = controller()->GetPolicy(kBookmarkNamespace); |
| + EXPECT_EQ(policy.name_space, "bookmark"); |
|
fgorski
2016/05/03 04:43:07
nit: kBookmark...
romax
2016/05/03 17:42:21
Done.
|
| + EXPECT_TRUE(isTemporary(policy)); |
| +} |
| + |
| +TEST_F(ClientPolicyControllerTest, CheckLastNDefined) { |
| + OfflinePageClientPolicy policy = controller()->GetPolicy(kLastNNamespace); |
| + EXPECT_EQ(policy.name_space, "last_n"); |
|
fgorski
2016/05/03 04:43:07
nit: kLastN...
romax
2016/05/03 17:42:21
Done.
|
| + EXPECT_TRUE(isTemporary(policy)); |
| +} |
| + |
| +} // namespace offline_pages |