// 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.
import { assert } from 'chai';
import { createTarget, } from '../../testing/EnvironmentHelpers.js';
import { setupRuntimeHooks } from '../../testing/RuntimeHelpers.js';
import { setupSettingsHooks } from '../../testing/SettingsHelpers.js';
import * as Platform from '../platform/platform.js';
import * as SDK from './sdk.js';
const { urlString } = Platform.DevToolsPath;
describe('ExecutionContext', () => {
    setupRuntimeHooks();
    setupSettingsHooks();
    function createExecutionContext(target, name, isDefault) {
        const runtimeModel = target.model(SDK.RuntimeModel.RuntimeModel);
        assert.exists(runtimeModel);
        return new SDK.RuntimeModel.ExecutionContext(runtimeModel, 42, 'uniqueId', name ?? 'name', urlString `http://www.example.com`, Boolean(isDefault));
    }
    it('can be compared based on target type', () => {
        const tabTarget = createTarget({ type: SDK.Target.Type.TAB });
        const mainFrameTargetUnderTab = createTarget({ type: SDK.Target.Type.FRAME, parentTarget: tabTarget });
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(createExecutionContext(mainFrameTargetUnderTab), createExecutionContext(createTarget({ type: SDK.Target.Type.FRAME, parentTarget: mainFrameTargetUnderTab }))), -1);
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(createExecutionContext(createTarget({ type: SDK.Target.Type.FRAME, parentTarget: mainFrameTargetUnderTab })), createExecutionContext(createTarget({ type: SDK.Target.Type.ServiceWorker, parentTarget: mainFrameTargetUnderTab }))), -1);
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(createExecutionContext(createTarget({ type: SDK.Target.Type.ServiceWorker, parentTarget: mainFrameTargetUnderTab })), createExecutionContext(createTarget({ type: SDK.Target.Type.SHARED_WORKER, parentTarget: mainFrameTargetUnderTab }))), -1);
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(createExecutionContext(createTarget({ type: SDK.Target.Type.ServiceWorker, parentTarget: mainFrameTargetUnderTab })), createExecutionContext(createTarget({ type: SDK.Target.Type.Worker, parentTarget: mainFrameTargetUnderTab }))), -1);
    });
    it('can be compared based on target depth', () => {
        const tabTarget = createTarget({ type: SDK.Target.Type.TAB });
        const mainFrameTarget = createTarget({ type: SDK.Target.Type.FRAME, parentTarget: tabTarget });
        const subframeTarget = createTarget({ type: SDK.Target.Type.FRAME, parentTarget: mainFrameTarget });
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(createExecutionContext(mainFrameTarget), createExecutionContext(subframeTarget)), -1);
    });
    it('can be compared based on defaultness', () => {
        const target = createTarget({ type: SDK.Target.Type.FRAME });
        const defaultExecutionContext = createExecutionContext(target, 'name', /* isDefault=*/ true);
        const notDefaultExecutionContext = createExecutionContext(target, 'name', /* isDefault=*/ false);
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(defaultExecutionContext, notDefaultExecutionContext), -1);
    });
    it('can be compared based on name', () => {
        const target = createTarget({ type: SDK.Target.Type.FRAME });
        const executionContextA = createExecutionContext(target, /* name=*/ 'a');
        const executionContextB = createExecutionContext(target, /* name=*/ 'b');
        assert.strictEqual(SDK.RuntimeModel.ExecutionContext.comparator(executionContextA, executionContextB), -1);
    });
});
//# sourceMappingURL=RuntimeModel.test.js.map