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

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

Issue 11299236: This moves the ONC parsing code into chromeos/network/onc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove translated strings Created 8 years 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 "chrome/browser/chromeos/cros/mock_network_library.h" 8 #include "chrome/browser/chromeos/cros/mock_network_library.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 9 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
10 #include "chrome/browser/policy/policy_map.h" 10 #include "chrome/browser/policy/policy_map.h"
11 #include "chrome/browser/policy/policy_service_impl.h" 11 #include "chrome/browser/policy/policy_service_impl.h"
12 #include "chromeos/network/onc/onc_constants.h"
12 #include "policy/policy_constants.h" 13 #include "policy/policy_constants.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 using testing::AtLeast; 17 using testing::AtLeast;
17 using testing::Mock; 18 using testing::Mock;
18 using testing::Ne; 19 using testing::Ne;
19 using testing::Return; 20 using testing::Return;
20 using testing::_; 21 using testing::_;
21 22
(...skipping 13 matching lines...) Expand all
35 PolicyServiceImpl::Providers providers; 36 PolicyServiceImpl::Providers providers;
36 providers.push_back(&provider_); 37 providers.push_back(&provider_);
37 policy_service_.reset(new PolicyServiceImpl(providers)); 38 policy_service_.reset(new PolicyServiceImpl(providers));
38 } 39 }
39 40
40 virtual void TearDown() OVERRIDE { 41 virtual void TearDown() OVERRIDE {
41 provider_.Shutdown(); 42 provider_.Shutdown();
42 } 43 }
43 44
44 // Maps configuration policy name to corresponding ONC source. 45 // Maps configuration policy name to corresponding ONC source.
45 static chromeos::NetworkUIData::ONCSource NameToONCSource( 46 static chromeos::onc::ONCSource NameToONCSource(
46 const std::string& name) { 47 const std::string& name) {
47 if (name == key::kDeviceOpenNetworkConfiguration) 48 if (name == key::kDeviceOpenNetworkConfiguration)
48 return chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY; 49 return chromeos::onc::ONC_SOURCE_DEVICE_POLICY;
49 if (name == key::kOpenNetworkConfiguration) 50 if (name == key::kOpenNetworkConfiguration)
50 return chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY; 51 return chromeos::onc::ONC_SOURCE_USER_POLICY;
51 return chromeos::NetworkUIData::ONC_SOURCE_NONE; 52 return chromeos::onc::ONC_SOURCE_NONE;
52 } 53 }
53 54
54 chromeos::MockNetworkLibrary network_library_; 55 chromeos::MockNetworkLibrary network_library_;
55 MockConfigurationPolicyProvider provider_; 56 MockConfigurationPolicyProvider provider_;
56 scoped_ptr<PolicyServiceImpl> policy_service_; 57 scoped_ptr<PolicyServiceImpl> policy_service_;
57 }; 58 };
58 59
59 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) { 60 TEST_P(NetworkConfigurationUpdaterTest, InitialUpdates) {
60 PolicyMap policy; 61 PolicyMap policy;
61 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 62 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
62 Value::CreateStringValue(kFakeONC)); 63 Value::CreateStringValue(kFakeONC));
63 provider_.UpdateChromePolicy(policy); 64 provider_.UpdateChromePolicy(policy);
64 65
65 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 66 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
66 67
67 // Initially, only the device policy is applied. The user policy is only 68 // Initially, only the device policy is applied. The user policy is only
68 // applied after the user profile was initialized. 69 // applied after the user profile was initialized.
69 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? 70 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ?
70 kFakeONC : kEmptyConfiguration; 71 kFakeONC : kEmptyConfiguration;
71 EXPECT_CALL(network_library_, LoadOncNetworks( 72 EXPECT_CALL(network_library_, LoadOncNetworks(
72 device_onc, "", chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, _, _)); 73 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _, _));
73 74
74 { 75 {
75 NetworkConfigurationUpdater updater(policy_service_.get(), 76 NetworkConfigurationUpdater updater(policy_service_.get(),
76 &network_library_); 77 &network_library_);
77 Mock::VerifyAndClearExpectations(&network_library_); 78 Mock::VerifyAndClearExpectations(&network_library_);
78 79
79 // After the user policy is initialized, we always push both policies to the 80 // After the user policy is initialized, we always push both policies to the
80 // NetworkLibrary. 81 // NetworkLibrary.
81 EXPECT_CALL(network_library_, LoadOncNetworks( 82 EXPECT_CALL(network_library_, LoadOncNetworks(
82 kFakeONC, "", NameToONCSource(GetParam()), _, _)); 83 kFakeONC, "", NameToONCSource(GetParam()), _, _));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 PolicyMap policy; 143 PolicyMap policy;
143 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 144 policy.Set(GetParam(), POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
144 Value::CreateStringValue(kFakeONC)); 145 Value::CreateStringValue(kFakeONC));
145 provider_.UpdateChromePolicy(policy); 146 provider_.UpdateChromePolicy(policy);
146 Mock::VerifyAndClearExpectations(&network_library_); 147 Mock::VerifyAndClearExpectations(&network_library_);
147 148
148 // Another update is expected if the policy goes away. In the current 149 // Another update is expected if the policy goes away. In the current
149 // implementation, we always apply both policies. 150 // implementation, we always apply both policies.
150 EXPECT_CALL(network_library_, LoadOncNetworks( 151 EXPECT_CALL(network_library_, LoadOncNetworks(
151 kEmptyConfiguration, "", 152 kEmptyConfiguration, "",
152 chromeos::NetworkUIData::ONC_SOURCE_DEVICE_POLICY, _, _)); 153 chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _, _));
153 154
154 EXPECT_CALL(network_library_, LoadOncNetworks( 155 EXPECT_CALL(network_library_, LoadOncNetworks(
155 kEmptyConfiguration, "", 156 kEmptyConfiguration, "",
156 chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY, _, _)); 157 chromeos::onc::ONC_SOURCE_USER_POLICY, _, _));
157 158
158 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_)); 159 EXPECT_CALL(network_library_, RemoveNetworkProfileObserver(_));
159 160
160 policy.Erase(GetParam()); 161 policy.Erase(GetParam());
161 provider_.UpdateChromePolicy(policy); 162 provider_.UpdateChromePolicy(policy);
162 } 163 }
163 Mock::VerifyAndClearExpectations(&network_library_); 164 Mock::VerifyAndClearExpectations(&network_library_);
164 } 165 }
165 166
166 INSTANTIATE_TEST_CASE_P( 167 INSTANTIATE_TEST_CASE_P(
167 NetworkConfigurationUpdaterTestInstance, 168 NetworkConfigurationUpdaterTestInstance,
168 NetworkConfigurationUpdaterTest, 169 NetworkConfigurationUpdaterTest,
169 testing::Values(key::kDeviceOpenNetworkConfiguration, 170 testing::Values(key::kDeviceOpenNetworkConfiguration,
170 key::kOpenNetworkConfiguration)); 171 key::kOpenNetworkConfiguration));
171 172
172 } // namespace policy 173 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698