#include "chrome/browser/password_manager/chrome_webauthn_credentials_delegate.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/base64.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/mock_callback.h"
#include "base/test/test_future.h"
#include "chrome/browser/password_manager/chrome_webauthn_credentials_delegate_factory.h"
#include "chrome/browser/webauthn/authenticator_request_dialog_model.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/password_manager/core/browser/passkey_credential.h"
#include "components/password_manager/core/browser/webauthn_credentials_delegate.h"
#include "content/public/test/web_contents_tester.h"
#include "device/fido/discoverable_credential_metadata.h"
#include "device/fido/fido_parsing_utils.h"
#include "device/fido/fido_types.h"
#include "device/fido/public_key_credential_user_entity.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if !BUILDFLAG(IS_ANDROID)
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "chrome/browser/webauthn/authenticator_request_dialog_controller.h"
#include "chrome/browser/webauthn/authenticator_request_dialog_model.h"
#include "chrome/browser/webauthn/authenticator_request_scheduler.h"
#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
#include "device/fido/features.h"
#include "device/fido/fido_request_handler_base.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "base/memory/raw_ptr.h"
#include "chrome/browser/webauthn/android/webauthn_request_delegate_android.h"
#endif
namespace {
PasskeyCredential;
OnPasskeySelectedCallback;
constexpr uint8_t kUserId[] = …;
constexpr char kUserName1[] = …;
constexpr char kUserName2[] = …;
constexpr uint8_t kCredId1[] = …;
constexpr uint8_t kCredId2[] = …;
constexpr uint8_t kCredIdGpm[] = …;
constexpr char kRpId[] = …;
const device::DiscoverableCredentialMetadata user1{ … };
const device::DiscoverableCredentialMetadata user2{ … };
const device::DiscoverableCredentialMetadata userGpm{ … };
PasskeyCredential CreatePasskey(std::vector<uint8_t> cred_id,
std::string username,
PasskeyCredential::Source source =
PasskeyCredential::Source::kAndroidPhone) { … }
const PasskeyCredential passkey1 = …;
const PasskeyCredential passkey2 = …;
const PasskeyCredential passkeyGpm = …;
}
class ChromeWebAuthnCredentialsDelegateTest
: public ChromeRenderViewHostTestHarness { … };
TEST_F(ChromeWebAuthnCredentialsDelegateTest, RetrieveCredentials) { … }
TEST_F(ChromeWebAuthnCredentialsDelegateTest,
DontOfferPasskeysFromAnotherDevice) { … }
TEST_F(ChromeWebAuthnCredentialsDelegateTest, RetrieveCredentialsDelayed) { … }
TEST_F(ChromeWebAuthnCredentialsDelegateTest,
RetrieveCredentialsWithEmptyList) { … }
TEST_F(ChromeWebAuthnCredentialsDelegateTest, SelectCredential) { … }
TEST_F(ChromeWebAuthnCredentialsDelegateTest, AbortRequest) { … }
TEST_F(ChromeWebAuthnCredentialsDelegateTest, AbortRequestPendingCallback) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(ChromeWebAuthnCredentialsDelegateTest,
OnStepTransitionCallbackOtherSource) { … }
class GpmPasskeyChromeWebAuthnCredentialsDelegateTest
: public ChromeWebAuthnCredentialsDelegateTest { … };
TEST_F(GpmPasskeyChromeWebAuthnCredentialsDelegateTest,
IgnoreRepeatedSelectPasskey) { … }
TEST_F(GpmPasskeyChromeWebAuthnCredentialsDelegateTest,
OnStepTransitionCallbackGpmSource) { … }
TEST_F(GpmPasskeyChromeWebAuthnCredentialsDelegateTest,
OnStepTransitionCallbackGpmSourceAndUiNotDisabled) { … }
#endif
#if BUILDFLAG(IS_ANDROID)
TEST_F(ChromeWebAuthnCredentialsDelegateTest, AndroidHybridAvailability) {
EXPECT_FALSE(credentials_delegate()->IsAndroidHybridAvailable());
credentials_delegate()->SetAndroidHybridAvailable(
ChromeWebAuthnCredentialsDelegate::AndroidHybridAvailable(true));
EXPECT_TRUE(credentials_delegate()->IsAndroidHybridAvailable());
}
#endif