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

Side by Side Diff: chrome/browser/policy/configuration_policy_handler_unittest.cc

Issue 18153007: Add policies to control power management on the Chrome OS login screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit addressed. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/prefs/pref_value_map.h" 6 #include "base/prefs/pref_value_map.h"
7 #include "chrome/browser/extensions/external_policy_loader.h" 7 #include "chrome/browser/extensions/external_policy_loader.h"
8 #include "chrome/browser/policy/configuration_policy_handler.h" 8 #include "chrome/browser/policy/configuration_policy_handler.h"
9 #include "chrome/browser/policy/policy_error_map.h" 9 #include "chrome/browser/policy/policy_error_map.h"
10 #include "chrome/browser/policy/policy_map.h" 10 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace policy { 15 namespace policy {
16 16
17 namespace { 17 namespace {
18 18
19 StringToIntEnumListPolicyHandler::MappingEntry kTestTypeMap[] = { 19 StringToIntEnumListPolicyHandler::MappingEntry kTestTypeMap[] = {
20 { "one", 1 }, 20 { "one", 1 },
21 { "two", 2 }, 21 { "two", 2 },
22 }; 22 };
23 23
24 int kTestAllowedSet[] = { 0, 2 };
25
24 const char kTestPref[] = "unit_test.test_pref"; 26 const char kTestPref[] = "unit_test.test_pref";
25 27
26 } // namespace 28 } // namespace
27 29
28 TEST(StringToIntEnumListPolicyHandlerTest, CheckPolicySettings) { 30 TEST(StringToIntEnumListPolicyHandlerTest, CheckPolicySettings) {
29 base::ListValue list; 31 base::ListValue list;
30 PolicyMap policy_map; 32 PolicyMap policy_map;
31 PolicyErrorMap errors; 33 PolicyErrorMap errors;
32 StringToIntEnumListPolicyHandler handler( 34 StringToIntEnumListPolicyHandler handler(
33 key::kExtensionAllowedTypes, prefs::kExtensionAllowedTypes, 35 key::kExtensionAllowedTypes, prefs::kExtensionAllowedTypes,
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 473
472 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY, 474 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
473 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10)); 475 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10));
474 prefs.Clear(); 476 prefs.Clear();
475 handler.ApplyPolicySettings(policy_map, &prefs); 477 handler.ApplyPolicySettings(policy_map, &prefs);
476 expected.reset(base::Value::CreateDoubleValue(0.1)); 478 expected.reset(base::Value::CreateDoubleValue(0.1));
477 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 479 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
478 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); 480 EXPECT_TRUE(base::Value::Equals(expected.get(), value));
479 } 481 }
480 482
483 TEST(IntSetPolicyHandlerTest, CheckPolicySettings) {
484 PolicyMap policy_map;
485 PolicyErrorMap errors;
486
487 // This tests needs to modify an int policy. The exact policy used and its
488 // semantics outside the test are irrelevant.
489 IntSetPolicyHandler handler(
490 key::kDiskCacheSize, kTestPref,
491 kTestAllowedSet, kTestAllowedSet + arraysize(kTestAllowedSet));
492
493 // Check that values lying in the accepted set are not rejected.
494 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
495 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0));
496 errors.Clear();
497 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
498 EXPECT_TRUE(errors.empty());
499
500 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
501 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(2));
502 errors.Clear();
503 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
504 EXPECT_TRUE(errors.empty());
505
506 // Check that values not found in the accepted set are rejected and yield an
507 // error message.
508 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
509 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(1));
510 errors.Clear();
511 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
512 EXPECT_FALSE(errors.empty());
513
514 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
515 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(3));
516 errors.Clear();
517 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
518 EXPECT_FALSE(errors.empty());
519
520 // Check that an entirely invalid value is rejected and yields an error
521 // message.
522 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
523 POLICY_SCOPE_USER, base::Value::CreateStringValue("invalid"));
524 errors.Clear();
525 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
526 EXPECT_FALSE(errors.empty());
527 }
528
529 TEST(IntSetPolicyHandlerTest, ApplyPolicySettings) {
530 PolicyMap policy_map;
531 PrefValueMap prefs;
532 scoped_ptr<base::Value> expected;
533 const base::Value* value;
534
535 // This tests needs to modify an int policy. The exact policy used and its
536 // semantics outside the test are irrelevant.
537 IntSetPolicyHandler handler(
538 key::kDiskCacheSize, kTestPref,
539 kTestAllowedSet, kTestAllowedSet + arraysize(kTestAllowedSet));
540
541 // Check that values lying in the accepted set are written to the pref.
542 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
543 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0));
544 prefs.Clear();
545 handler.ApplyPolicySettings(policy_map, &prefs);
546 expected.reset(base::Value::CreateIntegerValue(0));
547 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
548 EXPECT_TRUE(base::Value::Equals(expected.get(), value));
549
550 policy_map.Set(key::kDiskCacheSize, POLICY_LEVEL_MANDATORY,
551 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(2));
552 prefs.Clear();
553 handler.ApplyPolicySettings(policy_map, &prefs);
554 expected.reset(base::Value::CreateIntegerValue(2));
555 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
556 EXPECT_TRUE(base::Value::Equals(expected.get(), value));
557 }
558
481 TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) { 559 TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) {
482 base::ListValue list; 560 base::ListValue list;
483 PolicyMap policy_map; 561 PolicyMap policy_map;
484 PolicyErrorMap errors; 562 PolicyErrorMap errors;
485 ExtensionListPolicyHandler handler(key::kExtensionInstallBlacklist, 563 ExtensionListPolicyHandler handler(key::kExtensionInstallBlacklist,
486 prefs::kExtensionInstallDenyList, 564 prefs::kExtensionInstallDenyList,
487 true); 565 true);
488 566
489 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 567 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
490 POLICY_SCOPE_USER, list.DeepCopy()); 568 POLICY_SCOPE_USER, list.DeepCopy());
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 758
681 list.Append(Value::CreateStringValue("https://corp.monkey.net/*")); 759 list.Append(Value::CreateStringValue("https://corp.monkey.net/*"));
682 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, 760 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
683 POLICY_SCOPE_USER, list.DeepCopy()); 761 POLICY_SCOPE_USER, list.DeepCopy());
684 handler.ApplyPolicySettings(policy_map, &prefs); 762 handler.ApplyPolicySettings(policy_map, &prefs);
685 ASSERT_TRUE(prefs.GetValue(prefs::kExtensionAllowedInstallSites, &value)); 763 ASSERT_TRUE(prefs.GetValue(prefs::kExtensionAllowedInstallSites, &value));
686 EXPECT_TRUE(base::Value::Equals(&list, value)); 764 EXPECT_TRUE(base::Value::Equals(&list, value));
687 } 765 }
688 766
689 } // namespace policy 767 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698