// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { assert } from 'chai';
import sinon from 'sinon';
import * as Platform from '../../../../core/platform/platform.js';
import * as SDK from '../../../../core/sdk/sdk.js';
import * as Bindings from '../../../../models/bindings/bindings.js';
import * as Workspace from '../../../../models/workspace/workspace.js';
import { createTarget, deinitializeGlobalVars, initializeGlobalVars } from '../../../../testing/EnvironmentHelpers.js';
import { describeWithMockConnection } from '../../../../testing/MockConnection.js';
import { setupMockedUISourceCode } from '../../../../testing/UISourceCodeHelpers.js';
import * as PerfUI from './perf_ui.js';
const { urlString } = Platform.DevToolsPath;
describeWithMockConnection('LineLevelProfile', () => {
    before(async () => {
        await initializeGlobalVars();
    });
    after(async () => {
        await deinitializeGlobalVars();
    });
    describe('Helper', () => {
        it('should collect and apply performance decorations', async () => {
            const helper = new PerfUI.LineLevelProfile.Helper("performance" /* Workspace.UISourceCode.DecoratorType.PERFORMANCE */);
            const { sut: uiSourceCode } = setupMockedUISourceCode(urlString `file:///script.js`);
            const target = createTarget();
            const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
            if (!debuggerModel) {
                assert.fail('DebuggerModel not found');
            }
            const debuggerWorkspaceBinding = sinon.createStubInstance(Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding);
            sinon.stub(Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding, 'instance')
                .returns(debuggerWorkspaceBinding);
            sinon.stub(debuggerModel, 'createRawLocationByURL')
                .returns(new SDK.DebuggerModel.Location(debuggerModel, 'scriptId', 4, 9));
            const uiLocation = new Workspace.UISourceCode.UILocation(uiSourceCode, 4, 9);
            debuggerWorkspaceBinding.rawLocationToUILocation.resolves(uiLocation);
            helper.addLocationData(target, urlString `file:///script.js`, { line: 5, column: 10 }, 100);
            await helper.update();
            const decorations = uiSourceCode.getDecorationData("performance" /* Workspace.UISourceCode.DecoratorType.PERFORMANCE */);
            assert.isDefined(decorations, 'Decorations should be defined');
            const lineData = decorations.get(5);
            assert.isDefined(lineData, 'Line data should be defined');
            const columnData = lineData.get(10);
            assert.strictEqual(columnData, 100);
        });
    });
});
//# sourceMappingURL=LineLevelProfile.test.js.map