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

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

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix forward declaration. 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chromeos/login/existing_user_controller.h" 22 #include "chrome/browser/chromeos/login/existing_user_controller.h"
23 #include "chrome/browser/chromeos/login/user.h" 23 #include "chrome/browser/chromeos/login/user.h"
24 #include "chrome/browser/chromeos/login/user_manager.h" 24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/login/wizard_controller.h" 25 #include "chrome/browser/chromeos/login/wizard_controller.h"
26 #include "chrome/browser/chromeos/policy/device_local_account.h"
26 #include "chrome/browser/chromeos/policy/device_policy_builder.h" 27 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
27 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
28 #include "chrome/browser/lifetime/application_lifetime.h" 29 #include "chrome/browser/lifetime/application_lifetime.h"
29 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 30 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
30 #include "chrome/browser/policy/cloud/policy_builder.h" 31 #include "chrome/browser/policy/cloud/policy_builder.h"
31 #include "chrome/browser/policy/policy_service.h" 32 #include "chrome/browser/policy/policy_service.h"
32 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" 33 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
33 #include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h" 34 #include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h"
34 #include "chrome/browser/policy/test/local_policy_test_server.h" 35 #include "chrome/browser/policy/test/local_policy_test_server.h"
35 #include "chrome/browser/prefs/session_startup_pref.h" 36 #include "chrome/browser/prefs/session_startup_pref.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 ConditionTestCallback callback_; 109 ConditionTestCallback callback_;
109 base::RunLoop run_loop_; 110 base::RunLoop run_loop_;
110 111
111 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); 112 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher);
112 }; 113 };
113 114
114 } // namespace 115 } // namespace
115 116
116 class DeviceLocalAccountTest : public InProcessBrowserTest { 117 class DeviceLocalAccountTest : public InProcessBrowserTest {
117 protected: 118 protected:
118 DeviceLocalAccountTest() {} 119 DeviceLocalAccountTest()
120 : user_id_1_(GenerateDeviceLocalAccountUserId(
121 kAccountId1, DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
122 user_id_2_(GenerateDeviceLocalAccountUserId(
123 kAccountId2, DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {}
124
119 virtual ~DeviceLocalAccountTest() {} 125 virtual ~DeviceLocalAccountTest() {}
120 126
121 virtual void SetUp() OVERRIDE { 127 virtual void SetUp() OVERRIDE {
122 // Configure and start the test server. 128 // Configure and start the test server.
123 scoped_ptr<crypto::RSAPrivateKey> signing_key( 129 scoped_ptr<crypto::RSAPrivateKey> signing_key(
124 PolicyBuilder::CreateTestSigningKey()); 130 PolicyBuilder::CreateTestSigningKey());
125 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get())); 131 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get()));
126 signing_key.reset(); 132 signing_key.reset();
127 test_server_.RegisterClient(PolicyBuilder::kFakeToken, 133 test_server_.RegisterClient(PolicyBuilder::kFakeToken,
128 PolicyBuilder::kFakeDeviceId); 134 PolicyBuilder::kFakeDeviceId);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 kAccountId2).empty()); 273 kAccountId2).empty());
268 } 274 }
269 275
270 void CheckPublicSessionPresent(const std::string& id) { 276 void CheckPublicSessionPresent(const std::string& id) {
271 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id); 277 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id);
272 ASSERT_TRUE(user); 278 ASSERT_TRUE(user);
273 EXPECT_EQ(id, user->email()); 279 EXPECT_EQ(id, user->email());
274 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType()); 280 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType());
275 } 281 }
276 282
283 const std::string user_id_1_;
284 const std::string user_id_2_;
285
277 LocalPolicyTestServer test_server_; 286 LocalPolicyTestServer test_server_;
278 base::ScopedTempDir temp_dir_; 287 base::ScopedTempDir temp_dir_;
279 288
280 chromeos::FakeSessionManagerClient* session_manager_client_; 289 chromeos::FakeSessionManagerClient* session_manager_client_;
281 }; 290 };
282 291
283 static bool IsKnownUser(const std::string& account_id) { 292 static bool IsKnownUser(const std::string& account_id) {
284 return chromeos::UserManager::Get()->IsKnownUser(account_id); 293 return chromeos::UserManager::Get()->IsKnownUser(account_id);
285 } 294 }
286 295
287 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { 296 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
288 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 297 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
289 base::Bind(&IsKnownUser, kAccountId1)).Run(); 298 base::Bind(&IsKnownUser, user_id_1_)).Run();
290 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 299 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
291 base::Bind(&IsKnownUser, kAccountId2)).Run(); 300 base::Bind(&IsKnownUser, user_id_2_)).Run();
292 301
293 CheckPublicSessionPresent(kAccountId1); 302 CheckPublicSessionPresent(user_id_1_);
294 CheckPublicSessionPresent(kAccountId2); 303 CheckPublicSessionPresent(user_id_2_);
295 } 304 }
296 305
297 static bool DisplayNameMatches(const std::string& account_id, 306 static bool DisplayNameMatches(const std::string& account_id,
298 const std::string& display_name) { 307 const std::string& display_name) {
299 const chromeos::User* user = 308 const chromeos::User* user =
300 chromeos::UserManager::Get()->FindUser(account_id); 309 chromeos::UserManager::Get()->FindUser(account_id);
301 if (!user || user->display_name().empty()) 310 if (!user || user->display_name().empty())
302 return false; 311 return false;
303 EXPECT_EQ(UTF8ToUTF16(display_name), user->display_name()); 312 EXPECT_EQ(UTF8ToUTF16(display_name), user->display_name());
304 return true; 313 return true;
305 } 314 }
306 315
307 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) { 316 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) {
308 NotificationWatcher( 317 NotificationWatcher(
309 chrome::NOTIFICATION_USER_LIST_CHANGED, 318 chrome::NOTIFICATION_USER_LIST_CHANGED,
310 base::Bind(&DisplayNameMatches, kAccountId1, kDisplayName1)).Run(); 319 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName1)).Run();
311 } 320 }
312 321
313 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) { 322 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) {
314 // Policy for kAccountId2 is not installed in session_manager_client, make 323 // Policy for kAccountId2 is not installed in session_manager_client, make
315 // sure it gets fetched from the server. Note that the test setup doesn't set 324 // sure it gets fetched from the server. Note that the test setup doesn't set
316 // up policy for kAccountId2, so the presence of the display name can be used 325 // up policy for kAccountId2, so the presence of the display name can be used
317 // as signal to indicate successful policy download. 326 // as signal to indicate successful policy download.
318 NotificationWatcher( 327 NotificationWatcher(
319 chrome::NOTIFICATION_USER_LIST_CHANGED, 328 chrome::NOTIFICATION_USER_LIST_CHANGED,
320 base::Bind(&DisplayNameMatches, kAccountId2, kDisplayName2)).Run(); 329 base::Bind(&DisplayNameMatches, user_id_2_, kDisplayName2)).Run();
321 330
322 // Sanity check: The policy should be present now. 331 // Sanity check: The policy should be present now.
323 ASSERT_FALSE(session_manager_client_->device_local_account_policy( 332 ASSERT_FALSE(session_manager_client_->device_local_account_policy(
324 kAccountId2).empty()); 333 kAccountId2).empty());
325 } 334 }
326 335
327 static bool IsNotKnownUser(const std::string& account_id) { 336 static bool IsNotKnownUser(const std::string& account_id) {
328 return !IsKnownUser(account_id); 337 return !IsKnownUser(account_id);
329 } 338 }
330 339
331 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) { 340 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) {
332 // Wait until the login screen is up. 341 // Wait until the login screen is up.
333 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 342 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
334 base::Bind(&IsKnownUser, kAccountId1)).Run(); 343 base::Bind(&IsKnownUser, user_id_1_)).Run();
335 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 344 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
336 base::Bind(&IsKnownUser, kAccountId2)).Run(); 345 base::Bind(&IsKnownUser, user_id_2_)).Run();
337 346
338 // Update policy to remove kAccountId2. 347 // Update policy to remove kAccountId2.
339 em::ChromeDeviceSettingsProto policy; 348 em::ChromeDeviceSettingsProto policy;
340 policy.mutable_show_user_names()->set_show_user_names(true); 349 policy.mutable_show_user_names()->set_show_user_names(true);
341 em::DeviceLocalAccountInfoProto* account1 = 350 em::DeviceLocalAccountInfoProto* account1 =
342 policy.mutable_device_local_accounts()->add_account(); 351 policy.mutable_device_local_accounts()->add_account();
343 account1->set_account_id(kAccountId1); 352 account1->set_account_id(kAccountId1);
344 account1->set_type( 353 account1->set_type(
345 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); 354 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
346 355
347 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(), 356 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(),
348 policy.SerializeAsString()); 357 policy.SerializeAsString());
349 g_browser_process->policy_service()->RefreshPolicies(base::Closure()); 358 g_browser_process->policy_service()->RefreshPolicies(base::Closure());
350 359
351 // Make sure the second device-local account disappears. 360 // Make sure the second device-local account disappears.
352 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 361 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
353 base::Bind(&IsNotKnownUser, kAccountId2)).Run(); 362 base::Bind(&IsNotKnownUser, user_id_2_)).Run();
354 } 363 }
355 364
356 static bool IsSessionStarted() { 365 static bool IsSessionStarted() {
357 return chromeos::UserManager::Get()->IsSessionStarted(); 366 return chromeos::UserManager::Get()->IsSessionStarted();
358 } 367 }
359 368
360 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) { 369 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) {
361 // This observes the display name becoming available as this indicates 370 // This observes the display name becoming available as this indicates
362 // device-local account policy is fully loaded, which is a prerequisite for 371 // device-local account policy is fully loaded, which is a prerequisite for
363 // successful login. 372 // successful login.
364 NotificationWatcher( 373 NotificationWatcher(
365 chrome::NOTIFICATION_USER_LIST_CHANGED, 374 chrome::NOTIFICATION_USER_LIST_CHANGED,
366 base::Bind(&DisplayNameMatches, kAccountId1, kDisplayName1)).Run(); 375 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName1)).Run();
367 376
368 chromeos::ExistingUserController* controller = 377 chromeos::ExistingUserController* controller =
369 chromeos::ExistingUserController::current_controller(); 378 chromeos::ExistingUserController::current_controller();
370 ASSERT_TRUE(controller); 379 ASSERT_TRUE(controller);
371 controller->LoginAsPublicAccount(kAccountId1); 380 controller->LoginAsPublicAccount(user_id_1_);
372 381
373 // Wait for the session to start. 382 // Wait for the session to start.
374 NotificationWatcher(chrome::NOTIFICATION_SESSION_STARTED, 383 NotificationWatcher(chrome::NOTIFICATION_SESSION_STARTED,
375 base::Bind(IsSessionStarted)).Run(); 384 base::Bind(IsSessionStarted)).Run();
376 385
377 // Check that the startup pages specified in policy were opened. 386 // Check that the startup pages specified in policy were opened.
378 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 387 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
379 Browser* browser = 388 Browser* browser =
380 chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); 389 chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
381 ASSERT_TRUE(browser); 390 ASSERT_TRUE(browser);
382 391
383 TabStripModel* tabs = browser->tab_strip_model(); 392 TabStripModel* tabs = browser->tab_strip_model();
384 ASSERT_TRUE(tabs); 393 ASSERT_TRUE(tabs);
385 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); 394 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
386 EXPECT_EQ(expected_tab_count, tabs->count()); 395 EXPECT_EQ(expected_tab_count, tabs->count());
387 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) 396 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i)
388 EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL()); 397 EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL());
389 } 398 }
390 399
391 } // namespace policy 400 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698