Commit 3419b503 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Convert enterprise_platform_keys_api_unittest.cc to the Identity service

It was using the SigninManager to set the authenticated (primary)
account. Replaced by a call to the identity API.

Bug: 903863
Change-Id: Ib82685ddd13e907d8f318e3079207763fd3c9f51
Reviewed-on: https://chromium-review.googlesource.com/c/1348329
Commit-Queue: Sergio Villar <svillar@igalia.com>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610805}
parent de60a40b
......@@ -17,7 +17,7 @@
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chrome/browser/chromeos/settings/stub_install_attributes.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h"
......@@ -33,9 +33,9 @@
#include "components/account_id/account_id.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/user_manager/scoped_user_manager.h"
#include "extensions/common/extension_builder.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
......@@ -174,8 +174,9 @@ class EPKChallengeKeyTestBase : public BrowserWithTestWindowTest {
// Derived classes can override this method to set the required authenticated
// user in the SigninManager class.
virtual void SetAuthenticatedUser() {
SigninManagerFactory::GetForProfile(browser()->profile())
->SetAuthenticatedAccountInfo("12345", kUserEmail);
identity::MakePrimaryAccountAvailable(
IdentityManagerFactory::GetForProfile(browser()->profile()),
kUserEmail);
}
// Like extension_function_test_utils::RunFunctionAndReturnError but with an
......@@ -587,9 +588,9 @@ class EPKChallengeMachineKeyUnmanagedUserTest
: public EPKChallengeMachineKeyTest {
protected:
void SetAuthenticatedUser() override {
SigninManagerFactory::GetForProfile(browser()->profile())
->SetAuthenticatedAccountInfo(account_id_.GetGaiaId(),
account_id_.GetUserEmail());
identity::MakePrimaryAccountAvailable(
IdentityManagerFactory::GetForProfile(browser()->profile()),
account_id_.GetUserEmail());
}
TestingProfile* CreateProfile() override {
......@@ -597,8 +598,10 @@ class EPKChallengeMachineKeyUnmanagedUserTest
return profile_manager()->CreateTestingProfile(account_id_.GetUserEmail());
}
const std::string email = "test@chromium.com";
const AccountId account_id_ =
AccountId::FromUserEmailGaiaId("test@chromium.com", "12345");
AccountId::FromUserEmailGaiaId(email,
identity::GetTestGaiaIdForEmail(email));
};
TEST_F(EPKChallengeMachineKeyUnmanagedUserTest, UserNotManaged) {
......@@ -609,9 +612,9 @@ TEST_F(EPKChallengeMachineKeyUnmanagedUserTest, UserNotManaged) {
class EPKChallengeUserKeyUnmanagedUserTest : public EPKChallengeUserKeyTest {
protected:
void SetAuthenticatedUser() override {
SigninManagerFactory::GetForProfile(browser()->profile())
->SetAuthenticatedAccountInfo(account_id_.GetGaiaId(),
account_id_.GetUserEmail());
identity::MakePrimaryAccountAvailable(
IdentityManagerFactory::GetForProfile(browser()->profile()),
account_id_.GetUserEmail());
}
TestingProfile* CreateProfile() override {
......@@ -619,8 +622,10 @@ class EPKChallengeUserKeyUnmanagedUserTest : public EPKChallengeUserKeyTest {
return profile_manager()->CreateTestingProfile(account_id_.GetUserEmail());
}
const std::string email = "test@chromium.com";
const AccountId account_id_ =
AccountId::FromUserEmailGaiaId("test@chromium.com", "12345");
AccountId::FromUserEmailGaiaId(email,
identity::GetTestGaiaIdForEmail(email));
};
TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) {
......
......@@ -127,16 +127,6 @@ void UpdateRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
run_loop.Run();
}
std::string GetTestGaiaIdForEmail(const std::string& email) {
std::string gaia_id =
std::string("gaia_id_for_") + gaia::CanonicalizeEmail(email);
// Avoid character '@' in the gaia ID string as there is code in the codebase
// that asserts that a gaia ID does not contain a "@" character.
std::replace(gaia_id.begin(), gaia_id.end(), '@', '_');
return gaia_id;
}
} // namespace
AccountInfo SetPrimaryAccount(IdentityManager* identity_manager,
......@@ -345,4 +335,13 @@ void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
account_tracker_service->SeedAccountInfo(account_info);
}
std::string GetTestGaiaIdForEmail(const std::string& email) {
std::string gaia_id =
std::string("gaia_id_for_") + gaia::CanonicalizeEmail(email);
// Avoid character '@' in the gaia ID string as there is code in the codebase
// that asserts that a gaia ID does not contain a "@" character.
std::replace(gaia_id.begin(), gaia_id.end(), '@', '_');
return gaia_id;
}
} // namespace identity
......@@ -125,6 +125,8 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager,
void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
AccountInfo account_info);
std::string GetTestGaiaIdForEmail(const std::string& email);
} // namespace identity
#endif // SERVICES_IDENTITY_PUBLIC_CPP_IDENTITY_TEST_UTILS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment