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

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

Issue 1934743003: Implementing client policy and controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 7 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 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 "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
20 bool isTemporary(const OfflinePageClientPolicy& policy) {
21 // Check if policy has a expire period > 0 or a limited number
22 // of pages allowed.
23 return (policy.lifetime_policy.page_limit > kUnlimitedPages ||
24 !policy.lifetime_policy.expiration_period.is_zero());
25 }
26
27 } // namespace
28
29 class ClientPolicyControllerTest : public testing::Test {
30 public:
31 ClientPolicyController* controller() { return controller_.get(); }
32
33 // testing::Test
34 void SetUp() override;
35 void TearDown() override;
36
37 private:
38 std::unique_ptr<ClientPolicyController> controller_;
39 };
40
41 void ClientPolicyControllerTest::SetUp() {
42 controller_.reset(new ClientPolicyController());
43 }
44
45 void ClientPolicyControllerTest::TearDown() {
46 controller_.reset();
47 }
48
49 TEST_F(ClientPolicyControllerTest, FallbackTest) {
50 OfflinePageClientPolicy policy = controller()->GetPolicy(kUndefinedNamespace);
51 EXPECT_EQ(policy.name_space, kDefaultNamespace);
52 EXPECT_TRUE(isTemporary(policy));
53 }
54
55 TEST_F(ClientPolicyControllerTest, CheckBookmarkDefined) {
56 OfflinePageClientPolicy policy = controller()->GetPolicy(kBookmarkNamespace);
57 EXPECT_EQ(policy.name_space, kBookmarkNamespace);
58 EXPECT_TRUE(isTemporary(policy));
59 }
60
61 TEST_F(ClientPolicyControllerTest, CheckLastNDefined) {
62 OfflinePageClientPolicy policy = controller()->GetPolicy(kLastNNamespace);
63 EXPECT_EQ(policy.name_space, kLastNNamespace);
64 EXPECT_TRUE(isTemporary(policy));
65 }
66
67 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/client_policy_controller.cc ('k') | components/offline_pages/offline_page_client_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698