diff --git a/internal/platform/implementation/account_manager.h b/internal/platform/implementation/account_manager.h index bf2e20f6..c462b45d 100644 --- a/internal/platform/implementation/account_manager.h +++ b/internal/platform/implementation/account_manager.h @@ -55,7 +55,7 @@ class AccountManager { // Gets current active account. If no login user, return std::nullopt. virtual std::optional GetCurrentAccount() = 0; - // Initializes the login process for a Google account. + // Initializes the login process for a Google account from 1P client. // |login_success_callback| is called when the login succeeded. Account // information is passed to callback. // |login_failure_callback| is called when the login fails. @@ -63,6 +63,17 @@ class AccountManager { absl::AnyInvocable login_success_callback, absl::AnyInvocable login_failure_callback) = 0; + // Initializes the login process for a Google account from an oauth client. + // |client_id| GCP client_id of the client + // |client_secret| GCP client_secret of the client + // |login_success_callback| is called when the login succeeded. Account + // information is passed to callback. + // |login_failure_callback| is called when the login fails. + virtual void Login( + absl::string_view client_id, absl::string_view client_secret, + absl::AnyInvocable login_success_callback, + absl::AnyInvocable login_failure_callback) = 0; + // Logs out current active account. |logout_callback| is called when logout is // completed. virtual void Logout( diff --git a/internal/test/fake_account_manager.cc b/internal/test/fake_account_manager.cc index 2ee7a3d3..dfb98f90 100644 --- a/internal/test/fake_account_manager.cc +++ b/internal/test/fake_account_manager.cc @@ -46,6 +46,22 @@ void FakeAccountManager::Login( login_failure_callback(absl::InternalError("No account.")); } +void FakeAccountManager::Login( + absl::string_view client_id, absl::string_view client_secret, + absl::AnyInvocable login_success_callback, + absl::AnyInvocable login_failure_callback) { + if (account_.has_value()) { + UpdateCurrentUser(account_->id); + NotifyLogin(account_->id); + // Invoke callback after all operations have been performed since test cases + // may rely on the callback for synchronization. + login_success_callback(*account_); + return; + } + + login_failure_callback(absl::InternalError("No account.")); +} + void FakeAccountManager::Logout( absl::AnyInvocable logout_callback) { if (is_logout_success_) { diff --git a/internal/test/fake_account_manager.h b/internal/test/fake_account_manager.h index 4da65b73..d53fa0c2 100644 --- a/internal/test/fake_account_manager.h +++ b/internal/test/fake_account_manager.h @@ -39,6 +39,11 @@ class FakeAccountManager : public AccountManager { absl::AnyInvocable login_success_callback, absl::AnyInvocable login_failure_callback) override; + void Login( + absl::string_view client_id, absl::string_view client_secret, + absl::AnyInvocable login_success_callback, + absl::AnyInvocable login_failure_callback) override; + void Logout(absl::AnyInvocable logout_callback) override; bool GetAccessToken( diff --git a/internal/test/mock_account_manager.h b/internal/test/mock_account_manager.h index 49746c25..41765c01 100644 --- a/internal/test/mock_account_manager.h +++ b/internal/test/mock_account_manager.h @@ -32,6 +32,11 @@ class MockAccountManager : public AccountManager { (absl::AnyInvocable login_success_callback, absl::AnyInvocable login_failure_callback), (override)); + MOCK_METHOD(void, Login, + (absl::string_view client_id, absl::string_view client_secret, + absl::AnyInvocable login_success_callback, + absl::AnyInvocable login_failure_callback), + (override)); MOCK_METHOD(void, Logout, (absl::AnyInvocable logout_callback), (override)); diff --git a/sharing/certificates/nearby_share_certificate_manager_impl_test.cc b/sharing/certificates/nearby_share_certificate_manager_impl_test.cc index feb6fcd4..da269b03 100644 --- a/sharing/certificates/nearby_share_certificate_manager_impl_test.cc +++ b/sharing/certificates/nearby_share_certificate_manager_impl_test.cc @@ -117,8 +117,9 @@ class NearbyShareCertificateManagerImplTest fake_account_manager_.SetAccount(account); - fake_account_manager_.Login([](AccountManager::Account account) {}, - [](absl::Status status) {}); + fake_account_manager_.Login( + "test_client_id", "test_client_secret", + [](AccountManager::Account account) {}, [](absl::Status status) {}); NearbyShareSchedulerFactory::SetFactoryForTesting(&scheduler_factory_); NearbyShareCertificateStorageImpl::Factory::SetFactoryForTesting( @@ -511,10 +512,10 @@ TEST_F(NearbyShareCertificateManagerImplTest, FastForward(GetNearbyShareTestNotBefore() + kNearbyShareCertificateValidityPeriod * 0.5 - Now()); - std::optional encrypted_metadata_key_everyone - = - cert_manager_->EncryptPrivateCertificateMetadataKey( - DeviceVisibility::DEVICE_VISIBILITY_EVERYONE); + std::optional + encrypted_metadata_key_everyone = + cert_manager_->EncryptPrivateCertificateMetadataKey( + DeviceVisibility::DEVICE_VISIBILITY_EVERYONE); EXPECT_EQ(GetNearbyShareTestEncryptedMetadataKey().encrypted_key(), encrypted_metadata_key_everyone->encrypted_key()); EXPECT_EQ(GetNearbyShareTestEncryptedMetadataKey().salt(), diff --git a/sharing/nearby_sharing_service_impl_test.cc b/sharing/nearby_sharing_service_impl_test.cc index 581e5cf3..6c0a186f 100644 --- a/sharing/nearby_sharing_service_impl_test.cc +++ b/sharing/nearby_sharing_service_impl_test.cc @@ -2174,6 +2174,7 @@ TEST_F(NearbySharingServiceImplTest, ValidateLoginStateWhenSettingVisibility) { absl::Notification login_notification; account_manager().SetAccount(account); service_->GetAccountManager()->Login( + "test_client_id", "test_client_secret", [&](AccountManager::Account account) { EXPECT_EQ(account.id, kTestAccountId); login_notification.Notify(); @@ -4467,6 +4468,7 @@ TEST_F(NearbySharingServiceImplTest, ObserveAccountLoginAndLogout) { account.id = kTestAccountId; account_manager().SetAccount(account); service_->GetAccountManager()->Login( + "test_client_id", "test_client_secret", [&](AccountManager::Account account) { EXPECT_EQ(account.id, kTestAccountId); notification.Notify(); @@ -4499,6 +4501,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) { absl::Notification login_notification; account_manager().SetAccount(account); service_->GetAccountManager()->Login( + "test_client_id", "test_client_secret", [&](AccountManager::Account account) { EXPECT_EQ(account.id, kTestAccountId); login_notification.Notify(); @@ -4536,6 +4539,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) { absl::Notification login_notification; account_manager().SetAccount(account); service_->GetAccountManager()->Login( + "test_client_id", "test_client_secret", [&](AccountManager::Account account) { EXPECT_EQ(account.id, kTestAccountId); login_notification.Notify(); @@ -4563,6 +4567,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) { absl::Notification login2_notification; account_manager().SetAccount(account); service_->GetAccountManager()->Login( + "test_client_id", "test_client_secret", [&](AccountManager::Account account) { EXPECT_EQ(account.id, kTestAccountId); login2_notification.Notify(); @@ -4605,6 +4610,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutNoStopRunningSurfaces) { account.id = kTestAccountId; account_manager().SetAccount(account); service_->GetAccountManager()->Login( + "test_client_id", "test_client_secret", [&](AccountManager::Account account) { EXPECT_EQ(account.id, kTestAccountId); notification.Notify();