chromium/third_party/blink/renderer/modules/credentialmanagement/credential_manager_type_converters_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/credentialmanagement/credential_manager_type_converters.h"

#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "mojo/public/cpp/bindings/type_converter.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/webauthn/authenticator.mojom-blink.h"
#include "third_party/blink/public/mojom/webid/federated_auth_request.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_client_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_client_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_large_blob_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_large_blob_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_values.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_supplemental_pub_keys_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_supplemental_pub_keys_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cable_authentication_data.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_credential_request_options_context.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_provider_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_remote_desktop_client_override.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace mojo {

V8Context;
RpContext;

const uint8_t kSample[] =;

static blink::V8UnionArrayBufferOrArrayBufferView* arrayBufferOrView(
    const uint8_t* data,
    size_t size);
static Vector<uint8_t> vectorOf(const uint8_t* data, size_t size);

TEST(CredentialManagerTypeConvertersTest, RpContextTest) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_appidNotSet) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_appidSetTrue) {}

#if BUILDFLAG(IS_ANDROID)
TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_userVerificationMethods) {
  auto mojo_type =
      blink::mojom::blink::AuthenticationExtensionsClientOutputs::New();
  mojo_type->echo_user_verification_methods = true;
  mojo_type->user_verification_methods =
      Vector<blink::mojom::blink::UvmEntryPtr>();
  mojo_type->user_verification_methods->emplace_back(
      blink::mojom::blink::UvmEntry::New(/*user_verification_method=*/1,
                                         /*key_protection_type=*/2,
                                         /*matcher_protection_type=*/3));
  mojo_type->user_verification_methods->emplace_back(
      blink::mojom::blink::UvmEntry::New(/*user_verification_method=*/4,
                                         /*key_protection_type=*/5,
                                         /*matcher_protection_type=*/6));

  auto* blink_type =
      ConvertTo<blink::AuthenticationExtensionsClientOutputs*>(mojo_type);

  EXPECT_TRUE(blink_type->hasUvm());
  EXPECT_THAT(blink_type->uvm(),
              ::testing::ElementsAre(Vector<uint32_t>{1, 2, 3},
                                     Vector<uint32_t>{4, 5, 6}));
}
#endif

MATCHER_P(DOMArrayBufferEqualTo, vector, "") {}

MATCHER_P(UnionDOMArrayBufferOrViewEqualTo, vector, "") {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_largeBlobEmpty) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_largeBlobRead) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_largeBlobWritten) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_credBlob) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_supplementalPubKeys) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_prf) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientOutputs_prfWithSecond) {}

TEST(CredentialManagerTypeConvertersTest,
     PublicKeyCredentialRequestOptions_extensions) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_appid) {}

#if BUILDFLAG(IS_ANDROID)
TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_uvm) {
  blink::AuthenticationExtensionsClientInputs* blink_type =
      blink::AuthenticationExtensionsClientInputs::Create();
  blink_type->setUvm(true);

  blink::mojom::blink::AuthenticationExtensionsClientInputsPtr mojo_type =
      ConvertTo<blink::mojom::blink::AuthenticationExtensionsClientInputsPtr>(
          *blink_type);

  ASSERT_EQ(mojo_type->user_verification_methods, true);
}
#endif

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_largeBlobWrite) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_largeBlobRead) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_hasCredBlob) {}

blink::RemoteDesktopClientOverride* blinkRemoteDesktopOverride(String origin) {}

blink::mojom::blink::RemoteDesktopClientOverridePtr mojoRemoteDesktopOverride(
    String origin_string) {}

const char* kSampleOrigin =;

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_remoteDesktopClientOverride) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_supplementalPubKeys) {}

TEST(CredentialManagerTypeConvertersTest,
     AuthenticationExtensionsClientInputsTest_prfInputs) {}

static blink::V8UnionArrayBufferOrArrayBufferView* arrayBufferOrView(
    const uint8_t* data,
    size_t size) {}

static Vector<uint8_t> vectorOf(const uint8_t* data, size_t size) {}

// Crash test for crbug.com/347715555.
TEST(CredentialManagerTypeConvertersTest, NoClientId) {}

}  // namespace mojo