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

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

Issue 11667006: Create a list of policy changes before notifying observers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 7 years, 11 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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h"
9 #include "base/run_loop.h"
8 #include "chrome/browser/chromeos/cros/mock_network_library.h" 10 #include "chrome/browser/chromeos/cros/mock_network_library.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 11 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
10 #include "chrome/browser/policy/policy_map.h" 12 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/browser/policy/policy_service_impl.h" 13 #include "chrome/browser/policy/policy_service_impl.h"
12 #include "chromeos/network/onc/onc_constants.h" 14 #include "chromeos/network/onc/onc_constants.h"
13 #include "chromeos/network/onc/onc_utils.h" 15 #include "chromeos/network/onc/onc_utils.h"
14 #include "policy/policy_constants.h" 16 #include "policy/policy_constants.h"
15 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 using testing::AtLeast; 20 using testing::AtLeast;
19 using testing::Mock; 21 using testing::Mock;
20 using testing::Ne; 22 using testing::Ne;
21 using testing::Return; 23 using testing::Return;
22 using testing::_; 24 using testing::_;
23 25
24 namespace policy { 26 namespace policy {
25 27
26 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; 28 static const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
27 29
28 class NetworkConfigurationUpdaterTest 30 class NetworkConfigurationUpdaterTest
29 : public testing::TestWithParam<const char*>{ 31 : public testing::TestWithParam<const char*>{
32 public:
33 NetworkConfigurationUpdaterTest() : loop_(MessageLoop::TYPE_UI) {}
30 protected: 34 protected:
31 virtual void SetUp() OVERRIDE { 35 virtual void SetUp() OVERRIDE {
32 EXPECT_CALL(provider_, IsInitializationComplete()) 36 EXPECT_CALL(provider_, IsInitializationComplete())
33 .WillRepeatedly(Return(true)); 37 .WillRepeatedly(Return(true));
34 provider_.Init(); 38 provider_.Init();
35 PolicyServiceImpl::Providers providers; 39 PolicyServiceImpl::Providers providers;
36 providers.push_back(&provider_); 40 providers.push_back(&provider_);
37 policy_service_.reset(new PolicyServiceImpl(providers)); 41 policy_service_.reset(new PolicyServiceImpl(providers));
38 } 42 }
39 43
40 virtual void TearDown() OVERRIDE { 44 virtual void TearDown() OVERRIDE {
41 provider_.Shutdown(); 45 provider_.Shutdown();
42 } 46 }
43 47
48 void UpdateProviderPolicy(const PolicyMap& policy) {
49 provider_.UpdateChromePolicy(policy);
50 base::RunLoop loop;
51 loop.RunUntilIdle();
52 }
53
44 // Maps configuration policy name to corresponding ONC source. 54 // Maps configuration policy name to corresponding ONC source.
45 static chromeos::onc::ONCSource NameToONCSource( 55 static chromeos::onc::ONCSource NameToONCSource(
46 const std::string& name) { 56 const std::string& name) {
47 if (name == key::kDeviceOpenNetworkConfiguration) 57 if (name == key::kDeviceOpenNetworkConfiguration)
48 return chromeos::onc::ONC_SOURCE_DEVICE_POLICY; 58 return chromeos::onc::ONC_SOURCE_DEVICE_POLICY;
49 if (name == key::kOpenNetworkConfiguration) 59 if (name == key::kOpenNetworkConfiguration)
50 return chromeos::onc::ONC_SOURCE_USER_POLICY; 60 return chromeos::onc::ONC_SOURCE_USER_POLICY;
51 return chromeos::onc::ONC_SOURCE_NONE; 61 return chromeos::onc::ONC_SOURCE_NONE;
52 } 62 }
53 63
54 chromeos::MockNetworkLibrary network_library_; 64 chromeos::MockNetworkLibrary network_library_;
55 MockConfigurationPolicyProvider provider_; 65 MockConfigurationPolicyProvider provider_;
56 scoped_ptr<PolicyServiceImpl> policy_service_; 66 scoped_ptr<PolicyServiceImpl> policy_service_;
67 MessageLoop loop_;
57 }; 68 };
58 69
59 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) { 70 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) {
60 PolicyMap policy; 71 PolicyMap policy;
61 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 72 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
62 Value::CreateStringValue(kFakeONC)); 73 Value::CreateStringValue(kFakeONC));
63 provider_.UpdateChromePolicy(policy); 74 UpdateProviderPolicy(policy);
64 75
65 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 76 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
66 77
67 // Initially, only the device policy is applied. The user policy is only 78 // Initially, only the device policy is applied. The user policy is only
68 // applied after the user profile was initialized. 79 // applied after the user profile was initialized.
69 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? 80 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ?
70 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration; 81 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration;
71 EXPECT_CALL(network_library_, LoadOncNetworks( 82 EXPECT_CALL(network_library_, LoadOncNetworks(
72 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); 83 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _));
73 84
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 118
108 // Web trust should be forwarded to LoadOncNetworks. 119 // Web trust should be forwarded to LoadOncNetworks.
109 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, true)) 120 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, true))
110 .Times(AtLeast(0)); 121 .Times(AtLeast(0));
111 122
112 updater.set_allow_web_trust(true); 123 updater.set_allow_web_trust(true);
113 124
114 PolicyMap policy; 125 PolicyMap policy;
115 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 126 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
116 Value::CreateStringValue(kFakeONC)); 127 Value::CreateStringValue(kFakeONC));
117 provider_.UpdateChromePolicy(policy); 128 UpdateProviderPolicy(policy);
118 Mock::VerifyAndClearExpectations(&network_library_); 129 Mock::VerifyAndClearExpectations(&network_library_);
119 130
120 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 131 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
121 } 132 }
122 Mock::VerifyAndClearExpectations(&network_library_); 133 Mock::VerifyAndClearExpectations(&network_library_);
123 } 134 }
124 135
125 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 136 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
126 { 137 {
127 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 138 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
(...skipping 13 matching lines...) Expand all
141 // In the current implementation, we always apply both policies. 152 // In the current implementation, we always apply both policies.
142 EXPECT_CALL(network_library_, LoadOncNetworks( 153 EXPECT_CALL(network_library_, LoadOncNetworks(
143 chromeos::onc::kEmptyUnencryptedConfiguration, 154 chromeos::onc::kEmptyUnencryptedConfiguration,
144 "", 155 "",
145 Ne(NameToONCSource(GetParam())), 156 Ne(NameToONCSource(GetParam())),
146 _)); 157 _));
147 158
148 PolicyMap policy; 159 PolicyMap policy;
149 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 160 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
150 Value::CreateStringValue(kFakeONC)); 161 Value::CreateStringValue(kFakeONC));
151 provider_.UpdateChromePolicy(policy); 162 UpdateProviderPolicy(policy);
152 Mock::VerifyAndClearExpectations(&network_library_); 163 Mock::VerifyAndClearExpectations(&network_library_);
153 164
154 // Another update is expected if the policy goes away. In the current 165 // Another update is expected if the policy goes away. In the current
155 // implementation, we always apply both policies. 166 // implementation, we always apply both policies.
156 EXPECT_CALL(network_library_, LoadOncNetworks( 167 EXPECT_CALL(network_library_, LoadOncNetworks(
157 chromeos::onc::kEmptyUnencryptedConfiguration, "", 168 chromeos::onc::kEmptyUnencryptedConfiguration, "",
158 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); 169 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _));
159 170
160 EXPECT_CALL(network_library_, LoadOncNetworks( 171 EXPECT_CALL(network_library_, LoadOncNetworks(
161 chromeos::onc::kEmptyUnencryptedConfiguration, "", 172 chromeos::onc::kEmptyUnencryptedConfiguration, "",
162 chromeos::onc::ONC_SOURCE_USER_POLICY, _)); 173 chromeos::onc::ONC_SOURCE_USER_POLICY, _));
163 174
164 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 175 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
165 176
166 policy.Erase(GetParam()); 177 policy.Erase(GetParam());
167 provider_.UpdateChromePolicy(policy); 178 UpdateProviderPolicy(policy);
168 } 179 }
169 Mock::VerifyAndClearExpectations(&network_library_); 180 Mock::VerifyAndClearExpectations(&network_library_);
170 } 181 }
171 182
172 INSTANTIATE_TEST_CASE_P( 183 INSTANTIATE_TEST_CASE_P(
173 NetworkConfigurationUpdaterTestInstance, 184 NetworkConfigurationUpdaterTestInstance,
174 NetworkConfigurationUpdaterTest, 185 NetworkConfigurationUpdaterTest,
175 testing::Values(key::kDeviceOpenNetworkConfiguration, 186 testing::Values(key::kDeviceOpenNetworkConfiguration,
176 key::kOpenNetworkConfiguration)); 187 key::kOpenNetworkConfiguration));
177 188
178 } // namespace policy 189 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698