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