1 // Copyright (c) 2011 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 "chrome/browser/policy/policy_map.h" 6 7 #include "base/memory/scoped_ptr.h" 8 #include "policy/configuration_policy_type.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace policy { 12 13 TEST(PolicyMapTest, SetAndGet) { 14 PolicyMap map; 15 map.Set(kPolicyHomepageLocation, Value::CreateStringValue("aaa")); 16 StringValue expected("aaa"); 17 EXPECT_TRUE(expected.Equals(map.Get(kPolicyHomepageLocation))); 18 map.Set(kPolicyHomepageLocation, Value::CreateStringValue("bbb")); 19 StringValue expected_b("bbb"); 20 EXPECT_TRUE(expected_b.Equals(map.Get(kPolicyHomepageLocation))); 21 } 22 23 TEST(PolicyMapTest, Equals) { 24 PolicyMap a; 25 a.Set(kPolicyHomepageLocation, Value::CreateStringValue("aaa")); 26 PolicyMap a2; 27 a2.Set(kPolicyHomepageLocation, Value::CreateStringValue("aaa")); 28 PolicyMap b; 29 b.Set(kPolicyHomepageLocation, Value::CreateStringValue("bbb")); 30 PolicyMap c; 31 c.Set(kPolicyHomepageLocation, Value::CreateStringValue("aaa")); 32 c.Set(kPolicyHomepageIsNewTabPage, Value::CreateBooleanValue(true)); 33 EXPECT_FALSE(a.Equals(b)); 34 EXPECT_FALSE(b.Equals(a)); 35 EXPECT_FALSE(a.Equals(c)); 36 EXPECT_FALSE(c.Equals(a)); 37 EXPECT_TRUE(a.Equals(a2)); 38 EXPECT_TRUE(a2.Equals(a)); 39 PolicyMap empty1; 40 PolicyMap empty2; 41 EXPECT_TRUE(empty1.Equals(empty2)); 42 EXPECT_TRUE(empty2.Equals(empty1)); 43 EXPECT_FALSE(empty1.Equals(a)); 44 EXPECT_FALSE(a.Equals(empty1)); 45 } 46 47 TEST(PolicyMapTest, Swap) { 48 PolicyMap a; 49 a.Set(kPolicyHomepageLocation, Value::CreateStringValue("aaa")); 50 PolicyMap b; 51 b.Set(kPolicyHomepageLocation, Value::CreateStringValue("bbb")); 52 b.Set(kPolicyHomepageIsNewTabPage, Value::CreateBooleanValue(true)); 53 a.Swap(&b); 54 StringValue expected("bbb"); 55 EXPECT_TRUE(expected.Equals(a.Get(kPolicyHomepageLocation))); 56 FundamentalValue expected_bool(true); 57 EXPECT_TRUE(expected_bool.Equals(a.Get(kPolicyHomepageIsNewTabPage))); 58 StringValue expected_a("aaa"); 59 EXPECT_TRUE(expected_a.Equals(b.Get(kPolicyHomepageLocation))); 60 61 b.Clear(); 62 a.Swap(&b); 63 PolicyMap empty; 64 EXPECT_TRUE(a.Equals(empty)); 65 EXPECT_FALSE(b.Equals(empty)); 66 } 67 68 } // namespace policy 69