Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: chrome/browser/policy/network_configuration_updater_unittest.cc

Issue 10386097: Refactored ConfigurationPolicyProvider to provide PolicyBundles instead of PolicyMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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 "chrome/browser/policy/policy_map.h" 9 #include "chrome/browser/policy/policy_map.h"
10 #include "policy/policy_constants.h" 10 #include "policy/policy_constants.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using testing::Mock; 14 using testing::Mock;
15 using testing::Return; 15 using testing::Return;
16 using testing::_; 16 using testing::_;
17 17
18 namespace policy { 18 namespace policy {
19 19
20 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; 20 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
21 21
22 class NetworkConfigurationUpdaterTest 22 class NetworkConfigurationUpdaterTest
23 : public testing::TestWithParam<const char*> { 23 : public testing::TestWithParam<const char*> {
24 protected: 24 protected:
25 virtual void SetUp() OVERRIDE { 25 virtual void SetUp() OVERRIDE {
26 EXPECT_CALL(provider_, ProvideInternal(_))
27 .WillRepeatedly(CopyPolicyMap(&policy_));
28 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _)) 26 EXPECT_CALL(network_library_, LoadOncNetworks(_, "", _, _))
29 .WillRepeatedly(Return(true)); 27 .WillRepeatedly(Return(true));
30 } 28 }
31 29
32 // Maps configuration policy name to corresponding ONC source. 30 // Maps configuration policy name to corresponding ONC source.
33 static chromeos::NetworkUIData::ONCSource NameToONCSource( 31 static chromeos::NetworkUIData::ONCSource NameToONCSource(
34 const std::string& name) { 32 const std::string& name) {
35 if (name == key::kDeviceOpenNetworkConfiguration) 33 if (name == key::kDeviceOpenNetworkConfiguration)
36 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY; 34 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY;
37 if (name == key::kOpenNetworkConfiguration) 35 if (name == key::kOpenNetworkConfiguration)
38 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY; 36 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY;
39 return chromeos::NetworkUIData::ONC_SOURCE_NONE; 37 return chromeos::NetworkUIData::ONC_SOURCE_NONE;
40 } 38 }
41 39
42 chromeos::MockNetworkLibrary network_library_; 40 chromeos::MockNetworkLibrary network_library_;
43 PolicyMap policy_;
44 MockConfigurationPolicyProvider provider_; 41 MockConfigurationPolicyProvider provider_;
45 }; 42 };
46 43
47 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) { 44 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdate) {
48 policy_.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 45 PolicyMap policy;
49 Value::CreateStringValue(kFakeONC)); 46 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
47 Value::CreateStringValue(kFakeONC));
48 provider_.UpdateChromePolicy(policy);
50 49
51 EXPECT_CALL(network_library_, 50 EXPECT_CALL(network_library_,
52 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 51 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
53 .WillOnce(Return(true)); 52 .WillOnce(Return(true));
54 53
55 NetworkConfigurationUpdater updater(&provider_, &network_library_); 54 NetworkConfigurationUpdater updater(&provider_, &network_library_);
56 Mock::VerifyAndClearExpectations(&network_library_); 55 Mock::VerifyAndClearExpectations(&network_library_);
57 } 56 }
58 57
59 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 58 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
60 NetworkConfigurationUpdater updater(&provider_, &network_library_); 59 NetworkConfigurationUpdater updater(&provider_, &network_library_);
61 60
62 // We should update if policy changes. 61 // We should update if policy changes.
63 EXPECT_CALL(network_library_, 62 EXPECT_CALL(network_library_,
64 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 63 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
65 .WillOnce(Return(true)); 64 .WillOnce(Return(true));
66 policy_.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 65 PolicyMap policy;
67 Value::CreateStringValue(kFakeONC)); 66 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
68 provider_.NotifyPolicyUpdated(); 67 Value::CreateStringValue(kFakeONC));
68 provider_.UpdateChromePolicy(policy);
69 Mock::VerifyAndClearExpectations(&network_library_); 69 Mock::VerifyAndClearExpectations(&network_library_);
70 70
71 // No update if the set the same value again. 71 // No update if the set the same value again.
72 EXPECT_CALL(network_library_, 72 EXPECT_CALL(network_library_,
73 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _)) 73 LoadOncNetworks(kFakeONC, "", NameToONCSource(GetParam()), _))
74 .Times(0); 74 .Times(0);
75 provider_.NotifyPolicyUpdated(); 75 provider_.UpdateChromePolicy(policy);
76 Mock::VerifyAndClearExpectations(&network_library_); 76 Mock::VerifyAndClearExpectations(&network_library_);
77 77
78 // Another update is expected if the policy goes away. 78 // Another update is expected if the policy goes away.
79 EXPECT_CALL(network_library_, 79 EXPECT_CALL(network_library_,
80 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration, 80 LoadOncNetworks(NetworkConfigurationUpdater::kEmptyConfiguration,
81 "", NameToONCSource(GetParam()), _)) 81 "", NameToONCSource(GetParam()), _))
82 .WillOnce(Return(true)); 82 .WillOnce(Return(true));
83 policy_.Erase(GetParam()); 83 policy.Erase(GetParam());
84 provider_.NotifyPolicyUpdated(); 84 provider_.UpdateChromePolicy(policy);
85 Mock::VerifyAndClearExpectations(&network_library_); 85 Mock::VerifyAndClearExpectations(&network_library_);
86 } 86 }
87 87
88 INSTANTIATE_TEST_CASE_P( 88 INSTANTIATE_TEST_CASE_P(
89 NetworkConfigurationUpdaterTestInstance, 89 NetworkConfigurationUpdaterTestInstance,
90 NetworkConfigurationUpdaterTest, 90 NetworkConfigurationUpdaterTest,
91 testing::Values(key::kDeviceOpenNetworkConfiguration, 91 testing::Values(key::kDeviceOpenNetworkConfiguration,
92 key::kOpenNetworkConfiguration)); 92 key::kOpenNetworkConfiguration));
93 93
94 } // namespace policy 94 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/mock_configuration_policy_provider.cc ('k') | chrome/browser/policy/policy_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698