OLD | NEW |
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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 12 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
13 #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" | 13 #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
| 16 #include "chromeos/cryptohome/cryptohome_parameters.h" |
16 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
17 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
18 #include "chromeos/dbus/fake_session_manager_client.h" | 19 #include "chromeos/dbus/fake_session_manager_client.h" |
19 #include "chromeos/dbus/session_manager_client.h" | 20 #include "chromeos/dbus/session_manager_client.h" |
20 #include "components/user_manager/user.h" | 21 #include "components/user_manager/user.h" |
21 #include "components/user_manager/user_manager.h" | 22 #include "components/user_manager/user_manager.h" |
22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "third_party/cros_system_api/dbus/service_constants.h" | 25 #include "third_party/cros_system_api/dbus/service_constants.h" |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kUserId1[] = "user1@example.com"; | 31 const char kUserId1[] = "user1@example.com"; |
31 const char kUserId2[] = "user2@example.com"; | 32 const char kUserId2[] = "user2@example.com"; |
32 const char kUserId3[] = "user3@example.com"; | 33 const char kUserId3[] = "user3@example.com"; |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 class CrashRestoreSimpleTest : public InProcessBrowserTest { | 37 class CrashRestoreSimpleTest : public InProcessBrowserTest { |
37 protected: | 38 protected: |
38 CrashRestoreSimpleTest() {} | 39 CrashRestoreSimpleTest() {} |
39 | 40 |
40 ~CrashRestoreSimpleTest() override {} | 41 ~CrashRestoreSimpleTest() override {} |
41 | 42 |
42 void SetUpCommandLine(base::CommandLine* command_line) override { | 43 void SetUpCommandLine(base::CommandLine* command_line) override { |
43 command_line->AppendSwitchASCII(switches::kLoginUser, kUserId1); | 44 command_line->AppendSwitchASCII(switches::kLoginUser, cryptohome_id1_.id()); |
44 command_line->AppendSwitchASCII( | 45 command_line->AppendSwitchASCII( |
45 switches::kLoginProfile, | 46 switches::kLoginProfile, |
46 CryptohomeClient::GetStubSanitizedUsername(kUserId1)); | 47 CryptohomeClient::GetStubSanitizedUsername(cryptohome_id1_)); |
47 } | 48 } |
48 | 49 |
49 void SetUpInProcessBrowserTestFixture() override { | 50 void SetUpInProcessBrowserTestFixture() override { |
50 // Redirect session_manager DBus calls to FakeSessionManagerClient. | 51 // Redirect session_manager DBus calls to FakeSessionManagerClient. |
51 session_manager_client_ = new FakeSessionManagerClient; | 52 session_manager_client_ = new FakeSessionManagerClient; |
52 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 53 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
53 scoped_ptr<SessionManagerClient>(session_manager_client_)); | 54 scoped_ptr<SessionManagerClient>(session_manager_client_)); |
54 session_manager_client_->StartSession(kUserId1); | 55 session_manager_client_->StartSession(cryptohome_id1_); |
55 } | 56 } |
56 | 57 |
57 FakeSessionManagerClient* session_manager_client_; | 58 FakeSessionManagerClient* session_manager_client_; |
| 59 const AccountId account_id1_ = AccountId::FromUserEmail(kUserId1); |
| 60 const AccountId account_id2_ = AccountId::FromUserEmail(kUserId2); |
| 61 const AccountId account_id3_ = AccountId::FromUserEmail(kUserId3); |
| 62 const cryptohome::Identification cryptohome_id1_ = |
| 63 cryptohome::Identification(account_id1_); |
| 64 const cryptohome::Identification cryptohome_id2_ = |
| 65 cryptohome::Identification(account_id2_); |
| 66 const cryptohome::Identification cryptohome_id3_ = |
| 67 cryptohome::Identification(account_id3_); |
58 }; | 68 }; |
59 | 69 |
60 IN_PROC_BROWSER_TEST_F(CrashRestoreSimpleTest, RestoreSessionForOneUser) { | 70 IN_PROC_BROWSER_TEST_F(CrashRestoreSimpleTest, RestoreSessionForOneUser) { |
61 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 71 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
62 user_manager::User* user = user_manager->GetActiveUser(); | 72 user_manager::User* user = user_manager->GetActiveUser(); |
63 ASSERT_TRUE(user); | 73 ASSERT_TRUE(user); |
64 EXPECT_EQ(kUserId1, user->email()); | 74 EXPECT_EQ(account_id1_, user->GetAccountId()); |
65 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId1), | 75 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id1_), |
66 user->username_hash()); | 76 user->username_hash()); |
67 EXPECT_EQ(1UL, user_manager->GetLoggedInUsers().size()); | 77 EXPECT_EQ(1UL, user_manager->GetLoggedInUsers().size()); |
68 } | 78 } |
69 | 79 |
70 // Observer that keeps track of user sessions restore event. | 80 // Observer that keeps track of user sessions restore event. |
71 class UserSessionRestoreObserver : public UserSessionStateObserver { | 81 class UserSessionRestoreObserver : public UserSessionStateObserver { |
72 public: | 82 public: |
73 UserSessionRestoreObserver() | 83 UserSessionRestoreObserver() |
74 : running_loop_(false), | 84 : running_loop_(false), |
75 user_sessions_restored_( | 85 user_sessions_restored_( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 DISALLOW_COPY_AND_ASSIGN(UserSessionRestoreObserver); | 119 DISALLOW_COPY_AND_ASSIGN(UserSessionRestoreObserver); |
110 }; | 120 }; |
111 | 121 |
112 class CrashRestoreComplexTest : public CrashRestoreSimpleTest { | 122 class CrashRestoreComplexTest : public CrashRestoreSimpleTest { |
113 protected: | 123 protected: |
114 CrashRestoreComplexTest() {} | 124 CrashRestoreComplexTest() {} |
115 ~CrashRestoreComplexTest() override {} | 125 ~CrashRestoreComplexTest() override {} |
116 | 126 |
117 void SetUpInProcessBrowserTestFixture() override { | 127 void SetUpInProcessBrowserTestFixture() override { |
118 CrashRestoreSimpleTest::SetUpInProcessBrowserTestFixture(); | 128 CrashRestoreSimpleTest::SetUpInProcessBrowserTestFixture(); |
119 session_manager_client_->StartSession(kUserId2); | 129 session_manager_client_->StartSession(cryptohome_id2_); |
120 session_manager_client_->StartSession(kUserId3); | 130 session_manager_client_->StartSession(cryptohome_id3_); |
121 } | 131 } |
122 }; | 132 }; |
123 | 133 |
124 IN_PROC_BROWSER_TEST_F(CrashRestoreComplexTest, RestoreSessionForThreeUsers) { | 134 IN_PROC_BROWSER_TEST_F(CrashRestoreComplexTest, RestoreSessionForThreeUsers) { |
125 { | 135 { |
126 UserSessionRestoreObserver restore_observer; | 136 UserSessionRestoreObserver restore_observer; |
127 restore_observer.Wait(); | 137 restore_observer.Wait(); |
128 } | 138 } |
129 | 139 |
130 chromeos::test::UserSessionManagerTestApi session_manager_test_api( | 140 chromeos::test::UserSessionManagerTestApi session_manager_test_api( |
131 chromeos::UserSessionManager::GetInstance()); | 141 chromeos::UserSessionManager::GetInstance()); |
132 session_manager_test_api.SetShouldObtainTokenHandleInTests(false); | 142 session_manager_test_api.SetShouldObtainTokenHandleInTests(false); |
133 | 143 |
134 DCHECK(UserSessionManager::GetInstance()->UserSessionsRestored()); | 144 DCHECK(UserSessionManager::GetInstance()->UserSessionsRestored()); |
135 | 145 |
136 // User that is last in the user sessions map becomes active. This behavior | 146 // User that is last in the user sessions map becomes active. This behavior |
137 // will become better defined once each user gets a separate user desktop. | 147 // will become better defined once each user gets a separate user desktop. |
138 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 148 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
139 user_manager::User* user = user_manager->GetActiveUser(); | 149 user_manager::User* user = user_manager->GetActiveUser(); |
140 ASSERT_TRUE(user); | 150 ASSERT_TRUE(user); |
141 EXPECT_EQ(kUserId3, user->email()); | 151 EXPECT_EQ(account_id3_, user->GetAccountId()); |
142 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId3), | 152 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id3_), |
143 user->username_hash()); | 153 user->username_hash()); |
144 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); | 154 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); |
145 ASSERT_EQ(3UL, users.size()); | 155 ASSERT_EQ(3UL, users.size()); |
146 | 156 |
147 // User that becomes active moves to the beginning of the list. | 157 // User that becomes active moves to the beginning of the list. |
148 EXPECT_EQ(kUserId3, users[0]->email()); | 158 EXPECT_EQ(account_id3_, users[0]->GetAccountId()); |
149 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId3), | 159 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id3_), |
150 users[0]->username_hash()); | 160 users[0]->username_hash()); |
151 EXPECT_EQ(kUserId2, users[1]->email()); | 161 EXPECT_EQ(account_id2_, users[1]->GetAccountId()); |
152 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId2), | 162 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id2_), |
153 users[1]->username_hash()); | 163 users[1]->username_hash()); |
154 EXPECT_EQ(kUserId1, users[2]->email()); | 164 EXPECT_EQ(account_id1_, users[2]->GetAccountId()); |
155 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(kUserId1), | 165 EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id1_), |
156 users[2]->username_hash()); | 166 users[2]->username_hash()); |
157 } | 167 } |
158 | 168 |
159 } // namespace chromeos | 169 } // namespace chromeos |
OLD | NEW |