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

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater_impl_cros_unittest.cc

Issue 12676017: Adding policy support to the new network configuration stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang errors. Created 7 years, 8 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/chromeos/policy/network_configuration_updater.h" 5 #include "chrome/browser/chromeos/policy/network_configuration_updater_impl_cros .h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "chrome/browser/chromeos/cros/mock_network_library.h" 13 #include "chrome/browser/chromeos/cros/mock_network_library.h"
14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
15 #include "chrome/browser/policy/policy_map.h" 15 #include "chrome/browser/policy/policy_map.h"
(...skipping 23 matching lines...) Expand all
39 39
40 const char kFakeONC[] = "{ \"GUID\": \"1234\" }"; 40 const char kFakeONC[] = "{ \"GUID\": \"1234\" }";
41 41
42 ACTION_P(SetCertificateList, list) { 42 ACTION_P(SetCertificateList, list) {
43 *arg3 = list; 43 *arg3 = list;
44 return true; 44 return true;
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 // Tests of NetworkConfigurationUpdaterImplCros
49 class NetworkConfigurationUpdaterTest 50 class NetworkConfigurationUpdaterTest
50 : public testing::TestWithParam<const char*>{ 51 : public testing::TestWithParam<const char*>{
51 protected: 52 protected:
52 NetworkConfigurationUpdaterTest() 53 NetworkConfigurationUpdaterTest()
53 : ui_thread_(content::BrowserThread::UI, &loop_), 54 : ui_thread_(content::BrowserThread::UI, &loop_),
54 io_thread_(content::BrowserThread::IO, &loop_) {} 55 io_thread_(content::BrowserThread::IO, &loop_) {}
55 56
56 virtual void SetUp() OVERRIDE { 57 virtual void SetUp() OVERRIDE {
57 EXPECT_CALL(provider_, IsInitializationComplete(_)) 58 EXPECT_CALL(provider_, IsInitializationComplete(_))
58 .WillRepeatedly(Return(true)); 59 .WillRepeatedly(Return(true));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 104 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
104 105
105 // Initially, only the device policy is applied. The user policy is only 106 // Initially, only the device policy is applied. The user policy is only
106 // applied after the user profile was initialized. 107 // applied after the user profile was initialized.
107 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ? 108 const char* device_onc = GetParam() == key::kDeviceOpenNetworkConfiguration ?
108 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration; 109 kFakeONC : chromeos::onc::kEmptyUnencryptedConfiguration;
109 EXPECT_CALL(network_library_, LoadOncNetworks( 110 EXPECT_CALL(network_library_, LoadOncNetworks(
110 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _)); 111 device_onc, "", chromeos::onc::ONC_SOURCE_DEVICE_POLICY, _));
111 112
112 { 113 {
113 NetworkConfigurationUpdater updater(policy_service_.get(), 114 NetworkConfigurationUpdaterImplCros updater(policy_service_.get(),
114 &network_library_); 115 &network_library_);
115 Mock::VerifyAndClearExpectations(&network_library_); 116 Mock::VerifyAndClearExpectations(&network_library_);
116 117
117 // After the user policy is initialized, we always push both policies to the 118 // After the user policy is initialized, we always push both policies to the
118 // NetworkLibrary. 119 // NetworkLibrary.
119 EXPECT_CALL(network_library_, LoadOncNetworks( 120 EXPECT_CALL(network_library_, LoadOncNetworks(
120 kFakeONC, "", NameToONCSource(GetParam()), _)); 121 kFakeONC, "", NameToONCSource(GetParam()), _));
121 EXPECT_CALL(network_library_, LoadOncNetworks( 122 EXPECT_CALL(network_library_, LoadOncNetworks(
122 chromeos::onc::kEmptyUnencryptedConfiguration, 123 chromeos::onc::kEmptyUnencryptedConfiguration,
123 "", 124 "",
124 Ne(NameToONCSource(GetParam())), 125 Ne(NameToONCSource(GetParam())),
(...skipping 13 matching lines...) Expand all
138 const net::CertificateList empty_cert_list; 139 const net::CertificateList empty_cert_list;
139 140
140 const net::CertificateList cert_list = 141 const net::CertificateList cert_list =
141 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(), 142 net::CreateCertificateListFromFile(net::GetTestCertsDirectory(),
142 "ok_cert.pem", 143 "ok_cert.pem",
143 net::X509Certificate::FORMAT_AUTO); 144 net::X509Certificate::FORMAT_AUTO);
144 ASSERT_EQ(1u, cert_list.size()); 145 ASSERT_EQ(1u, cert_list.size());
145 146
146 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, _)) 147 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, _))
147 .WillRepeatedly(SetCertificateList(empty_cert_list)); 148 .WillRepeatedly(SetCertificateList(empty_cert_list));
148 NetworkConfigurationUpdater updater(policy_service_.get(), 149 NetworkConfigurationUpdaterImplCros updater(policy_service_.get(),
149 &network_library_); 150 &network_library_);
150 net::CertTrustAnchorProvider* trust_provider = 151 net::CertTrustAnchorProvider* trust_provider =
151 updater.GetCertTrustAnchorProvider(); 152 updater.GetCertTrustAnchorProvider();
152 ASSERT_TRUE(trust_provider); 153 ASSERT_TRUE(trust_provider);
153 // The initial list of trust anchors is empty. 154 // The initial list of trust anchors is empty.
154 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 155 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
155 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty()); 156 EXPECT_TRUE(trust_provider->GetAdditionalTrustAnchors().empty());
156 157
157 // Initially, certificates imported from policy don't have trust flags. 158 // Initially, certificates imported from policy don't have trust flags.
158 updater.OnUserPolicyInitialized(); 159 updater.OnUserPolicyInitialized();
159 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 160 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
(...skipping 28 matching lines...) Expand all
188 Mock::VerifyAndClearExpectations(&network_library_); 189 Mock::VerifyAndClearExpectations(&network_library_);
189 } 190 }
190 191
191 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) { 192 TEST_P(NetworkConfigurationUpdaterTest, PolicyChange) {
192 { 193 {
193 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_)); 194 EXPECT_CALL(network_library_, AddNetworkProfileObserver(_));
194 195
195 // Ignore the initial updates. 196 // Ignore the initial updates.
196 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, _)) 197 EXPECT_CALL(network_library_, LoadOncNetworks(_, _, _, _))
197 .Times(AnyNumber()); 198 .Times(AnyNumber());
198 NetworkConfigurationUpdater updater(policy_service_.get(), 199 NetworkConfigurationUpdaterImplCros updater(policy_service_.get(),
199 &network_library_); 200 &network_library_);
200 updater.OnUserPolicyInitialized(); 201 updater.OnUserPolicyInitialized();
201 Mock::VerifyAndClearExpectations(&network_library_); 202 Mock::VerifyAndClearExpectations(&network_library_);
202 203
203 // We should update if policy changes. 204 // We should update if policy changes.
204 EXPECT_CALL(network_library_, LoadOncNetworks( 205 EXPECT_CALL(network_library_, LoadOncNetworks(
205 kFakeONC, "", NameToONCSource(GetParam()), _)); 206 kFakeONC, "", NameToONCSource(GetParam()), _));
206 207
207 // In the current implementation, we always apply both policies. 208 // In the current implementation, we always apply both policies.
208 EXPECT_CALL(network_library_, LoadOncNetworks( 209 EXPECT_CALL(network_library_, LoadOncNetworks(
209 chromeos::onc::kEmptyUnencryptedConfiguration, 210 chromeos::onc::kEmptyUnencryptedConfiguration,
(...skipping 25 matching lines...) Expand all
235 Mock::VerifyAndClearExpectations(&network_library_); 236 Mock::VerifyAndClearExpectations(&network_library_);
236 } 237 }
237 238
238 INSTANTIATE_TEST_CASE_P( 239 INSTANTIATE_TEST_CASE_P(
239 NetworkConfigurationUpdaterTestInstance, 240 NetworkConfigurationUpdaterTestInstance,
240 NetworkConfigurationUpdaterTest, 241 NetworkConfigurationUpdaterTest,
241 testing::Values(key::kDeviceOpenNetworkConfiguration, 242 testing::Values(key::kDeviceOpenNetworkConfiguration,
242 key::kOpenNetworkConfiguration)); 243 key::kOpenNetworkConfiguration));
243 244
244 } // namespace policy 245 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698