Home | History | Annotate | Download | only in policy
      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/configuration_policy_store_interface.h"
      6 #include "chrome/browser/policy/mock_configuration_policy_store.h"
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 using ::testing::_;
     10 
     11 namespace policy {
     12 
     13 TEST(ConfigurationPolicyStoreInterfaceTest, Observer) {
     14   MockConfigurationPolicyStore store;
     15   EXPECT_CALL(store, Apply(_, _)).Times(3);
     16   ObservingPolicyStoreInterface observer(&store);
     17 
     18   EXPECT_FALSE(observer.IsProxyPolicyApplied());
     19   observer.Apply(kPolicyJavascriptEnabled, Value::CreateBooleanValue(true));
     20   EXPECT_FALSE(observer.IsProxyPolicyApplied());
     21   observer.Apply(kPolicyProxyMode, Value::CreateStringValue("direct"));
     22   EXPECT_TRUE(observer.IsProxyPolicyApplied());
     23   observer.Apply(kPolicyIncognitoEnabled, Value::CreateBooleanValue(true));
     24   EXPECT_TRUE(observer.IsProxyPolicyApplied());
     25 
     26   EXPECT_TRUE(store.Get(kPolicyJavascriptEnabled) != NULL);
     27   EXPECT_TRUE(store.Get(kPolicyProxyMode) != NULL);
     28   EXPECT_TRUE(store.Get(kPolicyIncognitoEnabled) != NULL);
     29   EXPECT_TRUE(store.Get(kPolicyPrintingEnabled) == NULL);
     30 }
     31 
     32 TEST(ConfigurationPolicyStoreInterfaceTest, Filter) {
     33   MockConfigurationPolicyStore store_pass;
     34   EXPECT_CALL(store_pass, Apply(_, _)).Times(1);
     35   FilteringPolicyStoreInterface filter_pass(&store_pass, true);
     36 
     37   EXPECT_TRUE(store_pass.policy_map().empty());
     38   filter_pass.Apply(kPolicyJavascriptEnabled, Value::CreateBooleanValue(true));
     39   EXPECT_TRUE(store_pass.policy_map().empty());
     40   filter_pass.Apply(kPolicyProxyMode, Value::CreateStringValue("direct"));
     41   EXPECT_FALSE(store_pass.policy_map().empty());
     42   EXPECT_EQ(store_pass.policy_map().size(), 1u);
     43   EXPECT_TRUE(store_pass.Get(kPolicyJavascriptEnabled) == NULL);
     44   EXPECT_TRUE(store_pass.Get(kPolicyProxyMode) != NULL);
     45 
     46   MockConfigurationPolicyStore store_block;
     47   EXPECT_CALL(store_block, Apply(_, _)).Times(0);
     48   FilteringPolicyStoreInterface filter_block(&store_block, false);
     49 
     50   EXPECT_TRUE(store_block.policy_map().empty());
     51   filter_block.Apply(kPolicyJavascriptEnabled, Value::CreateBooleanValue(true));
     52   EXPECT_TRUE(store_block.policy_map().empty());
     53   filter_block.Apply(kPolicyProxyMode, Value::CreateStringValue("direct"));
     54   EXPECT_TRUE(store_block.policy_map().empty());
     55 }
     56 
     57 }  // namespace policy
     58