OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/cros/mock_network_library.h" | 7 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using testing::Mock; | 12 using testing::Mock; |
13 using testing::Return; | 13 using testing::Return; |
14 using testing::_; | 14 using testing::_; |
15 | 15 |
16 namespace policy { | 16 namespace policy { |
17 | 17 |
18 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; | 18 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; |
19 | 19 |
20 class NetworkConfigurationUpdaterTest | 20 class NetworkConfigurationUpdaterTest |
21 : public testing::TestWithParam<ConfigurationPolicyType> { | 21 : public testing::TestWithParam<ConfigurationPolicyType> { |
22 protected: | 22 protected: |
| 23 virtual void SetUp() OVERRIDE { |
| 24 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _)) |
| 25 .WillRepeatedly(Return(true)); |
| 26 } |
| 27 |
| 28 // Maps configuration policy type to corresponding ONC source. |
| 29 static chromeos::NetworkUIData::ONCSource TypeToONCSource( |
| 30 ConfigurationPolicyType type) { |
| 31 switch (type) { |
| 32 case kPolicyDeviceOpenNetworkConfiguration: |
| 33 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY; |
| 34 case kPolicyOpenNetworkConfiguration: |
| 35 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY; |
| 36 default: |
| 37 return chromeos::NetworkUIData::ONC_SOURCE_NONE; |
| 38 } |
| 39 } |
| 40 |
23 chromeos::MockNetworkLibrary network_library_; | 41 chromeos::MockNetworkLibrary network_library_; |
24 MockConfigurationPolicyProvider provider_; | 42 MockConfigurationPolicyProvider provider_; |
25 }; | 43 }; |
26 | 44 |
27 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { | 45 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { |
28 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); | 46 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); |
29 | 47 |
30 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "", _, _)) | 48 EXPECT_CALL(network_library_, |
31 .WillRepeatedly(Return(true)); | 49 LoadOncNetworks(kFakeONC, "", TypeToONCSource(GetParam()), _)) |
| 50 .WillOnce(Return(true)); |
32 | 51 |
33 NetworkConfigurationUpdater updater(&provider_, &network_library_); | 52 NetworkConfigurationUpdater updater(&provider_, &network_library_); |
34 Mock::VerifyAndClearExpectations(&network_library_); | 53 Mock::VerifyAndClearExpectations(&network_library_); |
35 } | 54 } |
36 | 55 |
37 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { | 56 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { |
38 NetworkConfigurationUpdater updater(&provider_, &network_library_); | 57 NetworkConfigurationUpdater updater(&provider_, &network_library_); |
39 | 58 |
40 // We should update if policy changes. | 59 // We should update if policy changes. |
41 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "", _, _)) | 60 EXPECT_CALL(network_library_, |
| 61 LoadOncNetworks(kFakeONC, "", TypeToONCSource(GetParam()), _)) |
42 .WillOnce(Return(true)); | 62 .WillOnce(Return(true)); |
43 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); | 63 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); |
44 provider_.NotifyPolicyUpdated(); | 64 provider_.NotifyPolicyUpdated(); |
45 Mock::VerifyAndClearExpectations(&network_library_); | 65 Mock::VerifyAndClearExpectations(&network_library_); |
46 | 66 |
47 // No update if the set the same value again. | 67 // No update if the set the same value again. |
48 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "", _, _)) | 68 EXPECT_CALL(network_library_, |
| 69 LoadOncNetworks(kFakeONC, "", TypeToONCSource(GetParam()), _)) |
49 .Times(0); | 70 .Times(0); |
50 provider_.NotifyPolicyUpdated(); | 71 provider_.NotifyPolicyUpdated(); |
51 Mock::VerifyAndClearExpectations(&network_library_); | 72 Mock::VerifyAndClearExpectations(&network_library_); |
52 | 73 |
53 // Another update is expected if the policy goes away. | 74 // Another update is expected if the policy goes away. |
54 EXPECT_CALL(network_library_, LoadOncNetworks("", "", _, _)) | 75 EXPECT_CALL(network_library_, |
| 76 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration, |
| 77 "", TypeToONCSource(GetParam()), _)) |
55 .WillOnce(Return(true)); | 78 .WillOnce(Return(true)); |
56 provider_.RemovePolicy(GetParam()); | 79 provider_.RemovePolicy(GetParam()); |
57 provider_.NotifyPolicyUpdated(); | 80 provider_.NotifyPolicyUpdated(); |
58 Mock::VerifyAndClearExpectations(&network_library_); | 81 Mock::VerifyAndClearExpectations(&network_library_); |
59 } | 82 } |
60 | 83 |
61 INSTANTIATE_TEST_CASE_P( | 84 INSTANTIATE_TEST_CASE_P( |
62 NetworkConfigurationUpdaterTestInstance, | 85 NetworkConfigurationUpdaterTestInstance, |
63 NetworkConfigurationUpdaterTest, | 86 NetworkConfigurationUpdaterTest, |
64 testing::Values(kPolicyDeviceOpenNetworkConfiguration, | 87 testing::Values(kPolicyDeviceOpenNetworkConfiguration, |
65 kPolicyOpenNetworkConfiguration)); | 88 kPolicyOpenNetworkConfiguration)); |
66 | 89 |
67 } // namespace policy | 90 } // namespace policy |
OLD | NEW |