// third_party/blink/public/mojom/credentialmanagement/credential_manager.mojom.MojoProfile.swift is auto generated by mojom_bindings_generator.py, do not edit

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

// This file is autogenerated by:
//     mojo/public/tools/bindings/generators/mojom_fuzzilli_generator.py
// For:
//     third_party/blink/public/mojom/credentialmanagement/credential_manager.mojom
//

private let mojoPrefix = "blink.mojom."

///
/// Interfaces
///
extension ILType {
    // CredentialManager
    fileprivate static let jsBlinkMojomCredentialManagerRemote: ILType = .object(
        ofGroup: "blink.mojom.CredentialManagerRemote",
        withProperties: ["$"],
        withMethods: [
            "store",
            "preventSilentAccess",
            "get",
        ])
    fileprivate static let jsBlinkMojomCredentialManagerRemoteWrapper: ILType = .object(
        ofGroup: "blink.mojom.CredentialManagerRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsBlinkMojomCredentialManagerPendingReceiver: ILType = .object(
        ofGroup: "blink.mojom.CredentialManagerPendingReceiver")
}

extension ObjectGroup {
    // CredentialManager
    fileprivate static let blinkMojomCredentialManagerRemote = ObjectGroup(
        name: "blink.mojom.CredentialManagerRemote",
        instanceType: .jsBlinkMojomCredentialManagerRemote,
        properties: ["$": .jsBlinkMojomCredentialManagerRemoteWrapper],
        methods: [
            "store": [
                .plain(.jsBlinkMojomCredentialInfo),
            ] => .jsPromise(resolvingTo: .jsBlinkMojomCredentialManager_Store_ResponseParams),
            "preventSilentAccess": [
            ] => .jsPromise(resolvingTo: .jsBlinkMojomCredentialManager_PreventSilentAccess_ResponseParams),
            "get": [
                .plain(.jsBlinkMojomCredentialMediationRequirement),
                .plain(.boolean),
                .plain(.jsUrlMojomUrlArray),
            ] => .jsPromise(resolvingTo: .jsBlinkMojomCredentialManager_Get_ResponseParams),
        ]
    )

    fileprivate static let blinkMojomCredentialManagerRemoteWrapper = ObjectGroup(
        name: "blink.mojom.CredentialManagerRemoteWrapper",
        instanceType: .jsBlinkMojomCredentialManagerRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsBlinkMojomCredentialManagerPendingReceiver,
        ]
    )

    fileprivate static let blinkMojomCredentialManagerPendingReceiver = ObjectGroup(
        name: "blink.mojom.CredentialManagerPendingReceiver",
        instanceType: .jsBlinkMojomCredentialManagerPendingReceiver,
        properties: [:],
        methods: [:]
    )
}

///
/// Structs
///
extension ILType {
    fileprivate static let jsBlinkMojomCredentialInfo: ILType = .object(
        ofGroup: "blink.mojom.CredentialInfo",
        withProperties: [
            "type",
            "id",
            "name",
            "icon",
            "password",
            "federation",
        ])
    fileprivate static let jsBlinkMojomCredentialInfoConstructor: ILType = .constructor([
        .plain(.jsBlinkMojomCredentialType),
        .either(.jsMojoBaseMojomString16, .undefined),
        .either(.jsMojoBaseMojomString16, .undefined),
        .plain(.jsUrlMojomUrl),
        .either(.jsMojoBaseMojomString16, .undefined),
        .plain(.jsUrlMojomSchemeHostPort),
    ] => .jsBlinkMojomCredentialInfo)
    fileprivate static let jsBlinkMojomCredentialManager_Store_ResponseParams: ILType = .object(
        ofGroup: "blink.mojom.CredentialManager_Store_ResponseParams",
        withProperties: [
        ])
    fileprivate static let jsBlinkMojomCredentialManager_PreventSilentAccess_ResponseParams: ILType = .object(
        ofGroup: "blink.mojom.CredentialManager_PreventSilentAccess_ResponseParams",
        withProperties: [
        ])
    fileprivate static let jsBlinkMojomCredentialManager_Get_ResponseParams: ILType = .object(
        ofGroup: "blink.mojom.CredentialManager_Get_ResponseParams",
        withProperties: [
            "error",
            "credential",
        ])
}

extension ObjectGroup {
    fileprivate static let blinkMojomCredentialInfo = ObjectGroup(
        name: "blink.mojom.CredentialInfo",
        instanceType: .jsBlinkMojomCredentialInfo,
        properties: [
            "type": .jsBlinkMojomCredentialType,
            "id": .jsMojoBaseMojomString16,
            "name": .jsMojoBaseMojomString16,
            "icon": .jsUrlMojomUrl,
            "password": .jsMojoBaseMojomString16,
            "federation": .jsUrlMojomSchemeHostPort,
        ],
        methods: [:]
    )
    fileprivate static let blinkMojomCredentialManagerStoreResponseParams = ObjectGroup(
        name: "blink.mojom.CredentialManager_Store_ResponseParams",
        instanceType: .jsBlinkMojomCredentialManager_Store_ResponseParams,
        properties: [:],
        methods: [:]
    )
    fileprivate static let blinkMojomCredentialManagerPreventSilentAccessResponseParams = ObjectGroup(
        name: "blink.mojom.CredentialManager_PreventSilentAccess_ResponseParams",
        instanceType: .jsBlinkMojomCredentialManager_PreventSilentAccess_ResponseParams,
        properties: [:],
        methods: [:]
    )
    fileprivate static let blinkMojomCredentialManagerGetResponseParams = ObjectGroup(
        name: "blink.mojom.CredentialManager_Get_ResponseParams",
        instanceType: .jsBlinkMojomCredentialManager_Get_ResponseParams,
        properties: [
            "error": .jsBlinkMojomCredentialManagerError,
            "credential": .jsBlinkMojomCredentialInfo,
        ],
        methods: [:]
    )
}

///
/// Arrays
///
extension ILType {
    fileprivate static let jsUrlMojomUrlArray: ILType =
        .createJsArrayType(ofElementType: .jsUrlMojomUrl)
}

/// As Fuzzilli runs, the OperationMutator and VariadicInputReducer will modify
/// the `CreateArray` operation to increase or decrease the element count. This
/// allows arrays to be arbitrarily long.
private let MojoUrlMojomUrlArrayGenerator = CodeGenerator(
    "MojoUrlMojomUrlArrayGenerator",
    inputs: .required(.jsUrlMojomUrl),
    produces: [.jsUrlMojomUrlArray]
) { b, elem in
    var elements: [Variable] = [elem]
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.urlMojomUrl.name)
}

///
/// Enumerations
///
extension ILType {
    fileprivate static let jsBlinkMojomCredentialType: ILType = .intEnumeration(
        ofName: "blink.mojom.CredentialType",
        withValues: [0, 1, 2])
    fileprivate static let jsBlinkMojomCredentialMediationRequirement: ILType = .intEnumeration(
        ofName: "blink.mojom.CredentialMediationRequirement",
        withValues: [0, 1, 2, 3])
    fileprivate static let jsBlinkMojomCredentialManagerError: ILType = .intEnumeration(
        ofName: "blink.mojom.CredentialManagerError",
        withValues: [0, 1, 2, 3])
}

///
/// Generators
///
// TODO(crbug.com/500386713) Consider using mojoBuiltins or another list instead of regex
private func isTargetObject(type: ILType) -> Bool {
    guard type.Is(.object()), let group = type.group else { return false }
    return group.starts(with: mojoPrefix)
}

/// Mojo variant of the builtin `MethodCallGenerator` that operates only on
/// "Mojo" objects instead of all the objects in the JavaScript environment,
/// most of which are unrelated to the interface. This generator emits random
/// method calls, generating any arguments that are not available.
private let MojoMethodCallGenerator = CodeGenerator("MojoMethodCallGenerator") {
    b in
    // Pick a variable among all Mojo variables with methods
    var targetVar = b.findVariable {
        let type = b.type(of: $0)
        return isTargetObject(type: type) && !type.methods.isEmpty
    }

    // If we can't find a Mojo object in scope, create the CredentialManager remote
    guard let obj = targetVar else {
        let getRemoteFunc = b.createNamedVariable(forBuiltin: "getOrCreatePrimaryRemote")
        b.callFunction(getRemoteFunc, withArgs: [])
        return
    }

    let methodName = b.type(of: obj).randomMethod()!
    let signatures = b.methodSignatures(of: methodName, on: obj)
    let signature = chooseUniform(from: signatures)
    let arguments = b.findOrGenerateArguments(forSignature: signature)
    b.callMethod(methodName, on: obj, withArgs: arguments, guard: false)
}

/// Mojo variant of the builtin `PropertyRetrievalGenerator` that operates only
/// on "Mojo" objects instead of all the objects in the JavaScript environment,
/// most of which are unrelated to the interface. This generator emits random
/// property retrievals.
private let MojoPropertyRetrievalGenerator = CodeGenerator(
    "MojoPropertyRetrievalGenerator"
) { b in
    let targetVar = b.findVariable { isTargetObject(type: b.type(of: $0)) }
    guard let obj = targetVar else { return }

    let propertyName =
        b.type(of: obj).randomProperty() ?? b.randomCustomPropertyName()
    b.getProperty(propertyName, of: obj)
}

private let mojoBuiltins: [String: ILType] = [
    /// Profiles declare this method, a wrapper method around `getRemote` that follows
    /// the Singleton pattern, in `codePrefix`. This method ensures: (1) `getRemote`
    /// is only called once, and (2) the remote is saved to a global variable so it
    /// can be closed at the end of the program.
    "getOrCreatePrimaryRemote": .function([] => .jsBlinkMojomCredentialManagerRemote),
    "blink.mojom.CredentialInfo": .jsBlinkMojomCredentialInfoConstructor,
]

private let keepGenerators = [
    "IntegerGenerator", "StringGenerator", "TernaryOperationGenerator",
    "PlainFunctionGenerator", "AsyncFunctionGenerator", "AwaitGenerator",
    "SubroutineReturnGenerator", "TryCatchGenerator",
]

private let mojoDisabledGenerators: [String] = CodeGenerators.map { $0.name }
    .filter {
        !keepGenerators.contains($0)
    }

let mojoCredentialManagerProfile = Profile(
    processArgs: { _ in return [] },
    processArgsReference: nil,
    processEnv: [
        "ASAN_OPTIONS": "detect_odr_violation=0:abort_on_error=1", "DISPLAY": ":20",
    ],
    maxExecsBeforeRespawn: 1000,
    timeout: Timeout.interval(11000, 11000),
    codePrefix: """
        let globalRemote = null;
        function getOrCreatePrimaryRemote() {
            if (!globalRemote) {
                globalRemote = blink.mojom.CredentialManager.getRemote();
            }
            return globalRemote;
        }
        """,
    codeSuffix: "if (globalRemote) {globalRemote.$.close()}",
    ecmaVersion: v8Profile.ecmaVersion,
    startupTests: [
        ("fuzzilli('FUZZILLI_PRINT', 'test')", .shouldSucceed),
        (
            """
            if (typeof blink == 'undefined' \
            || blink?.mojom?.CredentialManager === undefined) \
            throw 'CredentialManager not found'
            """,
            .shouldSucceed
        ),
    ] + v8Profile.startupTests,
    additionalCodeGenerators: [
        (MojoMethodCallGenerator, 10000),
        (MojoPropertyRetrievalGenerator, 10000),
        (MojoUrlMojomUrlArrayGenerator, 1),
    ] + commonMojoCodeGenerators,
    additionalProgramTemplates: WeightedList([]),
    disabledCodeGenerators: mojoDisabledGenerators,
    disabledMutators: [
        "ExplorationMutator", "ProbingMutator", "PropertyAccessorMutator"
    ],
    additionalBuiltins: mojoBuiltins.merging(commonMojoBuiltins) { (existing, _) in existing },
    additionalObjectGroups: [
        .blinkMojomCredentialManagerRemote,
        .blinkMojomCredentialManagerRemoteWrapper,
        .blinkMojomCredentialManagerPendingReceiver,
        .blinkMojomCredentialInfo,
        .blinkMojomCredentialManagerStoreResponseParams,
        .blinkMojomCredentialManagerPreventSilentAccessResponseParams,
        .blinkMojomCredentialManagerGetResponseParams,
    ] + commonMojoObjectGroups,
    additionalEnumerations: [
        .jsBlinkMojomCredentialType,
        .jsBlinkMojomCredentialMediationRequirement,
        .jsBlinkMojomCredentialManagerError,
    ] + commonMojoEnumerations,
    additionalOptionsBags: [] + commonMojoOptionsBags,
    optionalPostProcessor: nil
)
