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

Side by Side Diff: chromeos/network/managed_network_configuration_handler_unittest.cc

Issue 13957012: Adding a NetworkProfileHandler used by ManagedNetworkConfigurationHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed one comment. Created 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/network/managed_network_configuration_handler.h" 5 #include "chromeos/network/managed_network_configuration_handler.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chromeos/dbus/dbus_thread_manager.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/mock_dbus_thread_manager.h" 12 #include "chromeos/dbus/mock_dbus_thread_manager.h"
13 #include "chromeos/dbus/mock_shill_manager_client.h" 13 #include "chromeos/dbus/mock_shill_manager_client.h"
14 #include "chromeos/dbus/mock_shill_profile_client.h" 14 #include "chromeos/dbus/mock_shill_profile_client.h"
15 #include "chromeos/dbus/mock_shill_service_client.h" 15 #include "chromeos/dbus/mock_shill_service_client.h"
16 #include "chromeos/dbus/shill_profile_client_stub.h" 16 #include "chromeos/dbus/shill_profile_client_stub.h"
17 #include "chromeos/network/network_configuration_handler.h" 17 #include "chromeos/network/network_configuration_handler.h"
18 #include "chromeos/network/network_profile_handler_stub.h"
18 #include "chromeos/network/onc/onc_test_utils.h" 19 #include "chromeos/network/onc/onc_test_utils.h"
19 #include "chromeos/network/onc/onc_utils.h" 20 #include "chromeos/network/onc/onc_utils.h"
20 #include "dbus/object_path.h" 21 #include "dbus/object_path.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
24 25
25 using ::testing::Invoke; 26 using ::testing::Invoke;
26 using ::testing::Mock; 27 using ::testing::Mock;
27 using ::testing::Pointee; 28 using ::testing::Pointee;
28 using ::testing::Return; 29 using ::testing::Return;
29 using ::testing::SaveArg; 30 using ::testing::SaveArg;
30 using ::testing::StrEq; 31 using ::testing::StrEq;
31 using ::testing::StrictMock; 32 using ::testing::StrictMock;
32 using ::testing::_; 33 using ::testing::_;
33 34
34 namespace test_utils = ::chromeos::onc::test_utils; 35 namespace test_utils = ::chromeos::onc::test_utils;
35 36
37 namespace chromeos {
38
36 namespace { 39 namespace {
37 40
38 std::string ValueToString(const base::Value* value) { 41 std::string ValueToString(const base::Value* value) {
39 std::stringstream str; 42 std::stringstream str;
40 str << *value; 43 str << *value;
41 return str.str(); 44 return str.str();
42 } 45 }
43 46
47 const char kSharedProfilePath[] = "/profile/default";
48 const char kUser1[] = "user1";
49 const char kUser1ProfilePath[] = "/profile/user1/shill";
50
44 // Matcher to match base::Value. 51 // Matcher to match base::Value.
45 MATCHER_P(IsEqualTo, 52 MATCHER_P(IsEqualTo,
46 value, 53 value,
47 std::string(negation ? "isn't" : "is") + " equal to " + 54 std::string(negation ? "isn't" : "is") + " equal to " +
48 ValueToString(value)) { 55 ValueToString(value)) {
49 return value->Equals(&arg); 56 return value->Equals(&arg);
50 } 57 }
51 58
59 class ShillProfileStub {
stevenjb 2013/05/03 18:34:53 nit: Let's name this something like ShillProfileTe
pneubeck (no reviews) 2013/05/06 07:24:43 Done.
60 public:
61 typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus
62 DictionaryValueCallbackWithoutStatus;
63 typedef ShillClientHelper::ErrorCallback ErrorCallback;
64
65 void AddProfile(const std::string& profile_path,
66 const std::string& userhash) {
67 if (profile_entries_.HasKey(profile_path))
68 return;
69
70 base::DictionaryValue* profile = new base::DictionaryValue;
71 profile_entries_.SetWithoutPathExpansion(profile_path, profile);
72 profile_to_user_[profile_path] = userhash;
73 }
74
75 void AddEntry(const std::string& profile_path,
76 const std::string& entry_path,
77 const base::DictionaryValue& entry) {
78 base::DictionaryValue* entries = NULL;
79 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path, &entries);
80 ASSERT_TRUE(entries);
81
82 base::DictionaryValue* new_entry = entry.DeepCopy();
83 new_entry->SetStringWithoutPathExpansion(flimflam::kProfileProperty,
84 profile_path);
85 entries->SetWithoutPathExpansion(entry_path, new_entry);
86 }
87
88 void GetProperties(const dbus::ObjectPath& profile_path,
89 const DictionaryValueCallbackWithoutStatus& callback,
90 const ErrorCallback& error_callback) {
91 base::DictionaryValue* entries = NULL;
92 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(),
93 &entries);
94 ASSERT_TRUE(entries);
95
96 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
97 base::ListValue* entry_paths = new base::ListValue;
98 result->SetWithoutPathExpansion(flimflam::kEntriesProperty,
99 entry_paths);
100 for (base::DictionaryValue::Iterator it(*entries); !it.IsAtEnd();
101 it.Advance()) {
102 entry_paths->AppendString(it.key());
103 }
104
105 ASSERT_GT(profile_to_user_.count(profile_path.value()), 0UL);
106 const std::string& userhash = profile_to_user_[profile_path.value()];
107 result->SetStringWithoutPathExpansion(shill::kUserHashProperty, userhash);
108
109 callback.Run(*result);
110 }
111
112 void GetEntry(const dbus::ObjectPath& profile_path,
113 const std::string& entry_path,
114 const DictionaryValueCallbackWithoutStatus& callback,
115 const ErrorCallback& error_callback) {
116 base::DictionaryValue* entries = NULL;
117 profile_entries_.GetDictionaryWithoutPathExpansion(profile_path.value(),
118 &entries);
119 ASSERT_TRUE(entries);
120
121 base::DictionaryValue* entry = NULL;
122 entries->GetDictionaryWithoutPathExpansion(entry_path, &entry);
123 ASSERT_TRUE(entry);
124 callback.Run(*entry);
125 }
126
127 protected:
128 base::DictionaryValue profile_entries_;
129 std::map<std::string, std::string> profile_to_user_;
130 };
131
52 } // namespace 132 } // namespace
53 133
54
55 namespace chromeos {
56
57 class ManagedNetworkConfigurationHandlerTest : public testing::Test { 134 class ManagedNetworkConfigurationHandlerTest : public testing::Test {
58 public: 135 public:
59 ManagedNetworkConfigurationHandlerTest() { 136 ManagedNetworkConfigurationHandlerTest() {
60 } 137 }
61 138
62 virtual ~ManagedNetworkConfigurationHandlerTest() { 139 virtual ~ManagedNetworkConfigurationHandlerTest() {
63 } 140 }
64 141
65 virtual void SetUp() OVERRIDE { 142 virtual void SetUp() OVERRIDE {
66 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager; 143 MockDBusThreadManager* dbus_thread_manager = new MockDBusThreadManager;
67 EXPECT_CALL(*dbus_thread_manager, GetSystemBus()) 144 EXPECT_CALL(*dbus_thread_manager, GetSystemBus())
68 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL))); 145 .WillRepeatedly(Return(static_cast<dbus::Bus*>(NULL)));
69 DBusThreadManager::InitializeForTesting(dbus_thread_manager); 146 DBusThreadManager::InitializeForTesting(dbus_thread_manager);
70 147
71 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient()) 148 EXPECT_CALL(*dbus_thread_manager, GetShillManagerClient())
72 .WillRepeatedly(Return(&mock_manager_client_)); 149 .WillRepeatedly(Return(&mock_manager_client_));
73 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient()) 150 EXPECT_CALL(*dbus_thread_manager, GetShillServiceClient())
74 .WillRepeatedly(Return(&mock_service_client_)); 151 .WillRepeatedly(Return(&mock_service_client_));
75 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient()) 152 EXPECT_CALL(*dbus_thread_manager, GetShillProfileClient())
76 .WillRepeatedly(Return(&mock_profile_client_)); 153 .WillRepeatedly(Return(&mock_profile_client_));
77 154
78 ON_CALL(mock_profile_client_, GetProperties(_,_,_)) 155 ON_CALL(mock_profile_client_, GetProperties(_,_,_))
79 .WillByDefault(Invoke(&stub_profile_client_, 156 .WillByDefault(Invoke(&profiles_stub_,
80 &ShillProfileClientStub::GetProperties)); 157 &ShillProfileStub::GetProperties));
81 158
82 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_)) 159 ON_CALL(mock_profile_client_, GetEntry(_,_,_,_))
83 .WillByDefault(Invoke(&stub_profile_client_, 160 .WillByDefault(Invoke(&profiles_stub_,
84 &ShillProfileClientStub::GetEntry)); 161 &ShillProfileStub::GetEntry));
85 162
86 NetworkConfigurationHandler::Initialize(); 163 NetworkConfigurationHandler::Initialize();
87 ManagedNetworkConfigurationHandler::Initialize(); 164 ManagedNetworkConfigurationHandler::Initialize(&stub_profile_handler_);
88 message_loop_.RunUntilIdle(); 165 message_loop_.RunUntilIdle();
89 } 166 }
90 167
91 virtual void TearDown() OVERRIDE { 168 virtual void TearDown() OVERRIDE {
92 ManagedNetworkConfigurationHandler::Shutdown(); 169 ManagedNetworkConfigurationHandler::Shutdown();
93 NetworkConfigurationHandler::Shutdown(); 170 NetworkConfigurationHandler::Shutdown();
94 DBusThreadManager::Shutdown(); 171 DBusThreadManager::Shutdown();
95 } 172 }
96 173
174 void VerifyAndClearExpectations() {
175 Mock::VerifyAndClearExpectations(&mock_manager_client_);
176 Mock::VerifyAndClearExpectations(&mock_service_client_);
177 Mock::VerifyAndClearExpectations(&mock_profile_client_);
178 }
179
180 void InitializeStandardProfiles() {
181 profiles_stub_.AddProfile(kUser1ProfilePath, kUser1);
182 stub_profile_handler_.AddProfile(NetworkProfile(kUser1ProfilePath, kUser1));
183 stub_profile_handler_.AddProfile(
184 NetworkProfile(kSharedProfilePath, std::string()));
185 }
186
97 void SetUpEntry(const std::string& path_to_shill_json, 187 void SetUpEntry(const std::string& path_to_shill_json,
98 const std::string& profile_path, 188 const std::string& profile_path,
99 const std::string& entry_path) { 189 const std::string& entry_path) {
100 stub_profile_client_.AddEntry( 190 scoped_ptr<base::DictionaryValue> entry =
101 profile_path, 191 test_utils::ReadTestDictionary(path_to_shill_json);
102 entry_path, 192 profiles_stub_.AddEntry(profile_path, entry_path, *entry);
103 *test_utils::ReadTestDictionary(path_to_shill_json));
104 } 193 }
105 194
106 void SetPolicy(onc::ONCSource onc_source, 195 void SetPolicy(onc::ONCSource onc_source,
196 const std::string& userhash,
107 const std::string& path_to_onc) { 197 const std::string& path_to_onc) {
108 scoped_ptr<base::DictionaryValue> policy; 198 scoped_ptr<base::DictionaryValue> policy;
109 if (path_to_onc.empty()) 199 if (path_to_onc.empty())
110 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration); 200 policy = onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration);
111 else 201 else
112 policy = test_utils::ReadTestDictionary(path_to_onc); 202 policy = test_utils::ReadTestDictionary(path_to_onc);
113 203
114 base::ListValue* network_configs = NULL; 204 base::ListValue* network_configs = NULL;
115 policy->GetListWithoutPathExpansion( 205 policy->GetListWithoutPathExpansion(
116 onc::toplevel_config::kNetworkConfigurations, &network_configs); 206 onc::toplevel_config::kNetworkConfigurations, &network_configs);
117 207
118 managed_handler()->SetPolicy(onc::ONC_SOURCE_USER_POLICY, *network_configs); 208 managed_handler()->SetPolicy(
209 onc::ONC_SOURCE_USER_POLICY, userhash, *network_configs);
119 } 210 }
120 211
121 ManagedNetworkConfigurationHandler* managed_handler() { 212 ManagedNetworkConfigurationHandler* managed_handler() {
122 return ManagedNetworkConfigurationHandler::Get(); 213 return ManagedNetworkConfigurationHandler::Get();
123 } 214 }
124 215
125 protected: 216 protected:
126 StrictMock<MockShillManagerClient> mock_manager_client_; 217 StrictMock<MockShillManagerClient> mock_manager_client_;
127 StrictMock<MockShillServiceClient> mock_service_client_; 218 StrictMock<MockShillServiceClient> mock_service_client_;
128 StrictMock<MockShillProfileClient> mock_profile_client_; 219 StrictMock<MockShillProfileClient> mock_profile_client_;
129 ShillProfileClientStub stub_profile_client_; 220 NetworkProfileHandlerStub stub_profile_handler_;
221 ShillProfileStub profiles_stub_;
130 MessageLoop message_loop_; 222 MessageLoop message_loop_;
131 223
132 private: 224 private:
133 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest); 225 DISALLOW_COPY_AND_ASSIGN(ManagedNetworkConfigurationHandlerTest);
134 }; 226 };
135 227
228 TEST_F(ManagedNetworkConfigurationHandlerTest, ProfileInitialization) {
229 InitializeStandardProfiles();
230 message_loop_.RunUntilIdle();
231 }
232
136 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) { 233 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnconfigured) {
234 InitializeStandardProfiles();
137 scoped_ptr<base::DictionaryValue> expected_shill_properties = 235 scoped_ptr<base::DictionaryValue> expected_shill_properties =
138 test_utils::ReadTestDictionary( 236 test_utils::ReadTestDictionary(
139 "policy/shill_policy_on_unconfigured_wifi1.json"); 237 "policy/shill_policy_on_unconfigured_wifi1.json");
140 238
141 EXPECT_CALL(mock_profile_client_, 239 EXPECT_CALL(mock_profile_client_,
142 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), 240 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
143 _, _)).Times(1);
144 241
145 EXPECT_CALL(mock_manager_client_, 242 EXPECT_CALL(mock_manager_client_,
146 ConfigureServiceForProfile( 243 ConfigureServiceForProfile(
147 dbus::ObjectPath("/profile/chronos/shill"), 244 dbus::ObjectPath(kUser1ProfilePath),
148 IsEqualTo(expected_shill_properties.get()), 245 IsEqualTo(expected_shill_properties.get()),
149 _, _)).Times(1); 246 _, _));
150 247
151 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); 248 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
152 message_loop_.RunUntilIdle(); 249 message_loop_.RunUntilIdle();
153 } 250 }
154 251
155 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) { 252 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmodified) {
156 EXPECT_CALL(mock_profile_client_, 253 InitializeStandardProfiles();
157 GetProperties(_, _, _)).Times(1); 254 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _));
158 255
159 EXPECT_CALL(mock_manager_client_, 256 EXPECT_CALL(mock_manager_client_, ConfigureServiceForProfile(_, _, _, _));
160 ConfigureServiceForProfile(_, _, _, _)).Times(1);
161 257
162 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); 258 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
163 message_loop_.RunUntilIdle(); 259 message_loop_.RunUntilIdle();
164 Mock::VerifyAndClearExpectations(&mock_profile_client_); 260 VerifyAndClearExpectations();
165 Mock::VerifyAndClearExpectations(&mock_manager_client_);
166 261
167 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", 262 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json",
168 "/profile/chronos/shill", 263 kUser1ProfilePath,
169 "some_entry_path"); 264 "some_entry_path");
170 265
171 EXPECT_CALL(mock_profile_client_, 266 EXPECT_CALL(mock_profile_client_, GetProperties(_, _, _));
172 GetProperties(_, _, _)).Times(1);
173 267
174 EXPECT_CALL(mock_profile_client_, 268 EXPECT_CALL(mock_profile_client_,
175 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), 269 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
176 "some_entry_path", 270 "some_entry_path",
177 _, _)).Times(1); 271 _, _));
178 272
179 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); 273 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
180 message_loop_.RunUntilIdle(); 274 message_loop_.RunUntilIdle();
181 } 275 }
182 276
183 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) { 277 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyManageUnmanaged) {
278 InitializeStandardProfiles();
184 SetUpEntry("policy/shill_unmanaged_user_wifi1.json", 279 SetUpEntry("policy/shill_unmanaged_user_wifi1.json",
185 "/profile/chronos/shill", 280 kUser1ProfilePath,
186 "old_entry_path"); 281 "old_entry_path");
187 282
188 scoped_ptr<base::DictionaryValue> expected_shill_properties = 283 scoped_ptr<base::DictionaryValue> expected_shill_properties =
189 test_utils::ReadTestDictionary( 284 test_utils::ReadTestDictionary(
190 "policy/shill_policy_on_unmanaged_user_wifi1.json"); 285 "policy/shill_policy_on_unmanaged_user_wifi1.json");
191 286
192 EXPECT_CALL(mock_profile_client_, 287 EXPECT_CALL(mock_profile_client_,
193 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), 288 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
194 _, _)).Times(1);
195 289
196 EXPECT_CALL(mock_profile_client_, 290 EXPECT_CALL(mock_profile_client_,
197 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), 291 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
198 "old_entry_path", 292 "old_entry_path",
199 _, _)).Times(1); 293 _, _));
200 294
201 EXPECT_CALL(mock_manager_client_, 295 EXPECT_CALL(mock_manager_client_,
202 ConfigureServiceForProfile( 296 ConfigureServiceForProfile(
203 dbus::ObjectPath("/profile/chronos/shill"), 297 dbus::ObjectPath(kUser1ProfilePath),
204 IsEqualTo(expected_shill_properties.get()), 298 IsEqualTo(expected_shill_properties.get()),
205 _, _)).Times(1); 299 _, _));
206 300
207 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); 301 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
208 message_loop_.RunUntilIdle(); 302 message_loop_.RunUntilIdle();
209 } 303 }
210 304
211 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) { 305 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUpdateManagedNewGUID) {
306 InitializeStandardProfiles();
212 SetUpEntry("policy/shill_managed_wifi1.json", 307 SetUpEntry("policy/shill_managed_wifi1.json",
213 "/profile/chronos/shill", 308 kUser1ProfilePath,
214 "old_entry_path"); 309 "old_entry_path");
215 310
216 scoped_ptr<base::DictionaryValue> expected_shill_properties = 311 scoped_ptr<base::DictionaryValue> expected_shill_properties =
217 test_utils::ReadTestDictionary( 312 test_utils::ReadTestDictionary(
218 "policy/shill_policy_on_unmanaged_user_wifi1.json"); 313 "policy/shill_policy_on_unmanaged_user_wifi1.json");
219 314
220 // The passphrase isn't sent again, because it's configured by the user and 315 // The passphrase isn't sent again, because it's configured by the user and
221 // Shill doesn't sent it on GetProperties calls. 316 // Shill doesn't sent it on GetProperties calls.
222 expected_shill_properties->RemoveWithoutPathExpansion( 317 expected_shill_properties->RemoveWithoutPathExpansion(
223 flimflam::kPassphraseProperty, NULL); 318 flimflam::kPassphraseProperty, NULL);
224 319
225 EXPECT_CALL(mock_profile_client_, 320 EXPECT_CALL(mock_profile_client_,
226 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), 321 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
227 _, _)).Times(1);
228 322
229 EXPECT_CALL(mock_profile_client_, 323 EXPECT_CALL(mock_profile_client_,
230 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), 324 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
231 "old_entry_path", 325 "old_entry_path",
232 _, _)).Times(1); 326 _, _));
233 327
234 EXPECT_CALL(mock_manager_client_, 328 EXPECT_CALL(mock_manager_client_,
235 ConfigureServiceForProfile( 329 ConfigureServiceForProfile(
236 dbus::ObjectPath("/profile/chronos/shill"), 330 dbus::ObjectPath(kUser1ProfilePath),
237 IsEqualTo(expected_shill_properties.get()), 331 IsEqualTo(expected_shill_properties.get()),
238 _, _)).Times(1); 332 _, _));
239 333
240 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); 334 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
241 message_loop_.RunUntilIdle(); 335 message_loop_.RunUntilIdle();
242 } 336 }
243 337
244 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) { 338 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyReapplyToManaged) {
339 InitializeStandardProfiles();
245 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", 340 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json",
246 "/profile/chronos/shill", 341 kUser1ProfilePath,
247 "old_entry_path"); 342 "old_entry_path");
248 343
249 scoped_ptr<base::DictionaryValue> expected_shill_properties = 344 scoped_ptr<base::DictionaryValue> expected_shill_properties =
250 test_utils::ReadTestDictionary( 345 test_utils::ReadTestDictionary(
251 "policy/shill_policy_on_unmanaged_user_wifi1.json"); 346 "policy/shill_policy_on_unmanaged_user_wifi1.json");
252 347
253 // The passphrase isn't sent again, because it's configured by the user and 348 // The passphrase isn't sent again, because it's configured by the user and
254 // Shill doesn't sent it on GetProperties calls. 349 // Shill doesn't sent it on GetProperties calls.
255 expected_shill_properties->RemoveWithoutPathExpansion( 350 expected_shill_properties->RemoveWithoutPathExpansion(
256 flimflam::kPassphraseProperty, NULL); 351 flimflam::kPassphraseProperty, NULL);
257 352
258 EXPECT_CALL(mock_profile_client_, 353 EXPECT_CALL(mock_profile_client_,
259 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), 354 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
260 _, _)).Times(1);
261 355
262 EXPECT_CALL(mock_profile_client_, 356 EXPECT_CALL(mock_profile_client_,
263 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), 357 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
264 "old_entry_path", 358 "old_entry_path",
265 _, _)).Times(1); 359 _, _));
266 360
267 EXPECT_CALL(mock_manager_client_, 361 EXPECT_CALL(mock_manager_client_,
268 ConfigureServiceForProfile( 362 ConfigureServiceForProfile(
269 dbus::ObjectPath("/profile/chronos/shill"), 363 dbus::ObjectPath(kUser1ProfilePath),
270 IsEqualTo(expected_shill_properties.get()), 364 IsEqualTo(expected_shill_properties.get()),
271 _, _)).Times(1); 365 _, _));
272 366
273 SetPolicy(onc::ONC_SOURCE_USER_POLICY, "policy/policy_wifi1.onc"); 367 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
274 message_loop_.RunUntilIdle(); 368 message_loop_.RunUntilIdle();
275 } 369 }
276 370
277 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) { 371 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyUnmanageManaged) {
372 InitializeStandardProfiles();
278 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json", 373 SetUpEntry("policy/shill_policy_on_unmanaged_user_wifi1.json",
279 "/profile/chronos/shill", 374 kUser1ProfilePath,
280 "old_entry_path"); 375 "old_entry_path");
281 376
282 EXPECT_CALL(mock_profile_client_, 377 EXPECT_CALL(mock_profile_client_,
283 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), 378 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
284 _, _)).Times(1);
285 379
286 EXPECT_CALL(mock_profile_client_, 380 EXPECT_CALL(mock_profile_client_,
287 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), 381 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
288 "old_entry_path", 382 "old_entry_path",
289 _, _)).Times(1); 383 _, _));
290 384
291 EXPECT_CALL(mock_profile_client_, 385 EXPECT_CALL(mock_profile_client_,
292 DeleteEntry(dbus::ObjectPath("/profile/chronos/shill"), 386 DeleteEntry(dbus::ObjectPath(kUser1ProfilePath),
293 "old_entry_path", 387 "old_entry_path",
294 _, _)).Times(1); 388 _, _));
295 389
296 SetPolicy(onc::ONC_SOURCE_USER_POLICY, ""); 390 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "");
297 message_loop_.RunUntilIdle(); 391 message_loop_.RunUntilIdle();
298 } 392 }
299 393
300 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) { 394 TEST_F(ManagedNetworkConfigurationHandlerTest, SetPolicyIgnoreUnmanaged) {
395 InitializeStandardProfiles();
301 SetUpEntry("policy/shill_unmanaged_user_wifi1.json", 396 SetUpEntry("policy/shill_unmanaged_user_wifi1.json",
302 "/profile/chronos/shill", 397 kUser1ProfilePath,
303 "old_entry_path"); 398 "old_entry_path");
304 399
305 EXPECT_CALL(mock_profile_client_, 400 EXPECT_CALL(mock_profile_client_,
306 GetProperties(dbus::ObjectPath("/profile/chronos/shill"), 401 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
307 _, _)).Times(1);
308 402
309 EXPECT_CALL(mock_profile_client_, 403 EXPECT_CALL(mock_profile_client_,
310 GetEntry(dbus::ObjectPath("/profile/chronos/shill"), 404 GetEntry(dbus::ObjectPath(kUser1ProfilePath),
311 "old_entry_path", 405 "old_entry_path",
312 _, _)).Times(1); 406 _, _));
313 407
314 SetPolicy(onc::ONC_SOURCE_USER_POLICY, ""); 408 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "");
315 message_loop_.RunUntilIdle(); 409 message_loop_.RunUntilIdle();
316 } 410 }
317 411
412 TEST_F(ManagedNetworkConfigurationHandlerTest, LateProfileLoading) {
413 SetPolicy(onc::ONC_SOURCE_USER_POLICY, kUser1, "policy/policy_wifi1.onc");
414
415 message_loop_.RunUntilIdle();
416 VerifyAndClearExpectations();
417
418 scoped_ptr<base::DictionaryValue> expected_shill_properties =
419 test_utils::ReadTestDictionary(
420 "policy/shill_policy_on_unconfigured_wifi1.json");
421
422 EXPECT_CALL(mock_profile_client_,
423 GetProperties(dbus::ObjectPath(kUser1ProfilePath), _, _));
424
425 EXPECT_CALL(mock_manager_client_,
426 ConfigureServiceForProfile(
427 dbus::ObjectPath(kUser1ProfilePath),
428 IsEqualTo(expected_shill_properties.get()),
429 _, _));
430
431 InitializeStandardProfiles();
432 message_loop_.RunUntilIdle();
433 }
434
318 } // namespace chromeos 435 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698