0

Avoid unnecessary GaiaId casts in tests under /ash

This is achieved by adopting the test-only class GaiaId::Literal, which
allows constexpr instances for constants that represent Gaia IDs. This
also reduces the risk for bugs in tests or nonrealistic setups, as it is
hard to use strings other than Gaia IDs (such as e-mails) as gaia IDs,
and the other way round (use Gaia IDs accidentally to represent
something else).

Bug: 380416867
Change-Id: Idc1ad413c3de962e0d0a7d60f1d16870480013c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6207694
Reviewed-by: James Cook <jamescook@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1413133}
This commit is contained in:
Mikel Astiz
2025-01-29 13:20:22 -08:00
committed by Chromium LUCI CQ
parent 4bb5952778
commit 011bdbbd34
20 changed files with 63 additions and 74 deletions

@@ -66,8 +66,8 @@ class FakeSharedURLLoaderFactory : public network::SharedURLLoaderFactory {
} // namespace } // namespace
const char* TestAmbientClient::kTestGaiaId = "test_gaia_id"; const GaiaId::Literal TestAmbientClient::kTestGaiaId("test_gaia_id");
const char* TestAmbientClient::kTestAccessToken = "test_access_token"; const char TestAmbientClient::kTestAccessToken[] = "test_access_token";
TestAmbientClient::TestAmbientClient( TestAmbientClient::TestAmbientClient(
device::TestWakeLockProvider* wake_lock_provider) device::TestWakeLockProvider* wake_lock_provider)
@@ -120,7 +120,7 @@ void TestAmbientClient::IssueAccessToken(bool is_empty) {
/*expiration_time=*/base::Time::Now()); /*expiration_time=*/base::Time::Now());
} else { } else {
std::move(pending_callback_) std::move(pending_callback_)
.Run(GaiaId(kTestGaiaId), kTestAccessToken, .Run(kTestGaiaId, kTestAccessToken,
base::Time::Now() + kDefaultTokenExpirationDelay); base::Time::Now() + kDefaultTokenExpirationDelay);
} }
} }

@@ -9,6 +9,7 @@
#include "ash/public/cpp/ash_public_export.h" #include "ash/public/cpp/ash_public_export.h"
#include "base/functional/callback.h" #include "base/functional/callback.h"
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
#include "google_apis/gaia/gaia_id.h"
#include "services/device/public/cpp/test/test_wake_lock_provider.h" #include "services/device/public/cpp/test/test_wake_lock_provider.h"
namespace network { namespace network {
@@ -24,8 +25,8 @@ class ASH_PUBLIC_EXPORT TestAmbientClient : public AmbientClient {
explicit TestAmbientClient(device::TestWakeLockProvider* wake_lock_provider); explicit TestAmbientClient(device::TestWakeLockProvider* wake_lock_provider);
~TestAmbientClient() override; ~TestAmbientClient() override;
static const char* kTestGaiaId; static const GaiaId::Literal kTestGaiaId;
static const char* kTestAccessToken; static const char kTestAccessToken[];
// AmbientClient: // AmbientClient:
bool IsAmbientModeAllowed() override; bool IsAmbientModeAllowed() override;

@@ -33,7 +33,7 @@ namespace ash {
namespace { namespace {
constexpr char kUserEmail[] = "expected_email@example.com"; constexpr char kUserEmail[] = "expected_email@example.com";
constexpr char kFakeGaia[] = "fake_gaia"; constexpr GaiaId::Literal kFakeGaia("fake_gaia");
constexpr char kExpectedPassword[] = "expected_password"; constexpr char kExpectedPassword[] = "expected_password";
constexpr char kExpectedPin[] = "123456"; constexpr char kExpectedPin[] = "123456";
constexpr char kExpectedSalt[] = "test salt"; constexpr char kExpectedSalt[] = "test salt";
@@ -94,7 +94,7 @@ class ActiveSessionAuthControllerTest
} }
void AddUserToUserManager() { void AddUserToUserManager() {
account_id_ = AccountId::FromUserEmailGaiaId(kUserEmail, GaiaId(kFakeGaia)); account_id_ = AccountId::FromUserEmailGaiaId(kUserEmail, kFakeGaia);
user_manager_->AddGaiaUser(account_id_, user_manager::UserType::kRegular); user_manager_->AddGaiaUser(account_id_, user_manager::UserType::kRegular);
user_manager_->UserLoggedIn( user_manager_->UserLoggedIn(
account_id_, account_id_,

@@ -32,7 +32,7 @@ namespace ash {
namespace { namespace {
const char kTestAccount[] = "user@test.com"; const char kTestAccount[] = "user@test.com";
const char kFakeGaia[] = "fake_gaia"; const GaiaId::Literal kFakeGaia("fake_gaia");
const std::u16string title = u"title"; const std::u16string title = u"title";
const std::u16string description = u"description"; const std::u16string description = u"description";
@@ -56,7 +56,7 @@ class ActiveSessionAuthViewUnitTest : public AshTestBase {
std::make_unique<user_manager::FakeUserManager>(local_state()); std::make_unique<user_manager::FakeUserManager>(local_state());
AccountId account_id = AccountId account_id =
AccountId::FromUserEmailGaiaId(kTestAccount, GaiaId(kFakeGaia)); AccountId::FromUserEmailGaiaId(kTestAccount, kFakeGaia);
fake_user_manager->AddGaiaUser(account_id, fake_user_manager->AddGaiaUser(account_id,
user_manager::UserType::kRegular); user_manager::UserType::kRegular);
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>( scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(

@@ -24,7 +24,7 @@ namespace ash {
namespace { namespace {
constexpr char kUserEmail[] = "user1@gmail.com"; constexpr char kUserEmail[] = "user1@gmail.com";
constexpr char kFakeGaia[] = "fake_gaia"; constexpr GaiaId::Literal kFakeGaia("fake_gaia");
const std::u16string kTitle(u"Auth header view pixeltest title"); const std::u16string kTitle(u"Auth header view pixeltest title");
const std::u16string kErrorTitle(u"Auth header view pixeltest error"); const std::u16string kErrorTitle(u"Auth header view pixeltest error");
@@ -51,7 +51,7 @@ class AuthHeaderPixelTest : public AshTestBase {
auto fake_user_manager = auto fake_user_manager =
std::make_unique<user_manager::FakeUserManager>(local_state()); std::make_unique<user_manager::FakeUserManager>(local_state());
AccountId account_id = AccountId account_id =
AccountId::FromUserEmailGaiaId(kUserEmail, GaiaId(kFakeGaia)); AccountId::FromUserEmailGaiaId(kUserEmail, kFakeGaia);
fake_user_manager->AddGaiaUser(account_id, fake_user_manager->AddGaiaUser(account_id,
user_manager::UserType::kRegular); user_manager::UserType::kRegular);
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>( scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(

@@ -47,7 +47,7 @@ namespace {
using ::cryptohome::KeyLabel; using ::cryptohome::KeyLabel;
constexpr char kTestAccount[] = "user@test.com"; constexpr char kTestAccount[] = "user@test.com";
constexpr char kFakeGaia[] = "fake_gaia"; constexpr GaiaId::Literal kFakeGaia("fake_gaia");
constexpr char kExpectedPassword[] = "qwerty"; constexpr char kExpectedPassword[] = "qwerty";
class LocalAuthenticationRequestControllerImplPixelTest : public AshTestBase { class LocalAuthenticationRequestControllerImplPixelTest : public AshTestBase {
@@ -84,8 +84,7 @@ class LocalAuthenticationRequestControllerImplPixelTest : public AshTestBase {
UserDataAuthClient::InitializeFake(); UserDataAuthClient::InitializeFake();
SystemSaltGetter::Initialize(); SystemSaltGetter::Initialize();
test_account_id_ = test_account_id_ = AccountId::FromUserEmailGaiaId(kTestAccount, kFakeGaia);
AccountId::FromUserEmailGaiaId(kTestAccount, GaiaId(kFakeGaia));
SetExpectedCredentialsWithDbusClient(test_account_id_, kExpectedPassword); SetExpectedCredentialsWithDbusClient(test_account_id_, kExpectedPassword);

@@ -56,7 +56,7 @@ namespace {
using ::cryptohome::KeyLabel; using ::cryptohome::KeyLabel;
constexpr char kTestAccount[] = "user@test.com"; constexpr char kTestAccount[] = "user@test.com";
constexpr char kFakeGaia[] = "fake_gaia"; constexpr GaiaId::Literal kFakeGaia("fake_gaia");
constexpr char kExpectedPassword[] = "qwerty"; constexpr char kExpectedPassword[] = "qwerty";
constexpr char kExpectedPin[] = "150504"; constexpr char kExpectedPin[] = "150504";
@@ -85,8 +85,7 @@ class LocalAuthenticationRequestControllerImplTest : public LoginTestBase {
FakeCryptohomeMiscClient::GetStubSystemSalt()); FakeCryptohomeMiscClient::GetStubSystemSalt());
UserDataAuthClient::InitializeFake(); UserDataAuthClient::InitializeFake();
SystemSaltGetter::Initialize(); SystemSaltGetter::Initialize();
test_account_id_ = test_account_id_ = AccountId::FromUserEmailGaiaId(kTestAccount, kFakeGaia);
AccountId::FromUserEmailGaiaId(kTestAccount, GaiaId(kFakeGaia));
SetExpectedCredentialsWithDbusClient(test_account_id_, kExpectedPassword); SetExpectedCredentialsWithDbusClient(test_account_id_, kExpectedPassword);
@@ -434,8 +433,7 @@ class LocalAuthenticationWithPinControllerImplTest
FakeCryptohomeMiscClient::GetStubSystemSalt()); FakeCryptohomeMiscClient::GetStubSystemSalt());
UserDataAuthClient::InitializeFake(); UserDataAuthClient::InitializeFake();
SystemSaltGetter::Initialize(); SystemSaltGetter::Initialize();
test_account_id_ = test_account_id_ = AccountId::FromUserEmailGaiaId(kTestAccount, kFakeGaia);
AccountId::FromUserEmailGaiaId(kTestAccount, GaiaId(kFakeGaia));
SetExpectedCredentialsWithDbusClient(); SetExpectedCredentialsWithDbusClient();
fake_user_manager_.Reset( fake_user_manager_.Reset(

@@ -19,8 +19,9 @@ namespace ash {
namespace { namespace {
constexpr char kUser1[] = "user1@test.com"; constexpr char kUser1[] = "user1@test.com";
constexpr GaiaId::Literal kUser1GaiaId("11111");
const AccountId kAccountId1 = const AccountId kAccountId1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1)); AccountId::FromUserEmailGaiaId(kUser1, kUser1GaiaId);
const uint64_t kAssetId = 1; const uint64_t kAssetId = 1;
const uint64_t kUnitId = 1; const uint64_t kUnitId = 1;

@@ -41,7 +41,7 @@ namespace {
const char kUser[] = "user@gmail.com"; const char kUser[] = "user@gmail.com";
const AccountId kAccountId = const AccountId kAccountId =
AccountId::FromUserEmailGaiaId(kUser, GaiaId(kUser)); AccountId::FromUserEmailGaiaId(kUser, GaiaId("1111"));
const style::mojom::ColorScheme kLocalColorScheme = const style::mojom::ColorScheme kLocalColorScheme =
style::mojom::ColorScheme::kVibrant; style::mojom::ColorScheme::kVibrant;
const style::mojom::ColorScheme kDefaultColorScheme = const style::mojom::ColorScheme kDefaultColorScheme =

@@ -232,11 +232,11 @@ constexpr char kUserEmail1[] = "example1@abc.com";
constexpr char kUserEmail2[] = "joy@abc.com"; constexpr char kUserEmail2[] = "joy@abc.com";
constexpr char kUserEmail3[] = "joy1@abc.com"; constexpr char kUserEmail3[] = "joy1@abc.com";
const AccountId kAccountId1 = const AccountId kAccountId1 =
AccountId::FromUserEmailGaiaId(kUserEmail1, GaiaId(kUserEmail1)); AccountId::FromUserEmailGaiaId(kUserEmail1, GaiaId("1111"));
const AccountId kAccountId2 = const AccountId kAccountId2 =
AccountId::FromUserEmailGaiaId(kUserEmail2, GaiaId(kUserEmail2)); AccountId::FromUserEmailGaiaId(kUserEmail2, GaiaId("2222"));
const AccountId kAccountId3 = const AccountId kAccountId3 =
AccountId::FromUserEmailGaiaId(kUserEmail3, GaiaId(kUserEmail3)); AccountId::FromUserEmailGaiaId(kUserEmail3, GaiaId("3333"));
constexpr char kKbdTopRowPropertyName[] = "CROS_KEYBOARD_TOP_ROW_LAYOUT"; constexpr char kKbdTopRowPropertyName[] = "CROS_KEYBOARD_TOP_ROW_LAYOUT";
constexpr char kKbdTopRowLayoutUnspecified[] = ""; constexpr char kKbdTopRowLayoutUnspecified[] = "";

@@ -24,13 +24,11 @@
namespace ash { namespace ash {
namespace { namespace {
constexpr char kUser1[] = "user1@test.com";
const AccountId account_id_1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1));
constexpr char kUser2[] = "user2@test.com"; const AccountId account_id_1 =
AccountId::FromUserEmailGaiaId("user1@test.com", GaiaId("1111"));
const AccountId account_id_2 = const AccountId account_id_2 =
AccountId::FromUserEmailGaiaId(kUser2, GaiaId(kUser2)); AccountId::FromUserEmailGaiaId("user2@test.com", GaiaId("2222"));
// Creates an image of size |size|. // Creates an image of size |size|.
gfx::ImageSkia CreateImage(int width, int height, SkColor color) { gfx::ImageSkia CreateImage(int width, int height, SkColor color) {

@@ -20,7 +20,7 @@ namespace {
constexpr char kUser1[] = "user1@test.com"; constexpr char kUser1[] = "user1@test.com";
const AccountId account_id_1 = const AccountId account_id_1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1)); AccountId::FromUserEmailGaiaId(kUser1, GaiaId("1111"));
} // namespace } // namespace

@@ -30,7 +30,7 @@ using ::testing::UnorderedElementsAreArray;
constexpr char kUser1[] = "user1@test.com"; constexpr char kUser1[] = "user1@test.com";
const AccountId kAccount1 = const AccountId kAccount1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1)); AccountId::FromUserEmailGaiaId(kUser1, GaiaId::Literal("1111"));
constexpr char kDummyCollectionId[] = "testCollectionId"; constexpr char kDummyCollectionId[] = "testCollectionId";
// Returns a set of images with the given |type|. // Returns a set of images with the given |type|.

@@ -47,7 +47,7 @@ const std::string kUser1 = "user1@test.com";
constexpr std::string_view kExpectedMigrationFileContents = constexpr std::string_view kExpectedMigrationFileContents =
"migration_file_contents"; "migration_file_contents";
const AccountId kAccountId1 = const AccountId kAccountId1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1)); AccountId::FromUserEmailGaiaId(kUser1, GaiaId::Literal("gaia_id1"));
constexpr SkColor kDefaultImageColor = SkColorSetARGB(255, 31, 63, 127); constexpr SkColor kDefaultImageColor = SkColorSetARGB(255, 31, 63, 127);
SkBitmap CreateBitmap(SkColor color = kDefaultImageColor) { SkBitmap CreateBitmap(SkColor color = kDefaultImageColor) {
@@ -308,7 +308,7 @@ TEST_F(SeaPenWallpaperManagerTest, GetImageIdsMultipleAccounts) {
const std::string kUser2 = "user2@test.com"; const std::string kUser2 = "user2@test.com";
const AccountId kAccountId2 = const AccountId kAccountId2 =
AccountId::FromUserEmailGaiaId(kUser2, GaiaId(kUser2)); AccountId::FromUserEmailGaiaId(kUser2, GaiaId("gaia_id2"));
ASSERT_NE(kAccountId1.GetAccountIdKey(), kAccountId2.GetAccountIdKey()); ASSERT_NE(kAccountId1.GetAccountIdKey(), kAccountId2.GetAccountIdKey());
{ {
@@ -499,7 +499,7 @@ TEST_F(SeaPenWallpaperManagerTest, GetImageAndMetadataOtherAccount) {
{ {
// Try to retrieve the image with another account. // Try to retrieve the image with another account.
const AccountId other_account_id = AccountId::FromUserEmailGaiaId( const AccountId other_account_id = AccountId::FromUserEmailGaiaId(
"other_user@test.com", GaiaId("other_user@test.com")); "other_user@test.com", GaiaId("other_user_gaia_id"));
base::test::TestFuture<const gfx::ImageSkia&, base::test::TestFuture<const gfx::ImageSkia&,
personalization_app::mojom::RecentSeaPenImageInfoPtr> personalization_app::mojom::RecentSeaPenImageInfoPtr>
@@ -594,7 +594,7 @@ TEST_F(SeaPenWallpaperManagerTest, DeleteImageRemovesFromDisk) {
TEST_F(SeaPenWallpaperManagerTest, DeleteImageForOtherUserFails) { TEST_F(SeaPenWallpaperManagerTest, DeleteImageForOtherUserFails) {
constexpr uint32_t image_id = 999u; constexpr uint32_t image_id = 999u;
const AccountId other_account_id = AccountId::FromUserEmailGaiaId( const AccountId other_account_id = AccountId::FromUserEmailGaiaId(
"other_user@test.com", GaiaId("other_user@test.com")); "other_user@test.com", GaiaId("other_user_gaia_id"));
// Save a test image with the same id for both users. // Save a test image with the same id for both users.
for (const auto& account_id : {kAccountId1, other_account_id}) { for (const auto& account_id : {kAccountId1, other_account_id}) {

@@ -154,13 +154,13 @@ std::string GetDummyFileName(const AccountId& account_id) {
constexpr char kUser1[] = "user1@test.com"; constexpr char kUser1[] = "user1@test.com";
const AccountId kAccountId1 = const AccountId kAccountId1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1)); AccountId::FromUserEmailGaiaId(kUser1, GaiaId("1111"));
const std::string kWallpaperFilesId1 = GetDummyFileId(kAccountId1); const std::string kWallpaperFilesId1 = GetDummyFileId(kAccountId1);
const std::string kFileName1 = GetDummyFileName(kAccountId1); const std::string kFileName1 = GetDummyFileName(kAccountId1);
constexpr char kUser2[] = "user2@test.com"; constexpr char kUser2[] = "user2@test.com";
const AccountId kAccountId2 = const AccountId kAccountId2 =
AccountId::FromUserEmailGaiaId(kUser2, GaiaId(kUser2)); AccountId::FromUserEmailGaiaId(kUser2, GaiaId("2222"));
const std::string kWallpaperFilesId2 = GetDummyFileId(kAccountId2); const std::string kWallpaperFilesId2 = GetDummyFileId(kAccountId2);
const std::string kFileName2 = GetDummyFileName(kAccountId2); const std::string kFileName2 = GetDummyFileName(kAccountId2);
@@ -932,7 +932,7 @@ class WallpaperControllerTestBase : public AshTestBase {
raw_ptr<TestWallpaperDriveFsDelegate, DanglingUntriaged> drivefs_delegate_; raw_ptr<TestWallpaperDriveFsDelegate, DanglingUntriaged> drivefs_delegate_;
const AccountId kChildAccountId = const AccountId kChildAccountId =
AccountId::FromUserEmailGaiaId(kChildEmail, GaiaId(kChildEmail)); AccountId::FromUserEmailGaiaId(kChildEmail, GaiaId("child_gaia_id"));
private: private:
InProcessDataDecoder decoder_; InProcessDataDecoder decoder_;

@@ -37,7 +37,7 @@ using testing::Lt;
constexpr char kUser1[] = "user1@test.com"; constexpr char kUser1[] = "user1@test.com";
const AccountId account_id_1 = const AccountId account_id_1 =
AccountId::FromUserEmailGaiaId(kUser1, GaiaId(kUser1)); AccountId::FromUserEmailGaiaId(kUser1, GaiaId::Literal("1234"));
constexpr char kDummyUrl[] = "https://best_wallpaper/1"; constexpr char kDummyUrl[] = "https://best_wallpaper/1";
constexpr char kDummyUrl2[] = "https://best_wallpaper/2"; constexpr char kDummyUrl2[] = "https://best_wallpaper/2";

@@ -71,7 +71,7 @@ using ::testing::WithArg;
namespace ash::boca { namespace ash::boca {
namespace { namespace {
constexpr char kGaiaId[] = "123"; constexpr GaiaId::Literal kGaiaId("123");
constexpr char kUserEmail[] = "cat@gmail.com"; constexpr char kUserEmail[] = "cat@gmail.com";
constexpr char kWebviewHostName[] = "boca"; constexpr char kWebviewHostName[] = "boca";
@@ -267,8 +267,7 @@ class BocaAppPageHandlerTest : public testing::Test {
fake_user_manager_.Reset( fake_user_manager_.Reset(
std::make_unique<user_manager::FakeUserManager>(&local_state_)); std::make_unique<user_manager::FakeUserManager>(&local_state_));
auto account_id = auto account_id = AccountId::FromUserEmailGaiaId(kUserEmail, kGaiaId);
AccountId::FromUserEmailGaiaId(kUserEmail, GaiaId(kGaiaId));
auto browser_context_helper_delegate = auto browser_context_helper_delegate =
std::make_unique<ash::FakeBrowserContextHelperDelegate>(); std::make_unique<ash::FakeBrowserContextHelperDelegate>();
auto* browser_context_helper_delegate_ptr = auto* browser_context_helper_delegate_ptr =
@@ -407,7 +406,7 @@ TEST_F(BocaAppPageHandlerTest, CreateSessionWithFullInput) {
base::test::TestFuture<bool> future_1; base::test::TestFuture<bool> future_1;
::boca::UserIdentity teacher; ::boca::UserIdentity teacher;
teacher.set_gaia_id(kGaiaId); teacher.set_gaia_id(kGaiaId.ToString());
CreateSessionRequest request( CreateSessionRequest request(
nullptr, teacher, config->session_duration, nullptr, teacher, config->session_duration,
::boca::Session::SessionState::Session_SessionState_ACTIVE, ::boca::Session::SessionState::Session_SessionState_ACTIVE,
@@ -417,7 +416,7 @@ TEST_F(BocaAppPageHandlerTest, CreateSessionWithFullInput) {
// Unique pointer have ownership issue, have to do manual deep copy // Unique pointer have ownership issue, have to do manual deep copy
// here instead of using SaveArg. // here instead of using SaveArg.
Invoke([&](auto request) { Invoke([&](auto request) {
ASSERT_EQ(kGaiaId, request->teacher().gaia_id()); ASSERT_EQ(kGaiaId.ToString(), request->teacher().gaia_id());
ASSERT_EQ(session_duration, request->duration()); ASSERT_EQ(session_duration, request->duration());
ASSERT_EQ( ASSERT_EQ(
::boca::Session::SessionState::Session_SessionState_ACTIVE, ::boca::Session::SessionState::Session_SessionState_ACTIVE,
@@ -537,7 +536,7 @@ TEST_F(BocaAppPageHandlerTest, CreateSessionWithCritialInputOnly) {
mojom::OnTaskConfigPtr(nullptr), mojom::CaptionConfigPtr(nullptr), ""); mojom::OnTaskConfigPtr(nullptr), mojom::CaptionConfigPtr(nullptr), "");
::boca::UserIdentity teacher; ::boca::UserIdentity teacher;
teacher.set_gaia_id(kGaiaId); teacher.set_gaia_id(kGaiaId.ToString());
CreateSessionRequest request( CreateSessionRequest request(
nullptr, teacher, config->session_duration, nullptr, teacher, config->session_duration,
::boca::Session::SessionState::Session_SessionState_ACTIVE, ::boca::Session::SessionState::Session_SessionState_ACTIVE,
@@ -547,7 +546,7 @@ TEST_F(BocaAppPageHandlerTest, CreateSessionWithCritialInputOnly) {
// Unique pointer have ownership issue, have to do manual deep copy // Unique pointer have ownership issue, have to do manual deep copy
// here instead of using SaveArg. // here instead of using SaveArg.
Invoke([&](auto request) { Invoke([&](auto request) {
ASSERT_EQ(kGaiaId, request->teacher().gaia_id()); ASSERT_EQ(kGaiaId.ToString(), request->teacher().gaia_id());
ASSERT_EQ(session_duration, request->duration()); ASSERT_EQ(session_duration, request->duration());
ASSERT_EQ( ASSERT_EQ(
::boca::Session::SessionState::Session_SessionState_ACTIVE, ::boca::Session::SessionState::Session_SessionState_ACTIVE,
@@ -579,8 +578,7 @@ TEST_F(BocaAppPageHandlerTest, GetSessionWithFullInputTest) {
// API callback. // API callback.
base::test::TestFuture<mojom::SessionResultPtr> future_1; base::test::TestFuture<mojom::SessionResultPtr> future_1;
GetSessionRequest request(nullptr, false, GaiaId(kGaiaId), GetSessionRequest request(nullptr, false, kGaiaId, future.GetCallback());
future.GetCallback());
EXPECT_CALL(*session_client_impl(), GetSession(_)) EXPECT_CALL(*session_client_impl(), GetSession(_))
.WillOnce(WithArg<0>(Invoke([&](auto request) { .WillOnce(WithArg<0>(Invoke([&](auto request) {
auto session = std::make_unique<::boca::Session>(); auto session = std::make_unique<::boca::Session>();
@@ -712,8 +710,7 @@ TEST_F(BocaAppPageHandlerTest, GetSessionWithPartialInputTest) {
future; future;
// API callback. // API callback.
base::test::TestFuture<mojom::SessionResultPtr> future_1; base::test::TestFuture<mojom::SessionResultPtr> future_1;
GetSessionRequest request(nullptr, false, GaiaId(kGaiaId), GetSessionRequest request(nullptr, false, kGaiaId, future.GetCallback());
future.GetCallback());
EXPECT_CALL(*session_client_impl(), GetSession(_)) EXPECT_CALL(*session_client_impl(), GetSession(_))
.WillOnce(WithArg<0>(Invoke([&](auto request) { .WillOnce(WithArg<0>(Invoke([&](auto request) {
auto session = std::make_unique<::boca::Session>(); auto session = std::make_unique<::boca::Session>();
@@ -740,8 +737,7 @@ TEST_F(BocaAppPageHandlerTest, GetSessionWithHTTPError) {
// API callback. // API callback.
base::test::TestFuture<mojom::SessionResultPtr> future_1; base::test::TestFuture<mojom::SessionResultPtr> future_1;
GetSessionRequest request(nullptr, false, GaiaId(kGaiaId), GetSessionRequest request(nullptr, false, kGaiaId, future.GetCallback());
future.GetCallback());
EXPECT_CALL(*session_client_impl(), GetSession(_)) EXPECT_CALL(*session_client_impl(), GetSession(_))
.WillOnce(WithArg<0>(Invoke([&](auto request) { .WillOnce(WithArg<0>(Invoke([&](auto request) {
request->callback().Run( request->callback().Run(
@@ -765,8 +761,7 @@ TEST_F(BocaAppPageHandlerTest, GetSessionWithNullPtrInputTest) {
// API callback. // API callback.
base::test::TestFuture<mojom::SessionResultPtr> future_1; base::test::TestFuture<mojom::SessionResultPtr> future_1;
GetSessionRequest request(nullptr, false, GaiaId(kGaiaId), GetSessionRequest request(nullptr, false, kGaiaId, future.GetCallback());
future.GetCallback());
EXPECT_CALL(*session_client_impl(), GetSession(_)) EXPECT_CALL(*session_client_impl(), GetSession(_))
.WillOnce(WithArg<0>(Invoke( .WillOnce(WithArg<0>(Invoke(
[&](auto request) { request->callback().Run(base::ok(nullptr)); }))); [&](auto request) { request->callback().Run(base::ok(nullptr)); })));
@@ -789,8 +784,7 @@ TEST_F(BocaAppPageHandlerTest, GetSessionWithNonActiveSessionTest) {
future; future;
// API callback. // API callback.
base::test::TestFuture<mojom::SessionResultPtr> future_1; base::test::TestFuture<mojom::SessionResultPtr> future_1;
GetSessionRequest request(nullptr, false, GaiaId(kGaiaId), GetSessionRequest request(nullptr, false, kGaiaId, future.GetCallback());
future.GetCallback());
EXPECT_CALL(*session_client_impl(), GetSession(_)) EXPECT_CALL(*session_client_impl(), GetSession(_))
.WillOnce(WithArg<0>(Invoke([&](auto request) { .WillOnce(WithArg<0>(Invoke([&](auto request) {
request->callback().Run(std::make_unique<::boca::Session>()); request->callback().Run(std::make_unique<::boca::Session>());
@@ -815,8 +809,7 @@ TEST_F(BocaAppPageHandlerTest,
// API callback. // API callback.
base::test::TestFuture<mojom::SessionResultPtr> future_1; base::test::TestFuture<mojom::SessionResultPtr> future_1;
GetSessionRequest request(nullptr, false, GaiaId(kGaiaId), GetSessionRequest request(nullptr, false, kGaiaId, future.GetCallback());
future.GetCallback());
EXPECT_CALL(*session_client_impl(), GetSession(_)) EXPECT_CALL(*session_client_impl(), GetSession(_))
.WillOnce(WithArg<0>(Invoke([&](auto request) { .WillOnce(WithArg<0>(Invoke([&](auto request) {
auto session = std::make_unique<::boca::Session>(); auto session = std::make_unique<::boca::Session>();
@@ -852,7 +845,7 @@ TEST_F(BocaAppPageHandlerTest, EndSessionSucceed) {
base::test::TestFuture<std::optional<mojom::UpdateSessionError>> future_1; base::test::TestFuture<std::optional<mojom::UpdateSessionError>> future_1;
::boca::UserIdentity teacher; ::boca::UserIdentity teacher;
teacher.set_gaia_id(kGaiaId); teacher.set_gaia_id(kGaiaId.ToString());
UpdateSessionRequest request(nullptr, teacher, session_id, UpdateSessionRequest request(nullptr, teacher, session_id,
future.GetCallback()); future.GetCallback());
@@ -861,7 +854,7 @@ TEST_F(BocaAppPageHandlerTest, EndSessionSucceed) {
// Unique pointer have ownership issue, have to do manual deep copy // Unique pointer have ownership issue, have to do manual deep copy
// here instead of using SaveArg. // here instead of using SaveArg.
Invoke([&](auto request) { Invoke([&](auto request) {
ASSERT_EQ(kGaiaId, request->teacher().gaia_id()); ASSERT_EQ(kGaiaId.ToString(), request->teacher().gaia_id());
ASSERT_EQ(::boca::Session::PAST, *request->session_state()); ASSERT_EQ(::boca::Session::PAST, *request->session_state());
request->callback().Run(std::make_unique<::boca::Session>()); request->callback().Run(std::make_unique<::boca::Session>());
}))); })));
@@ -888,7 +881,7 @@ TEST_F(BocaAppPageHandlerTest, EndSessionWithHTTPFailure) {
base::test::TestFuture<std::optional<mojom::UpdateSessionError>> future_1; base::test::TestFuture<std::optional<mojom::UpdateSessionError>> future_1;
::boca::UserIdentity teacher; ::boca::UserIdentity teacher;
teacher.set_gaia_id(kGaiaId); teacher.set_gaia_id(kGaiaId.ToString());
UpdateSessionRequest request(nullptr, teacher, session_id, UpdateSessionRequest request(nullptr, teacher, session_id,
future.GetCallback()); future.GetCallback());
@@ -897,7 +890,7 @@ TEST_F(BocaAppPageHandlerTest, EndSessionWithHTTPFailure) {
// Unique pointer have ownership issue, have to do manual deep copy // Unique pointer have ownership issue, have to do manual deep copy
// here instead of using SaveArg. // here instead of using SaveArg.
Invoke([&](auto request) { Invoke([&](auto request) {
ASSERT_EQ(kGaiaId, request->teacher().gaia_id()); ASSERT_EQ(kGaiaId.ToString(), request->teacher().gaia_id());
ASSERT_EQ(::boca::Session::PAST, *request->session_state()); ASSERT_EQ(::boca::Session::PAST, *request->session_state());
request->callback().Run( request->callback().Run(
base::unexpected(google_apis::ApiErrorCode::HTTP_FORBIDDEN)); base::unexpected(google_apis::ApiErrorCode::HTTP_FORBIDDEN));
@@ -1497,7 +1490,7 @@ TEST_F(BocaAppPageHandlerTest, RemoveStudentSucceedAlsoRemoveFromLocalSession) {
// API callback. // API callback.
base::test::TestFuture<std::optional<mojom::RemoveStudentError>> future_1; base::test::TestFuture<std::optional<mojom::RemoveStudentError>> future_1;
RemoveStudentRequest request(nullptr, GaiaId(kGaiaId), session_id, RemoveStudentRequest request(nullptr, kGaiaId, session_id,
future.GetCallback()); future.GetCallback());
const char student_id[] = "4"; const char student_id[] = "4";
@@ -1506,7 +1499,7 @@ TEST_F(BocaAppPageHandlerTest, RemoveStudentSucceedAlsoRemoveFromLocalSession) {
// Unique pointer have ownership issue, have to do manual deep copy // Unique pointer have ownership issue, have to do manual deep copy
// here instead of using SaveArg. // here instead of using SaveArg.
Invoke([&](auto request) { Invoke([&](auto request) {
ASSERT_EQ(GaiaId(kGaiaId), request->gaia_id()); ASSERT_EQ(kGaiaId, request->gaia_id());
ASSERT_EQ(1u, request->student_ids().size()); ASSERT_EQ(1u, request->student_ids().size());
ASSERT_EQ(student_id, request->student_ids()[0]); ASSERT_EQ(student_id, request->student_ids()[0]);
request->callback().Run(true); request->callback().Run(true);
@@ -1534,7 +1527,7 @@ TEST_F(BocaAppPageHandlerTest, RemoveStudentWithHTTPFailure) {
// API callback. // API callback.
base::test::TestFuture<std::optional<mojom::RemoveStudentError>> future_1; base::test::TestFuture<std::optional<mojom::RemoveStudentError>> future_1;
RemoveStudentRequest request(nullptr, GaiaId(kGaiaId), session_id, RemoveStudentRequest request(nullptr, kGaiaId, session_id,
future.GetCallback()); future.GetCallback());
const char student_id[] = "id"; const char student_id[] = "id";
@@ -1543,7 +1536,7 @@ TEST_F(BocaAppPageHandlerTest, RemoveStudentWithHTTPFailure) {
// Unique pointer have ownership issue, have to do manual deep copy // Unique pointer have ownership issue, have to do manual deep copy
// here instead of using SaveArg. // here instead of using SaveArg.
Invoke([&](auto request) { Invoke([&](auto request) {
ASSERT_EQ(GaiaId(kGaiaId), request->gaia_id()); ASSERT_EQ(kGaiaId, request->gaia_id());
ASSERT_EQ(1u, request->student_ids().size()); ASSERT_EQ(1u, request->student_ids().size());
ASSERT_EQ(student_id, request->student_ids()[0]); ASSERT_EQ(student_id, request->student_ids()[0]);
request->callback().Run( request->callback().Run(

@@ -95,7 +95,7 @@ class FakeAccessibilityProviderProxy : public AccessibilityProviderProxy {
const char kFakeDeviceName[] = "Someone's Chromebook"; const char kFakeDeviceName[] = "Someone's Chromebook";
const char kFakeBoardName[] = "atlas"; const char kFakeBoardName[] = "atlas";
const char kFakeGaiaId[] = "123"; const GaiaId::Literal kFakeGaiaId("123");
const size_t kNumTestDevices = 3; const size_t kNumTestDevices = 3;
const char kFakeDeviceType[] = "Chromebook"; const char kFakeDeviceType[] = "Chromebook";
@@ -147,7 +147,7 @@ class EcheAppManagerTest : public AshTestBase {
SystemInfo::Builder() SystemInfo::Builder()
.SetDeviceName(kFakeDeviceName) .SetDeviceName(kFakeDeviceName)
.SetBoardName(kFakeBoardName) .SetBoardName(kFakeBoardName)
.SetGaiaId(GaiaId(kFakeGaiaId)) .SetGaiaId(kFakeGaiaId)
.SetDeviceType(kFakeDeviceType) .SetDeviceType(kFakeDeviceType)
.Build(), .Build(),
fake_phone_hub_manager_.get(), fake_device_sync_client_.get(), fake_phone_hub_manager_.get(), fake_device_sync_client_.get(),

@@ -28,7 +28,7 @@ const bool kFakeTabletMode = true;
const ConnectionStateType kFakeWifiConnectionState = const ConnectionStateType kFakeWifiConnectionState =
ConnectionStateType::kConnected; ConnectionStateType::kConnected;
const bool kFakeDebugMode = false; const bool kFakeDebugMode = false;
const char kFakeGaiaId[] = "123"; const GaiaId::Literal kFakeGaiaId("123");
const char kFakeDeviceType[] = "Chromebook"; const char kFakeDeviceType[] = "Chromebook";
const char kFakeOsVersion[] = "1.2.3.4"; const char kFakeOsVersion[] = "1.2.3.4";
const char kFakeChannel[] = "Dev"; const char kFakeChannel[] = "Dev";
@@ -213,7 +213,7 @@ class SystemInfoProviderTest : public testing::Test {
std::make_unique<SystemInfoProvider>(SystemInfo::Builder() std::make_unique<SystemInfoProvider>(SystemInfo::Builder()
.SetDeviceName(kFakeDeviceName) .SetDeviceName(kFakeDeviceName)
.SetBoardName(kFakeBoardName) .SetBoardName(kFakeBoardName)
.SetGaiaId(GaiaId(kFakeGaiaId)) .SetGaiaId(kFakeGaiaId)
.SetDeviceType(kFakeDeviceType) .SetDeviceType(kFakeDeviceType)
.SetOsVersion(kFakeOsVersion) .SetOsVersion(kFakeOsVersion)
.SetChannel(kFakeChannel) .SetChannel(kFakeChannel)
@@ -360,7 +360,7 @@ TEST_F(SystemInfoProviderTest, GetSystemInfoHasCorrectJson) {
EXPECT_EQ(tablet_mode, kFakeTabletMode); EXPECT_EQ(tablet_mode, kFakeTabletMode);
EXPECT_EQ(wifi_connection_state, "connected"); EXPECT_EQ(wifi_connection_state, "connected");
EXPECT_EQ(debug_mode, kFakeDebugMode); EXPECT_EQ(debug_mode, kFakeDebugMode);
EXPECT_EQ(gaia_id, kFakeGaiaId); EXPECT_EQ(gaia_id, kFakeGaiaId.ToString());
EXPECT_EQ(device_type, kFakeDeviceType); EXPECT_EQ(device_type, kFakeDeviceType);
EXPECT_EQ(os_version, kFakeOsVersion); EXPECT_EQ(os_version, kFakeOsVersion);
EXPECT_EQ(channel, kFakeChannel); EXPECT_EQ(channel, kFakeChannel);

@@ -32,7 +32,7 @@
namespace ash::graduation { namespace ash::graduation {
namespace { namespace {
constexpr char kUserGaiaId[] = "111"; constexpr GaiaId::Literal kUserGaiaId("111");
constexpr char kUserEmail[] = "user1test@gmail.com"; constexpr char kUserEmail[] = "user1test@gmail.com";
constexpr char kWebviewHostName[] = "graduation"; constexpr char kWebviewHostName[] = "graduation";
@@ -60,8 +60,7 @@ class GraduationUiHandlerTest : public testing::Test {
fake_user_manager_.Reset( fake_user_manager_.Reset(
std::make_unique<user_manager::FakeUserManager>(&local_state_)); std::make_unique<user_manager::FakeUserManager>(&local_state_));
auto account_id = auto account_id = AccountId::FromUserEmailGaiaId(kUserEmail, kUserGaiaId);
AccountId::FromUserEmailGaiaId(kUserEmail, GaiaId(kUserGaiaId));
auto* user = fake_user_manager_->AddGaiaUser( auto* user = fake_user_manager_->AddGaiaUser(
account_id, user_manager::UserType::kRegular); account_id, user_manager::UserType::kRegular);