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 | 15 |
15 namespace policy { | 16 namespace policy { |
16 | 17 |
17 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; | 18 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; |
18 | 19 |
19 class NetworkConfigurationUpdaterTest | 20 class NetworkConfigurationUpdaterTest |
20 : public testing::TestWithParam<ConfigurationPolicyType> { | 21 : public testing::TestWithParam<ConfigurationPolicyType> { |
21 protected: | 22 protected: |
22 chromeos::MockNetworkLibrary network_library_; | 23 chromeos::MockNetworkLibrary network_library_; |
23 MockConfigurationPolicyProvider provider_; | 24 MockConfigurationPolicyProvider provider_; |
24 }; | 25 }; |
25 | 26 |
26 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { | 27 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { |
27 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); | 28 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); |
28 | 29 |
29 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "")) | 30 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "", _)) |
30 .WillRepeatedly(Return(true)); | 31 .WillRepeatedly(Return(true)); |
31 | 32 |
32 NetworkConfigurationUpdater updater(&provider_, &network_library_); | 33 NetworkConfigurationUpdater updater(&provider_, &network_library_); |
33 Mock::VerifyAndClearExpectations(&network_library_); | 34 Mock::VerifyAndClearExpectations(&network_library_); |
34 } | 35 } |
35 | 36 |
36 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { | 37 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { |
37 NetworkConfigurationUpdater updater(&provider_, &network_library_); | 38 NetworkConfigurationUpdater updater(&provider_, &network_library_); |
38 | 39 |
39 // We should update if policy changes. | 40 // We should update if policy changes. |
40 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "")) | 41 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "", _)) |
41 .WillOnce(Return(true)); | 42 .WillOnce(Return(true)); |
42 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); | 43 provider_.AddPolicy(GetParam(), Value::CreateStringValue(kFakeONC)); |
43 provider_.NotifyPolicyUpdated(); | 44 provider_.NotifyPolicyUpdated(); |
44 Mock::VerifyAndClearExpectations(&network_library_); | 45 Mock::VerifyAndClearExpectations(&network_library_); |
45 | 46 |
46 // No update if the set the same value again. | 47 // No update if the set the same value again. |
47 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "")) | 48 EXPECT_CALL(network_library_, LoadOncNetworks(kFakeONC, "", _)) |
48 .Times(0); | 49 .Times(0); |
49 provider_.NotifyPolicyUpdated(); | 50 provider_.NotifyPolicyUpdated(); |
50 Mock::VerifyAndClearExpectations(&network_library_); | 51 Mock::VerifyAndClearExpectations(&network_library_); |
51 | 52 |
52 // Another update is expected if the policy goes away. | 53 // Another update is expected if the policy goes away. |
53 EXPECT_CALL(network_library_, LoadOncNetworks("", "")) | 54 EXPECT_CALL(network_library_, LoadOncNetworks("", "", _)) |
54 .WillOnce(Return(true)); | 55 .WillOnce(Return(true)); |
55 provider_.RemovePolicy(GetParam()); | 56 provider_.RemovePolicy(GetParam()); |
56 provider_.NotifyPolicyUpdated(); | 57 provider_.NotifyPolicyUpdated(); |
57 Mock::VerifyAndClearExpectations(&network_library_); | 58 Mock::VerifyAndClearExpectations(&network_library_); |
58 } | 59 } |
59 | 60 |
60 INSTANTIATE_TEST_CASE_P( | 61 INSTANTIATE_TEST_CASE_P( |
61 NetworkConfigurationUpdaterTestInstance, | 62 NetworkConfigurationUpdaterTestInstance, |
62 NetworkConfigurationUpdaterTest, | 63 NetworkConfigurationUpdaterTest, |
63 testing::Values(kPolicyDeviceOpenNetworkConfiguration, | 64 testing::Values(kPolicyDeviceOpenNetworkConfiguration, |
64 kPolicyOpenNetworkConfiguration)); | 65 kPolicyOpenNetworkConfiguration)); |
65 | 66 |
66 } // namespace policy | 67 } // namespace policy |
OLD | NEW |