| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 13 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
| 14 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 14 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 15 #include "chrome/browser/chromeos/login/ui/oobe_display.h" | 15 #include "chrome/browser/chromeos/login/ui/oobe_display.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 17 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 17 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 21 #include "components/signin/core/common/signin_pref_names.h" | 21 #include "components/signin/core/common/signin_pref_names.h" |
| 22 #include "components/user_manager/known_user.h" |
| 22 #include "components/user_manager/remove_user_delegate.h" | 23 #include "components/user_manager/remove_user_delegate.h" |
| 23 #include "components/user_manager/user_manager.h" | 24 #include "components/user_manager/user_manager.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 char kRefreshToken1[] = "refresh_token_1"; | 28 char kRefreshToken1[] = "refresh_token_1"; |
| 28 char kRefreshToken2[] = "refresh_token_2"; | 29 char kRefreshToken2[] = "refresh_token_2"; |
| 29 const base::FilePath::CharType kRefreshTokenToDeviceIdMapFile[] = | 30 const base::FilePath::CharType kRefreshTokenToDeviceIdMapFile[] = |
| 30 FILE_PATH_LITERAL("refrest_token_to_device_id.json"); | 31 FILE_PATH_LITERAL("refrest_token_to_device_id.json"); |
| 31 | 32 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 OobeBaseTest::SetUpOnMainThread(); | 52 OobeBaseTest::SetUpOnMainThread(); |
| 52 LoadRefreshTokenToDeviceIdMap(); | 53 LoadRefreshTokenToDeviceIdMap(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void TearDownOnMainThread() override { | 56 void TearDownOnMainThread() override { |
| 56 SaveRefreshTokenToDeviceIdMap(); | 57 SaveRefreshTokenToDeviceIdMap(); |
| 57 OobeBaseTest::TearDownOnMainThread(); | 58 OobeBaseTest::TearDownOnMainThread(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 std::string GetDeviceId(const AccountId& account_id) { | 61 std::string GetDeviceId(const AccountId& account_id) { |
| 61 return user_manager::UserManager::Get()->GetKnownUserDeviceId(account_id); | 62 return user_manager::known_user::GetKnownUserDeviceId(account_id); |
| 62 } | 63 } |
| 63 | 64 |
| 64 std::string GetDeviceIdFromSigninClient(const AccountId& account_id) { | 65 std::string GetDeviceIdFromSigninClient(const AccountId& account_id) { |
| 65 return ChromeSigninClientFactory::GetForProfile( | 66 return ChromeSigninClientFactory::GetForProfile( |
| 66 ProfileHelper::Get()->GetProfileByUser( | 67 ProfileHelper::Get()->GetProfileByUser( |
| 67 user_manager::UserManager::Get()->FindUser(account_id))) | 68 user_manager::UserManager::Get()->FindUser(account_id))) |
| 68 ->GetSigninScopedDeviceId(); | 69 ->GetSigninScopedDeviceId(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 std::string GetDeviceIdFromGAIA(const std::string& refresh_token) { | 72 std::string GetDeviceIdFromGAIA(const std::string& refresh_token) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // Simulate user that has device ID saved only in preferences (pre-M44). | 247 // Simulate user that has device ID saved only in preferences (pre-M44). |
| 247 PrefService* prefs = | 248 PrefService* prefs = |
| 248 ProfileHelper::Get() | 249 ProfileHelper::Get() |
| 249 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) | 250 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) |
| 250 ->GetPrefs(); | 251 ->GetPrefs(); |
| 251 prefs->SetString(prefs::kGoogleServicesSigninScopedDeviceId, | 252 prefs->SetString(prefs::kGoogleServicesSigninScopedDeviceId, |
| 252 GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail))); | 253 GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail))); |
| 253 | 254 |
| 254 // Can't use SetKnownUserDeviceId here, because it forbids changing a device | 255 // Can't use SetKnownUserDeviceId here, because it forbids changing a device |
| 255 // ID. | 256 // ID. |
| 256 user_manager::UserManager::Get()->SetKnownUserStringPref( | 257 user_manager::known_user::SetKnownUserStringPref( |
| 257 AccountId::FromUserEmail(kFakeUserEmail), "device_id", std::string()); | 258 AccountId::FromUserEmail(kFakeUserEmail), "device_id", std::string()); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // Tests that after the first sign in the device ID has been moved to the Local | 261 // Tests that after the first sign in the device ID has been moved to the Local |
| 261 // state. | 262 // state. |
| 262 IN_PROC_BROWSER_TEST_F(DeviceIDTest, Migration) { | 263 IN_PROC_BROWSER_TEST_F(DeviceIDTest, Migration) { |
| 263 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); | 264 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); |
| 264 SignInOffline(kFakeUserEmail, kFakeUserPassword); | 265 SignInOffline(kFakeUserEmail, kFakeUserPassword); |
| 265 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), | 266 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 266 kRefreshToken1); | 267 kRefreshToken1); |
| 267 } | 268 } |
| 268 | 269 |
| 269 // Set up a user that doesn't have a device ID. | 270 // Set up a user that doesn't have a device ID. |
| 270 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_LegacyUsers) { | 271 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_LegacyUsers) { |
| 271 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, | 272 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, |
| 272 kFakeUserGaiaId); | 273 kFakeUserGaiaId); |
| 273 | 274 |
| 274 PrefService* prefs = | 275 PrefService* prefs = |
| 275 ProfileHelper::Get() | 276 ProfileHelper::Get() |
| 276 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) | 277 ->GetProfileByUser(user_manager::UserManager::Get()->GetActiveUser()) |
| 277 ->GetPrefs(); | 278 ->GetPrefs(); |
| 278 EXPECT_TRUE( | 279 EXPECT_TRUE( |
| 279 prefs->GetString(prefs::kGoogleServicesSigninScopedDeviceId).empty()); | 280 prefs->GetString(prefs::kGoogleServicesSigninScopedDeviceId).empty()); |
| 280 | 281 |
| 281 // Can't use SetKnownUserDeviceId here, because it forbids changing a device | 282 // Can't use SetKnownUserDeviceId here, because it forbids changing a device |
| 282 // ID. | 283 // ID. |
| 283 user_manager::UserManager::Get()->SetKnownUserStringPref( | 284 user_manager::known_user::SetKnownUserStringPref( |
| 284 AccountId::FromUserEmail(kFakeUserEmail), "device_id", std::string()); | 285 AccountId::FromUserEmail(kFakeUserEmail), "device_id", std::string()); |
| 285 } | 286 } |
| 286 | 287 |
| 287 // Tests that device ID has been generated after the first sign in. | 288 // Tests that device ID has been generated after the first sign in. |
| 288 IN_PROC_BROWSER_TEST_F(DeviceIDTest, LegacyUsers) { | 289 IN_PROC_BROWSER_TEST_F(DeviceIDTest, LegacyUsers) { |
| 289 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); | 290 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); |
| 290 SignInOffline(kFakeUserEmail, kFakeUserPassword); | 291 SignInOffline(kFakeUserEmail, kFakeUserPassword); |
| 291 // Last param |auth_code| is empty, because we don't pass a device ID to GAIA | 292 // Last param |auth_code| is empty, because we don't pass a device ID to GAIA |
| 292 // in this case. | 293 // in this case. |
| 293 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), | 294 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
| 294 std::string()); | 295 std::string()); |
| 295 } | 296 } |
| 296 | 297 |
| 297 } // namespace chromeos | 298 } // namespace chromeos |
| OLD | NEW |