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

Side by Side Diff: chrome/browser/ui/ash/session_controller_client_unittest.cc

Issue 2863993002: cros: Defer primary user meta update until active (Closed)
Patch Set: fix nits Created 3 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
« no previous file with comments | « chrome/browser/ui/ash/session_controller_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/ui/ash/session_controller_client.h" 5 #include "chrome/browser/ui/ash/session_controller_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "components/session_manager/core/session_manager.h" 25 #include "components/session_manager/core/session_manager.h"
26 #include "components/signin/core/account_id/account_id.h" 26 #include "components/signin/core/account_id/account_id.h"
27 #include "components/user_manager/user_manager.h" 27 #include "components/user_manager/user_manager.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "net/cert/x509_certificate.h" 29 #include "net/cert/x509_certificate.h"
30 #include "net/test/cert_test_util.h" 30 #include "net/test/cert_test_util.h"
31 #include "net/test/test_data_directory.h" 31 #include "net/test/test_data_directory.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 using chromeos::FakeChromeUserManager; 34 using chromeos::FakeChromeUserManager;
35 using session_manager::SessionState;
35 36
36 namespace { 37 namespace {
37 38
38 const char* kUser = "user@test.com"; 39 const char* kUser = "user@test.com";
39 40
40 // Weak ptr to PolicyCertVerifier - object is freed in test destructor once 41 // Weak ptr to PolicyCertVerifier - object is freed in test destructor once
41 // we've ensured the profile has been shut down. 42 // we've ensured the profile has been shut down.
42 policy::PolicyCertVerifier* g_policy_cert_verifier_for_factory = nullptr; 43 policy::PolicyCertVerifier* g_policy_cert_verifier_for_factory = nullptr;
43 44
44 std::unique_ptr<KeyedService> CreateTestPolicyCertService( 45 std::unique_ptr<KeyedService> CreateTestPolicyCertService(
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 376
376 // No user session sent yet. 377 // No user session sent yet.
377 EXPECT_EQ(0, session_controller.update_user_session_count()); 378 EXPECT_EQ(0, session_controller.update_user_session_count());
378 379
379 // Simulate login. 380 // Simulate login.
380 const AccountId account_id(AccountId::FromUserEmail("user@test.com")); 381 const AccountId account_id(AccountId::FromUserEmail("user@test.com"));
381 user_manager()->AddUser(account_id); 382 user_manager()->AddUser(account_id);
382 session_manager_.CreateSession( 383 session_manager_.CreateSession(
383 account_id, chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( 384 account_id, chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(
384 "user@test.com")); 385 "user@test.com"));
386 session_manager_.SetSessionState(SessionState::ACTIVE);
385 SessionControllerClient::FlushForTesting(); 387 SessionControllerClient::FlushForTesting();
386 388
387 // User session was sent. 389 // User session was sent.
388 EXPECT_EQ(1, session_controller.update_user_session_count()); 390 EXPECT_EQ(1, session_controller.update_user_session_count());
389 391
390 // Simulate a request for an update where nothing changed. 392 // Simulate a request for an update where nothing changed.
391 client.SendUserSession(*user_manager()->GetLoggedInUsers()[0]); 393 client.SendUserSession(*user_manager()->GetLoggedInUsers()[0]);
392 SessionControllerClient::FlushForTesting(); 394 SessionControllerClient::FlushForTesting();
393 395
394 // Session was not updated because nothing changed. 396 // Session was not updated because nothing changed.
395 EXPECT_EQ(1, session_controller.update_user_session_count()); 397 EXPECT_EQ(1, session_controller.update_user_session_count());
396 } 398 }
397 399
398 TEST_F(SessionControllerClientTest, SupervisedUser) { 400 TEST_F(SessionControllerClientTest, SupervisedUser) {
399 // Create an object to test and connect it to our test interface. 401 // Create an object to test and connect it to our test interface.
400 SessionControllerClient client; 402 SessionControllerClient client;
401 TestSessionController session_controller; 403 TestSessionController session_controller;
402 client.session_controller_ = session_controller.CreateInterfacePtrAndBind(); 404 client.session_controller_ = session_controller.CreateInterfacePtrAndBind();
403 client.Init(); 405 client.Init();
404 SessionControllerClient::FlushForTesting(); 406 SessionControllerClient::FlushForTesting();
405 407
406 // Simulate the login screen. No user session yet. 408 // Simulate the login screen. No user session yet.
407 session_manager_.SetSessionState( 409 session_manager_.SetSessionState(SessionState::LOGIN_PRIMARY);
408 session_manager::SessionState::LOGIN_PRIMARY);
409 EXPECT_FALSE(session_controller.last_user_session()); 410 EXPECT_FALSE(session_controller.last_user_session());
410 411
411 // Simulate a supervised user logging in. 412 // Simulate a supervised user logging in.
412 const AccountId account_id(AccountId::FromUserEmail("child@test.com")); 413 const AccountId account_id(AccountId::FromUserEmail("child@test.com"));
413 const user_manager::User* user = 414 const user_manager::User* user =
414 user_manager()->AddSupervisedUser(account_id); 415 user_manager()->AddSupervisedUser(account_id);
415 ASSERT_TRUE(user); 416 ASSERT_TRUE(user);
416 417
417 // Start session. This logs in the user and sends an active user notification. 418 // Start session. This logs in the user and sends an active user notification.
418 // The hash must match the one used by FakeChromeUserManager. 419 // The hash must match the one used by FakeChromeUserManager.
419 session_manager_.CreateSession( 420 session_manager_.CreateSession(
420 account_id, chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting( 421 account_id, chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(
421 "child@test.com")); 422 "child@test.com"));
423 session_manager_.SetSessionState(SessionState::ACTIVE);
422 SessionControllerClient::FlushForTesting(); 424 SessionControllerClient::FlushForTesting();
423 425
424 // The session controller received session info and user session. 426 // The session controller received session info and user session.
425 EXPECT_LT(0u, session_controller.last_user_session()->session_id); 427 EXPECT_LT(0u, session_controller.last_user_session()->session_id);
426 EXPECT_EQ(user_manager::USER_TYPE_SUPERVISED, 428 EXPECT_EQ(user_manager::USER_TYPE_SUPERVISED,
427 session_controller.last_user_session()->type); 429 session_controller.last_user_session()->type);
428 430
429 // Simulate profile creation after login. 431 // Simulate profile creation after login.
430 CreateTestingProfile(user); 432 CreateTestingProfile(user);
431 user_profile_->SetSupervisedUserId("child-id"); 433 user_profile_->SetSupervisedUserId("child-id");
(...skipping 16 matching lines...) Expand all
448 450
449 // Simulate an update to the custodian information. 451 // Simulate an update to the custodian information.
450 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent3@test.com"); 452 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent3@test.com");
451 client.OnCustodianInfoChanged(); 453 client.OnCustodianInfoChanged();
452 SessionControllerClient::FlushForTesting(); 454 SessionControllerClient::FlushForTesting();
453 455
454 // The updated custodian was sent over the mojo interface. 456 // The updated custodian was sent over the mojo interface.
455 EXPECT_EQ("parent3@test.com", 457 EXPECT_EQ("parent3@test.com",
456 session_controller.last_user_session()->custodian_email); 458 session_controller.last_user_session()->custodian_email);
457 } 459 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/session_controller_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698