Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 void SetUpOnMainThread() override { | 50 void SetUpOnMainThread() override { |
| 51 OobeBaseTest::SetUpOnMainThread(); | 51 OobeBaseTest::SetUpOnMainThread(); |
| 52 LoadRefreshTokenToDeviceIdMap(); | 52 LoadRefreshTokenToDeviceIdMap(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void TearDownOnMainThread() override { | 55 void TearDownOnMainThread() override { |
| 56 SaveRefreshTokenToDeviceIdMap(); | 56 SaveRefreshTokenToDeviceIdMap(); |
| 57 OobeBaseTest::TearDownOnMainThread(); | 57 OobeBaseTest::TearDownOnMainThread(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::string GetDeviceId(const std::string& user_id) { | 60 std::string GetDeviceId(const AccountId& user_id) { |
|
achuithb
2015/10/23 00:08:50
account_id, here and below
Alexander Alekseev
2015/10/23 09:11:22
Done.
| |
| 61 return user_manager::UserManager::Get()->GetKnownUserDeviceId(user_id); | 61 return user_manager::UserManager::Get()->GetKnownUserDeviceId(user_id); |
| 62 } | 62 } |
| 63 | 63 |
| 64 std::string GetDeviceIdFromSigninClient(const std::string& user_id) { | 64 std::string GetDeviceIdFromSigninClient(const AccountId& user_id) { |
| 65 return ChromeSigninClientFactory::GetForProfile( | 65 return ChromeSigninClientFactory::GetForProfile( |
| 66 ProfileHelper::Get()->GetProfileByUser( | 66 ProfileHelper::Get()->GetProfileByUser( |
| 67 user_manager::UserManager::Get()->FindUser(user_id))) | 67 user_manager::UserManager::Get()->FindUser(user_id))) |
| 68 ->GetSigninScopedDeviceId(); | 68 ->GetSigninScopedDeviceId(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 std::string GetDeviceIdFromGAIA(const std::string& refresh_token) { | 71 std::string GetDeviceIdFromGAIA(const std::string& refresh_token) { |
| 72 return fake_gaia_->GetDeviceIdByRefreshToken(refresh_token); | 72 return fake_gaia_->GetDeviceIdByRefreshToken(refresh_token); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Checks that user's device ID retrieved from UserManager and SigninClient | 75 // Checks that user's device ID retrieved from UserManager and SigninClient |
| 76 // are the same. | 76 // are the same. |
| 77 // If |refresh_token| is not empty, checks that device ID associated with the | 77 // If |refresh_token| is not empty, checks that device ID associated with the |
| 78 // |refresh_token| in GAIA is the same as ID saved on device. | 78 // |refresh_token| in GAIA is the same as ID saved on device. |
| 79 void CheckDeviceIDIsConsistent(const std::string& user_id, | 79 void CheckDeviceIDIsConsistent(const AccountId& user_id, |
| 80 const std::string& refresh_token) { | 80 const std::string& refresh_token) { |
| 81 const std::string device_id_in_signin_client = | 81 const std::string device_id_in_signin_client = |
| 82 GetDeviceIdFromSigninClient(user_id); | 82 GetDeviceIdFromSigninClient(user_id); |
| 83 const std::string device_id_in_local_state = GetDeviceId(user_id); | 83 const std::string device_id_in_local_state = GetDeviceId(user_id); |
| 84 | 84 |
| 85 EXPECT_FALSE(device_id_in_signin_client.empty()); | 85 EXPECT_FALSE(device_id_in_signin_client.empty()); |
| 86 EXPECT_EQ(device_id_in_signin_client, device_id_in_local_state); | 86 EXPECT_EQ(device_id_in_signin_client, device_id_in_local_state); |
| 87 | 87 |
| 88 if (!refresh_token.empty()) { | 88 if (!refresh_token.empty()) { |
| 89 const std::string device_id_in_gaia = GetDeviceIdFromGAIA(refresh_token); | 89 const std::string device_id_in_gaia = GetDeviceIdFromGAIA(refresh_token); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 115 | 115 |
| 116 void SignInOffline(const std::string& user_id, const std::string& password) { | 116 void SignInOffline(const std::string& user_id, const std::string& password) { |
| 117 WaitForSigninScreen(); | 117 WaitForSigninScreen(); |
| 118 | 118 |
| 119 JS().ExecuteAsync( | 119 JS().ExecuteAsync( |
| 120 base::StringPrintf("chrome.send('authenticateUser', ['%s', '%s'])", | 120 base::StringPrintf("chrome.send('authenticateUser', ['%s', '%s'])", |
| 121 user_id.c_str(), password.c_str())); | 121 user_id.c_str(), password.c_str())); |
| 122 WaitForSessionStart(); | 122 WaitForSessionStart(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void RemoveUser(const std::string& user_id) { | 125 void RemoveUser(const AccountId& user_id) { |
| 126 user_manager::UserManager::Get()->RemoveUser(user_id, this); | 126 user_manager::UserManager::Get()->RemoveUser(user_id, this); |
| 127 user_removal_loop_.Run(); | 127 user_removal_loop_.Run(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 // user_manager::RemoveUserDelegate: | 131 // user_manager::RemoveUserDelegate: |
| 132 void OnBeforeUserRemoved(const std::string& username) override {} | 132 void OnBeforeUserRemoved(const std::string& username) override {} |
| 133 | 133 |
| 134 void OnUserRemoved(const std::string& username) override { | 134 void OnUserRemoved(const std::string& username) override { |
| 135 user_removal_loop_.Quit(); | 135 user_removal_loop_.Quit(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 json.c_str(), json.length())); | 169 json.c_str(), json.length())); |
| 170 } | 170 } |
| 171 | 171 |
| 172 base::RunLoop user_removal_loop_; | 172 base::RunLoop user_removal_loop_; |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 // Add the first user and check that device ID is consistent. | 175 // Add the first user and check that device ID is consistent. |
| 176 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_PRE_PRE_NewUsers) { | 176 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_PRE_PRE_NewUsers) { |
| 177 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, | 177 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, |
| 178 kFakeUserGaiaId); | 178 kFakeUserGaiaId); |
| 179 CheckDeviceIDIsConsistent(kFakeUserEmail, kRefreshToken1); | 179 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 180 kRefreshToken1); | |
| 180 } | 181 } |
| 181 | 182 |
| 182 // Authenticate the first user through GAIA and verify that device ID remains | 183 // Authenticate the first user through GAIA and verify that device ID remains |
| 183 // the same. | 184 // the same. |
| 184 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_PRE_NewUsers) { | 185 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_PRE_NewUsers) { |
| 185 const std::string device_id = GetDeviceId(kFakeUserEmail); | 186 const std::string device_id = |
| 187 GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)); | |
| 186 EXPECT_FALSE(device_id.empty()); | 188 EXPECT_FALSE(device_id.empty()); |
| 187 EXPECT_EQ(device_id, GetDeviceIdFromGAIA(kRefreshToken1)); | 189 EXPECT_EQ(device_id, GetDeviceIdFromGAIA(kRefreshToken1)); |
| 188 | 190 |
| 189 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken2, | 191 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken2, |
| 190 kFakeUserGaiaId); | 192 kFakeUserGaiaId); |
| 191 CheckDeviceIDIsConsistent(kFakeUserEmail, kRefreshToken2); | 193 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 194 kRefreshToken2); | |
| 192 | 195 |
| 193 CHECK_EQ(device_id, GetDeviceId(kFakeUserEmail)); | 196 CHECK_EQ(device_id, GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail))); |
| 194 } | 197 } |
| 195 | 198 |
| 196 // Authenticate the first user offline and verify that device ID remains | 199 // Authenticate the first user offline and verify that device ID remains |
| 197 // the same. | 200 // the same. |
| 198 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_NewUsers) { | 201 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_NewUsers) { |
| 199 const std::string device_id = GetDeviceId(kFakeUserEmail); | 202 const std::string device_id = |
| 203 GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)); | |
| 200 EXPECT_FALSE(device_id.empty()); | 204 EXPECT_FALSE(device_id.empty()); |
| 201 | 205 |
| 202 SignInOffline(kFakeUserEmail, kFakeUserPassword); | 206 SignInOffline(kFakeUserEmail, kFakeUserPassword); |
| 203 CheckDeviceIDIsConsistent(kFakeUserEmail, kRefreshToken2); | 207 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 208 kRefreshToken2); | |
| 204 | 209 |
| 205 // Verify that device ID remained the same after offline auth. | 210 // Verify that device ID remained the same after offline auth. |
| 206 CHECK_EQ(device_id, GetDeviceId(kFakeUserEmail)); | 211 CHECK_EQ(device_id, GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail))); |
| 207 } | 212 } |
| 208 | 213 |
| 209 // Add the second user. | 214 // Add the second user. |
| 210 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_NewUsers) { | 215 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_NewUsers) { |
| 211 WaitForSigninScreen(); | 216 WaitForSigninScreen(); |
| 212 JS().ExecuteAsync("chrome.send('showAddUser')"); | 217 JS().ExecuteAsync("chrome.send('showAddUser')"); |
| 213 SignInOnline(kSecondUserEmail, kSecondUserPassword, kSecondUserRefreshToken1, | 218 SignInOnline(kSecondUserEmail, kSecondUserPassword, kSecondUserRefreshToken1, |
| 214 kSecondUserGaiaId); | 219 kSecondUserGaiaId); |
| 215 CheckDeviceIDIsConsistent(kSecondUserEmail, kSecondUserRefreshToken1); | 220 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kSecondUserEmail), |
| 221 kSecondUserRefreshToken1); | |
| 216 } | 222 } |
| 217 | 223 |
| 218 // Remove the second user. | 224 // Remove the second user. |
| 219 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_NewUsers) { | 225 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_NewUsers) { |
| 220 WaitForSigninScreen(); | 226 WaitForSigninScreen(); |
| 221 RemoveUser(kSecondUserEmail); | 227 RemoveUser(AccountId::FromUserEmail(kSecondUserEmail)); |
| 222 } | 228 } |
| 223 | 229 |
| 224 // Add the second user back. Verify that device ID has been changed. | 230 // Add the second user back. Verify that device ID has been changed. |
| 225 IN_PROC_BROWSER_TEST_F(DeviceIDTest, NewUsers) { | 231 IN_PROC_BROWSER_TEST_F(DeviceIDTest, NewUsers) { |
| 226 EXPECT_TRUE(GetDeviceId(kSecondUserEmail).empty()); | 232 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kSecondUserEmail)).empty()); |
| 227 SignInOnline(kSecondUserEmail, kSecondUserPassword, kSecondUserRefreshToken2, | 233 SignInOnline(kSecondUserEmail, kSecondUserPassword, kSecondUserRefreshToken2, |
| 228 kSecondUserGaiaId); | 234 kSecondUserGaiaId); |
| 229 CheckDeviceIDIsConsistent(kSecondUserEmail, kSecondUserRefreshToken2); | 235 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kSecondUserEmail), |
| 236 kSecondUserRefreshToken2); | |
| 230 EXPECT_NE(GetDeviceIdFromGAIA(kSecondUserRefreshToken1), | 237 EXPECT_NE(GetDeviceIdFromGAIA(kSecondUserRefreshToken1), |
| 231 GetDeviceId(kSecondUserEmail)); | 238 GetDeviceId(AccountId::FromUserEmail(kSecondUserEmail))); |
| 232 } | 239 } |
| 233 | 240 |
| 234 // Set up a user that has a device ID stored in preference only. | 241 // Set up a user that has a device ID stored in preference only. |
| 235 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_Migration) { | 242 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_Migration) { |
| 236 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, | 243 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, |
| 237 kFakeUserGaiaId); | 244 kFakeUserGaiaId); |
| 238 | 245 |
| 239 // Simulate user that has device ID saved only in preferences (pre-M44). | 246 // Simulate user that has device ID saved only in preferences (pre-M44). |
| 240 PrefService* prefs = | 247 PrefService* prefs = |
| 241 ProfileHelper::Get() | 248 ProfileHelper::Get() |
| 242 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) | 249 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) |
| 243 ->GetPrefs(); | 250 ->GetPrefs(); |
| 244 prefs->SetString(prefs::kGoogleServicesSigninScopedDeviceId, | 251 prefs->SetString(prefs::kGoogleServicesSigninScopedDeviceId, |
| 245 GetDeviceId(kFakeUserEmail)); | 252 GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail))); |
| 246 | 253 |
| 247 // Can't use SetKnownUserDeviceId here, because it forbids changing a device | 254 // Can't use SetKnownUserDeviceId here, because it forbids changing a device |
| 248 // ID. | 255 // ID. |
| 249 user_manager::UserManager::Get()->SetKnownUserStringPref( | 256 user_manager::UserManager::Get()->SetKnownUserStringPref( |
| 250 kFakeUserEmail, "device_id", std::string()); | 257 AccountId::FromUserEmail(kFakeUserEmail), "device_id", std::string()); |
| 251 } | 258 } |
| 252 | 259 |
| 253 // Tests that after the first sign in the device ID has been moved to the Local | 260 // Tests that after the first sign in the device ID has been moved to the Local |
| 254 // state. | 261 // state. |
| 255 IN_PROC_BROWSER_TEST_F(DeviceIDTest, Migration) { | 262 IN_PROC_BROWSER_TEST_F(DeviceIDTest, Migration) { |
| 256 EXPECT_TRUE(GetDeviceId(kFakeUserEmail).empty()); | 263 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); |
| 257 SignInOffline(kFakeUserEmail, kFakeUserPassword); | 264 SignInOffline(kFakeUserEmail, kFakeUserPassword); |
| 258 CheckDeviceIDIsConsistent(kFakeUserEmail, kRefreshToken1); | 265 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 266 kRefreshToken1); | |
| 259 } | 267 } |
| 260 | 268 |
| 261 // Set up a user that doesn't have a device ID. | 269 // Set up a user that doesn't have a device ID. |
| 262 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_LegacyUsers) { | 270 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_LegacyUsers) { |
| 263 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, | 271 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, |
| 264 kFakeUserGaiaId); | 272 kFakeUserGaiaId); |
| 265 | 273 |
| 266 PrefService* prefs = | 274 PrefService* prefs = |
| 267 ProfileHelper::Get() | 275 ProfileHelper::Get() |
| 268 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) | 276 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) |
| 269 ->GetPrefs(); | 277 ->GetPrefs(); |
| 270 EXPECT_TRUE( | 278 EXPECT_TRUE( |
| 271 prefs->GetString(prefs::kGoogleServicesSigninScopedDeviceId).empty()); | 279 prefs->GetString(prefs::kGoogleServicesSigninScopedDeviceId).empty()); |
| 272 | 280 |
| 273 // Can't use SetKnownUserDeviceId here, because it forbids changing a device | 281 // Can't use SetKnownUserDeviceId here, because it forbids changing a device |
| 274 // ID. | 282 // ID. |
| 275 user_manager::UserManager::Get()->SetKnownUserStringPref( | 283 user_manager::UserManager::Get()->SetKnownUserStringPref( |
| 276 kFakeUserEmail, "device_id", std::string()); | 284 AccountId::FromUserEmail(kFakeUserEmail), "device_id", std::string()); |
| 277 } | 285 } |
| 278 | 286 |
| 279 // Tests that device ID has been generated after the first sign in. | 287 // Tests that device ID has been generated after the first sign in. |
| 280 IN_PROC_BROWSER_TEST_F(DeviceIDTest, LegacyUsers) { | 288 IN_PROC_BROWSER_TEST_F(DeviceIDTest, LegacyUsers) { |
| 281 EXPECT_TRUE(GetDeviceId(kFakeUserEmail).empty()); | 289 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); |
| 282 SignInOffline(kFakeUserEmail, kFakeUserPassword); | 290 SignInOffline(kFakeUserEmail, kFakeUserPassword); |
| 283 // Last param |auth_code| is empty, because we don't pass a device ID to GAIA | 291 // Last param |auth_code| is empty, because we don't pass a device ID to GAIA |
| 284 // in this case. | 292 // in this case. |
| 285 CheckDeviceIDIsConsistent(kFakeUserEmail, std::string()); | 293 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 294 std::string()); | |
| 286 } | 295 } |
| 287 | 296 |
| 288 } // namespace chromeos | 297 } // namespace chromeos |
| OLD | NEW |