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/profile_policy_connector.h"
      6 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
      7 #include "chrome/browser/policy/mock_configuration_policy_store.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 using ::testing::_;
     11 
     12 namespace policy {
     13 
     14 TEST(MergingPolicyProviderTest, MergeProxySettings) {
     15   MockConfigurationPolicyProvider browser_provider;
     16   MockConfigurationPolicyProvider profile_provider;
     17   MergingPolicyProvider merging_provider(&browser_provider, &profile_provider);
     18 
     19   // First, test settings from profile and no proxy settings from browser.
     20   // Only the profile policies should be forwarded.
     21   browser_provider.AddPolicy(kPolicyJavascriptEnabled,
     22                              Value::CreateBooleanValue(true));
     23   profile_provider.AddPolicy(kPolicyPrintingEnabled,
     24                              Value::CreateBooleanValue(true));
     25 
     26   MockConfigurationPolicyStore store0;
     27   EXPECT_CALL(store0, Apply(_, _)).Times(1);
     28   EXPECT_TRUE(merging_provider.Provide(&store0));
     29   EXPECT_EQ(store0.policy_map().size(), 1u);
     30   EXPECT_TRUE(store0.Get(kPolicyPrintingEnabled) != NULL);
     31 
     32   // Now have a proxy policy that should be merged.
     33   browser_provider.AddPolicy(kPolicyProxyMode,
     34                              Value::CreateStringValue("direct"));
     35 
     36   MockConfigurationPolicyStore store1;
     37   EXPECT_CALL(store1, Apply(_, _)).Times(2);
     38   EXPECT_TRUE(merging_provider.Provide(&store1));
     39   EXPECT_EQ(store1.policy_map().size(), 2u);
     40   EXPECT_TRUE(store1.Get(kPolicyPrintingEnabled) != NULL);
     41   EXPECT_TRUE(store1.Get(kPolicyProxyMode) != NULL);
     42 
     43   // If the profile includes any proxy policy, no proxy policies should be
     44   // merged from the browser provider.
     45   profile_provider.AddPolicy(kPolicyProxyServer,
     46                              Value::CreateStringValue("http://proxy:8080"));
     47 
     48   MockConfigurationPolicyStore store2;
     49   EXPECT_CALL(store2, Apply(_, _)).Times(2);
     50   EXPECT_TRUE(merging_provider.Provide(&store2));
     51   EXPECT_EQ(store2.policy_map().size(), 2u);
     52   EXPECT_TRUE(store2.Get(kPolicyPrintingEnabled) != NULL);
     53   EXPECT_TRUE(store2.Get(kPolicyProxyServer) != NULL);
     54   EXPECT_TRUE(store2.Get(kPolicyProxyMode) == NULL);
     55 }
     56 
     57 }  // namespace policy
     58