chromium/chrome/browser/password_manager/chrome_webauthn_credentials_delegate_unittest.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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  // !BUILDFLAG(IS_ANDROID)

#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 =;

}  // namespace

class ChromeWebAuthnCredentialsDelegateTest
    : public ChromeRenderViewHostTestHarness {};

// Testing retrieving passkeys when there are 2 public key credentials
// present.
TEST_F(ChromeWebAuthnCredentialsDelegateTest, RetrieveCredentials) {}

TEST_F(ChromeWebAuthnCredentialsDelegateTest,
       DontOfferPasskeysFromAnotherDevice) {}

// Testing retrieving suggestions when the credentials are not received until
// afterward.
TEST_F(ChromeWebAuthnCredentialsDelegateTest, RetrieveCredentialsDelayed) {}

// Testing retrieving suggestions when there are no public key credentials
// present.
TEST_F(ChromeWebAuthnCredentialsDelegateTest,
       RetrieveCredentialsWithEmptyList) {}

// Testing selection of a credential.
TEST_F(ChromeWebAuthnCredentialsDelegateTest, SelectCredential) {}

// Test aborting a request.
TEST_F(ChromeWebAuthnCredentialsDelegateTest, AbortRequest) {}

// Test aborting a request when a retrieve suggestions callback is pending.
TEST_F(ChromeWebAuthnCredentialsDelegateTest, AbortRequestPendingCallback) {}

#if !BUILDFLAG(IS_ANDROID)
TEST_F(ChromeWebAuthnCredentialsDelegateTest,
       OnStepTransitionCallbackOtherSource) {}

class GpmPasskeyChromeWebAuthnCredentialsDelegateTest
    : public ChromeWebAuthnCredentialsDelegateTest {};

// Regression test for crbug.com/346263461.
TEST_F(GpmPasskeyChromeWebAuthnCredentialsDelegateTest,
       IgnoreRepeatedSelectPasskey) {}

TEST_F(GpmPasskeyChromeWebAuthnCredentialsDelegateTest,
       OnStepTransitionCallbackGpmSource) {}

TEST_F(GpmPasskeyChromeWebAuthnCredentialsDelegateTest,
       OnStepTransitionCallbackGpmSourceAndUiNotDisabled) {}
#endif  // !BUILDFLAG(IS_ANDROID)

#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  // BUILDFLAG(IS_ANDROID)