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

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: Fixed DeviceLocalAccountTest. 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() : user_id_1_(GenerateDeviceLocalAccountUserId(
Mattias Nissler (ping if slow) 2013/05/15 09:38:47 Is this clang-format at work? Common Chromium styl
bartfab (slow) 2013/05/17 11:14:28 No, this was my own silly formatting. Done.
120 kAccountId1,
121 DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
122 user_id_2_(GenerateDeviceLocalAccountUserId(
123 kAccountId2,
124 DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {
125 }
126
119 virtual ~DeviceLocalAccountTest() {} 127 virtual ~DeviceLocalAccountTest() {}
120 128
121 virtual void SetUp() OVERRIDE { 129 virtual void SetUp() OVERRIDE {
122 // Configure and start the test server. 130 // Configure and start the test server.
123 scoped_ptr<crypto::RSAPrivateKey> signing_key( 131 scoped_ptr<crypto::RSAPrivateKey> signing_key(
124 PolicyBuilder::CreateTestSigningKey()); 132 PolicyBuilder::CreateTestSigningKey());
125 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get())); 133 ASSERT_TRUE(test_server_.SetSigningKey(signing_key.get()));
126 signing_key.reset(); 134 signing_key.reset();
127 test_server_.RegisterClient(PolicyBuilder::kFakeToken, 135 test_server_.RegisterClient(PolicyBuilder::kFakeToken,
128 PolicyBuilder::kFakeDeviceId); 136 PolicyBuilder::kFakeDeviceId);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 kAccountId2).empty()); 275 kAccountId2).empty());
268 } 276 }
269 277
270 void CheckPublicSessionPresent(const std::string& id) { 278 void CheckPublicSessionPresent(const std::string& id) {
271 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id); 279 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id);
272 ASSERT_TRUE(user); 280 ASSERT_TRUE(user);
273 EXPECT_EQ(id, user->email()); 281 EXPECT_EQ(id, user->email());
274 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType()); 282 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType());
275 } 283 }
276 284
285 const std::string user_id_1_;
286 const std::string user_id_2_;
287
277 LocalPolicyTestServer test_server_; 288 LocalPolicyTestServer test_server_;
278 base::ScopedTempDir temp_dir_; 289 base::ScopedTempDir temp_dir_;
279 290
280 chromeos::FakeSessionManagerClient* session_manager_client_; 291 chromeos::FakeSessionManagerClient* session_manager_client_;
281 }; 292 };
282 293
283 static bool IsKnownUser(const std::string& account_id) { 294 static bool IsKnownUser(const std::string& account_id) {
284 return chromeos::UserManager::Get()->IsKnownUser(account_id); 295 return chromeos::UserManager::Get()->IsKnownUser(account_id);
285 } 296 }
286 297
287 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { 298 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
288 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 299 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
289 base::Bind(&IsKnownUser, kAccountId1)).Run(); 300 base::Bind(&IsKnownUser, user_id_1_)).Run();
290 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 301 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
291 base::Bind(&IsKnownUser, kAccountId2)).Run(); 302 base::Bind(&IsKnownUser, user_id_2_)).Run();
292 303
293 CheckPublicSessionPresent(kAccountId1); 304 CheckPublicSessionPresent(user_id_1_);
294 CheckPublicSessionPresent(kAccountId2); 305 CheckPublicSessionPresent(user_id_2_);
295 } 306 }
296 307
297 static bool DisplayNameMatches(const std::string& account_id, 308 static bool DisplayNameMatches(const std::string& account_id,
298 const std::string& display_name) { 309 const std::string& display_name) {
299 const chromeos::User* user = 310 const chromeos::User* user =
300 chromeos::UserManager::Get()->FindUser(account_id); 311 chromeos::UserManager::Get()->FindUser(account_id);
301 if (!user || user->display_name().empty()) 312 if (!user || user->display_name().empty())
302 return false; 313 return false;
303 EXPECT_EQ(UTF8ToUTF16(display_name), user->display_name()); 314 EXPECT_EQ(UTF8ToUTF16(display_name), user->display_name());
304 return true; 315 return true;
305 } 316 }
306 317
307 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) { 318 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) {
308 NotificationWatcher( 319 NotificationWatcher(
309 chrome::NOTIFICATION_USER_LIST_CHANGED, 320 chrome::NOTIFICATION_USER_LIST_CHANGED,
310 base::Bind(&DisplayNameMatches, kAccountId1, kDisplayName1)).Run(); 321 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName1)).Run();
311 } 322 }
312 323
313 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) { 324 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) {
314 // Policy for kAccountId2 is not installed in session_manager_client, make 325 // 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 326 // 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 327 // up policy for kAccountId2, so the presence of the display name can be used
317 // as signal to indicate successful policy download. 328 // as signal to indicate successful policy download.
318 NotificationWatcher( 329 NotificationWatcher(
319 chrome::NOTIFICATION_USER_LIST_CHANGED, 330 chrome::NOTIFICATION_USER_LIST_CHANGED,
320 base::Bind(&DisplayNameMatches, kAccountId2, kDisplayName2)).Run(); 331 base::Bind(&DisplayNameMatches, user_id_2_, kDisplayName2)).Run();
321 332
322 // Sanity check: The policy should be present now. 333 // Sanity check: The policy should be present now.
323 ASSERT_FALSE(session_manager_client_->device_local_account_policy( 334 ASSERT_FALSE(session_manager_client_->device_local_account_policy(
324 kAccountId2).empty()); 335 kAccountId2).empty());
325 } 336 }
326 337
327 static bool IsNotKnownUser(const std::string& account_id) { 338 static bool IsNotKnownUser(const std::string& account_id) {
328 return !IsKnownUser(account_id); 339 return !IsKnownUser(account_id);
329 } 340 }
330 341
331 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) { 342 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) {
332 // Wait until the login screen is up. 343 // Wait until the login screen is up.
333 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 344 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
334 base::Bind(&IsKnownUser, kAccountId1)).Run(); 345 base::Bind(&IsKnownUser, user_id_1_)).Run();
335 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 346 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
336 base::Bind(&IsKnownUser, kAccountId2)).Run(); 347 base::Bind(&IsKnownUser, user_id_2_)).Run();
337 348
338 // Update policy to remove kAccountId2. 349 // Update policy to remove kAccountId2.
339 em::ChromeDeviceSettingsProto policy; 350 em::ChromeDeviceSettingsProto policy;
340 policy.mutable_show_user_names()->set_show_user_names(true); 351 policy.mutable_show_user_names()->set_show_user_names(true);
341 em::DeviceLocalAccountInfoProto* account1 = 352 em::DeviceLocalAccountInfoProto* account1 =
342 policy.mutable_device_local_accounts()->add_account(); 353 policy.mutable_device_local_accounts()->add_account();
343 account1->set_account_id(kAccountId1); 354 account1->set_account_id(kAccountId1);
344 account1->set_type( 355 account1->set_type(
345 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); 356 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
346 357
347 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(), 358 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(),
348 policy.SerializeAsString()); 359 policy.SerializeAsString());
349 g_browser_process->policy_service()->RefreshPolicies(base::Closure()); 360 g_browser_process->policy_service()->RefreshPolicies(base::Closure());
350 361
351 // Make sure the second device-local account disappears. 362 // Make sure the second device-local account disappears.
352 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 363 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
353 base::Bind(&IsNotKnownUser, kAccountId2)).Run(); 364 base::Bind(&IsNotKnownUser, user_id_2_)).Run();
354 } 365 }
355 366
356 static bool IsSessionStarted() { 367 static bool IsSessionStarted() {
357 return chromeos::UserManager::Get()->IsSessionStarted(); 368 return chromeos::UserManager::Get()->IsSessionStarted();
358 } 369 }
359 370
360 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) { 371 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) {
361 // This observes the display name becoming available as this indicates 372 // This observes the display name becoming available as this indicates
362 // device-local account policy is fully loaded, which is a prerequisite for 373 // device-local account policy is fully loaded, which is a prerequisite for
363 // successful login. 374 // successful login.
364 NotificationWatcher( 375 NotificationWatcher(
365 chrome::NOTIFICATION_USER_LIST_CHANGED, 376 chrome::NOTIFICATION_USER_LIST_CHANGED,
366 base::Bind(&DisplayNameMatches, kAccountId1, kDisplayName1)).Run(); 377 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName1)).Run();
367 378
368 chromeos::ExistingUserController* controller = 379 chromeos::ExistingUserController* controller =
369 chromeos::ExistingUserController::current_controller(); 380 chromeos::ExistingUserController::current_controller();
370 ASSERT_TRUE(controller); 381 ASSERT_TRUE(controller);
371 controller->LoginAsPublicAccount(kAccountId1); 382 controller->LoginAsPublicAccount(user_id_1_);
372 383
373 // Wait for the session to start. 384 // Wait for the session to start.
374 NotificationWatcher(chrome::NOTIFICATION_SESSION_STARTED, 385 NotificationWatcher(chrome::NOTIFICATION_SESSION_STARTED,
375 base::Bind(IsSessionStarted)).Run(); 386 base::Bind(IsSessionStarted)).Run();
376 387
377 // Check that the startup pages specified in policy were opened. 388 // Check that the startup pages specified in policy were opened.
378 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 389 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
379 Browser* browser = 390 Browser* browser =
380 chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); 391 chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
381 ASSERT_TRUE(browser); 392 ASSERT_TRUE(browser);
382 393
383 TabStripModel* tabs = browser->tab_strip_model(); 394 TabStripModel* tabs = browser->tab_strip_model();
384 ASSERT_TRUE(tabs); 395 ASSERT_TRUE(tabs);
385 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); 396 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
386 EXPECT_EQ(expected_tab_count, tabs->count()); 397 EXPECT_EQ(expected_tab_count, tabs->count());
387 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) 398 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i)
388 EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL()); 399 EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL());
389 } 400 }
390 401
391 } // namespace policy 402 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698