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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
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..6bd4faeffd7578b22c51d354fddf595140fd5eb1
--- /dev/null
+++ b/components/offline_pages/client_policy_controller_unittest.cc
@@ -0,0 +1,67 @@
+// 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";
+
+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:
+ ClientPolicyController* controller() { return controller_.get(); }
+
+ // testing::Test
+ void SetUp() override;
+ void TearDown() override;
+
+ private:
+ std::unique_ptr<ClientPolicyController> controller_;
+};
+
+void ClientPolicyControllerTest::SetUp() {
+ controller_.reset(new ClientPolicyController());
+}
+
+void ClientPolicyControllerTest::TearDown() {
+ controller_.reset();
+}
+
+TEST_F(ClientPolicyControllerTest, FallbackTest) {
+ OfflinePageClientPolicy policy = controller()->GetPolicy(kUndefinedNamespace);
+ EXPECT_EQ(policy.name_space, kDefaultNamespace);
+ EXPECT_TRUE(isTemporary(policy));
+}
+
+TEST_F(ClientPolicyControllerTest, CheckBookmarkDefined) {
+ OfflinePageClientPolicy policy = controller()->GetPolicy(kBookmarkNamespace);
+ EXPECT_EQ(policy.name_space, kBookmarkNamespace);
+ EXPECT_TRUE(isTemporary(policy));
+}
+
+TEST_F(ClientPolicyControllerTest, CheckLastNDefined) {
+ OfflinePageClientPolicy policy = controller()->GetPolicy(kLastNNamespace);
+ EXPECT_EQ(policy.name_space, kLastNNamespace);
+ EXPECT_TRUE(isTemporary(policy));
+}
+
+} // namespace offline_pages
« 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