| OLD | NEW |
| 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 "chrome/browser/policy/network_configuration_updater.h" | 5 #include "chrome/browser/policy/network_configuration_updater.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 8 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
| 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 10 #include "chrome/browser/policy/policy_map.h" | 10 #include "chrome/browser/policy/policy_map.h" |
| 11 #include "chrome/browser/policy/policy_service_impl.h" | 11 #include "chrome/browser/policy/policy_service_impl.h" |
| 12 #include "chromeos/network/onc/onc_constants.h" | 12 #include "chromeos/network/onc/onc_constants.h" |
| 13 #include "chromeos/network/onc/onc_utils.h" |
| 13 #include "policy/policy_constants.h" | 14 #include "policy/policy_constants.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using testing::AtLeast; | 18 using testing::AtLeast; |
| 18 using testing::Mock; | 19 using testing::Mock; |
| 19 using testing::Ne; | 20 using testing::Ne; |
| 20 using testing::Return; | 21 using testing::Return; |
| 21 using testing::_; | 22 using testing::_; |
| 22 | 23 |
| 23 namespace policy { | 24 namespace policy { |
| 24 | 25 |
| 25 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; | 26 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; |
| 26 static const char* kEmptyConfiguration = | |
| 27 NetworkConfigurationUpdater::kEmptyConfiguration; | |
| 28 | 27 |
| 29 class NetworkConfigurationUpdaterTest | 28 class NetworkConfigurationUpdaterTest |
| 30 : public testing::TestWithParam<const char*>{ | 29 : public testing::TestWithParam<const char*>{ |
| 31 protected: | 30 protected: |
| 32 virtual void SetUp() OVERRIDE { | 31 virtual void SetUp() OVERRIDE { |
| 33 EXPECT_CALL(provider_, IsInitializationComplete()) | 32 EXPECT_CALL(provider_, IsInitializationComplete()) |
| 34 .WillRepeatedly(Return(true)); | 33 .WillRepeatedly(Return(true)); |
| 35 provider_.Init(); | 34 provider_.Init(); |
| 36 PolicyServiceImpl::Providers providers; | 35 PolicyServiceImpl::Providers providers; |
| 37 providers.push_back(&provider_); | 36 providers.push_back(&provider_); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 PolicyMap policy; | 60 PolicyMap policy; |
| 62 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 61 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 63 Value::CreateStringValue(kFakeONC)); | 62 Value::CreateStringValue(kFakeONC)); |
| 64 provider_.UpdateChromePolicy(policy); | 63 provider_.UpdateChromePolicy(policy); |
| 65 | 64 |
| 66 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); | 65 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); |
| 67 | 66 |
| 68 // Initially, only the device policy is applied. The user policy is only | 67 // Initially, only the device policy is applied. The user policy is only |
| 69 // applied after the user profile was initialized. | 68 // applied after the user profile was initialized. |
| 70 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? | 69 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? |
| 71 kFakeONC : kEmptyConfiguration; | 70 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration; |
| 72 EXPECT_CALL(network_library_, LoadOncNetworks( | 71 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 73 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); | 72 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); |
| 74 | 73 |
| 75 { | 74 { |
| 76 NetworkConfigurationUpdater updater(policy_service_.get(), | 75 NetworkConfigurationUpdater updater(policy_service_.get(), |
| 77 &network_library_); | 76 &network_library_); |
| 78 Mock::VerifyAndClearExpectations(&network_library_); | 77 Mock::VerifyAndClearExpectations(&network_library_); |
| 79 | 78 |
| 80 // After the user policy is initialized, we always push both policies to the | 79 // After the user policy is initialized, we always push both policies to the |
| 81 // NetworkLibrary. | 80 // NetworkLibrary. |
| 82 EXPECT_CALL(network_library_, LoadOncNetworks( | 81 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 83 kFakeONC, "", NameToONCSource(GetParam()), _)); | 82 kFakeONC, "", NameToONCSource(GetParam()), _)); |
| 84 EXPECT_CALL(network_library_, LoadOncNetworks( | 83 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 85 kEmptyConfiguration, "", Ne(NameToONCSource(GetParam())), _)); | 84 chromeos::onc::kEmptyUnencryptedConfiguration, |
| 85 "", |
| 86 Ne(NameToONCSource(GetParam())), |
| 87 _)); |
| 86 | 88 |
| 87 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 89 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
| 88 | 90 |
| 89 updater.OnUserPolicyInitialized(); | 91 updater.OnUserPolicyInitialized(); |
| 90 } | 92 } |
| 91 Mock::VerifyAndClearExpectations(&network_library_); | 93 Mock::VerifyAndClearExpectations(&network_library_); |
| 92 } | 94 } |
| 93 | 95 |
| 94 TEST_P(NetworkConfigurationUpdaterTest, AllowWebTrust) { | 96 TEST_P(NetworkConfigurationUpdaterTest, AllowWebTrust) { |
| 95 { | 97 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 &network_library_); | 133 &network_library_); |
| 132 updater.OnUserPolicyInitialized(); | 134 updater.OnUserPolicyInitialized(); |
| 133 Mock::VerifyAndClearExpectations(&network_library_); | 135 Mock::VerifyAndClearExpectations(&network_library_); |
| 134 | 136 |
| 135 // We should update if policy changes. | 137 // We should update if policy changes. |
| 136 EXPECT_CALL(network_library_, LoadOncNetworks( | 138 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 137 kFakeONC, "", NameToONCSource(GetParam()), _)); | 139 kFakeONC, "", NameToONCSource(GetParam()), _)); |
| 138 | 140 |
| 139 // In the current implementation, we always apply both policies. | 141 // In the current implementation, we always apply both policies. |
| 140 EXPECT_CALL(network_library_, LoadOncNetworks( | 142 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 141 kEmptyConfiguration, "", Ne(NameToONCSource(GetParam())), _)); | 143 chromeos::onc::kEmptyUnencryptedConfiguration, |
| 144 "", |
| 145 Ne(NameToONCSource(GetParam())), |
| 146 _)); |
| 142 | 147 |
| 143 PolicyMap policy; | 148 PolicyMap policy; |
| 144 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 149 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 145 Value::CreateStringValue(kFakeONC)); | 150 Value::CreateStringValue(kFakeONC)); |
| 146 provider_.UpdateChromePolicy(policy); | 151 provider_.UpdateChromePolicy(policy); |
| 147 Mock::VerifyAndClearExpectations(&network_library_); | 152 Mock::VerifyAndClearExpectations(&network_library_); |
| 148 | 153 |
| 149 // Another update is expected if the policy goes away. In the current | 154 // Another update is expected if the policy goes away. In the current |
| 150 // implementation, we always apply both policies. | 155 // implementation, we always apply both policies. |
| 151 EXPECT_CALL(network_library_, LoadOncNetworks( | 156 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 152 kEmptyConfiguration, "", | 157 chromeos::onc::kEmptyUnencryptedConfiguration, "", |
| 153 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); | 158 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); |
| 154 | 159 |
| 155 EXPECT_CALL(network_library_, LoadOncNetworks( | 160 EXPECT_CALL(network_library_, LoadOncNetworks( |
| 156 kEmptyConfiguration, "", | 161 chromeos::onc::kEmptyUnencryptedConfiguration, "", |
| 157 chromeos::onc::ONC_SOURCE_USER_POLICY, _)); | 162 chromeos::onc::ONC_SOURCE_USER_POLICY, _)); |
| 158 | 163 |
| 159 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); | 164 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); |
| 160 | 165 |
| 161 policy.Erase(GetParam()); | 166 policy.Erase(GetParam()); |
| 162 provider_.UpdateChromePolicy(policy); | 167 provider_.UpdateChromePolicy(policy); |
| 163 } | 168 } |
| 164 Mock::VerifyAndClearExpectations(&network_library_); | 169 Mock::VerifyAndClearExpectations(&network_library_); |
| 165 } | 170 } |
| 166 | 171 |
| 167 INSTANTIATE_TEST_CASE_P( | 172 INSTANTIATE_TEST_CASE_P( |
| 168 NetworkConfigurationUpdaterTestInstance, | 173 NetworkConfigurationUpdaterTestInstance, |
| 169 NetworkConfigurationUpdaterTest, | 174 NetworkConfigurationUpdaterTest, |
| 170 testing::Values(key::kDeviceOpenNetworkConfiguration, | 175 testing::Values(key::kDeviceOpenNetworkConfiguration, |
| 171 key::kOpenNetworkConfiguration)); | 176 key::kOpenNetworkConfiguration)); |
| 172 | 177 |
| 173 } // namespace policy | 178 } // namespace policy |
| OLD | NEW |