// 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.
import { assert } from 'chai';
import * as Common from '../../core/common/common.js';
import * as Host from '../../core/host/host.js';
import * as Platform from '../../core/platform/platform.js';
import { describeWithEnvironment } from '../../testing/EnvironmentHelpers.js';
import * as Persistence from './persistence.js';
const { urlString } = Platform.DevToolsPath;
class TestPlatformFileSystem extends Persistence.PlatformFileSystem.PlatformFileSystem {
    #manager;
    constructor(path, manager) {
        super(path, Persistence.PlatformFileSystem.PlatformFileSystemType.WORKSPACE_PROJECT, false);
        this.#manager = manager;
    }
    isFileExcluded(folderPath) {
        const regex = this.#manager.workspaceFolderExcludePatternSetting().asRegExp();
        return Boolean(regex?.test(Common.ParsedURL.ParsedURL.encodedPathToRawPathString(folderPath)));
    }
    embedderPath() {
        return Common.ParsedURL.ParsedURL.urlToRawPathString(this.path(), Host.Platform.isWin());
    }
}
describeWithEnvironment('IsolatedFileSystemManager', () => {
    it('does not propagate events for ignored files', () => {
        const manager = Persistence.IsolatedFileSystemManager.IsolatedFileSystemManager.instance();
        manager.workspaceFolderExcludePatternSetting().set('[iI]gnored');
        const fileSystemPath = urlString `file:///var/www`;
        const fileSystem = new TestPlatformFileSystem(fileSystemPath, manager);
        manager.addPlatformFileSystem(fileSystemPath, fileSystem);
        const changedFiles = [];
        const addedFiles = [];
        manager.addEventListener(Persistence.IsolatedFileSystemManager.Events.FileSystemFilesChanged, event => {
            for (const file of event.data.added.valuesArray()) {
                addedFiles.push(file);
            }
            for (const file of event.data.changed.valuesArray()) {
                changedFiles.push(file);
            }
        });
        const hostInstance = Host.InspectorFrontendHost.InspectorFrontendHostInstance;
        // Simulate adding files
        hostInstance.events.dispatchEventToListeners(Host.InspectorFrontendHostAPI.Events.FileSystemFilesChangedAddedRemoved, {
            added: [
                '/var/www/ignoredFile',
                '/var/www/alsoIgnoredFile',
                '/var/www/friendlyFile',
            ],
            changed: [],
            removed: [],
        });
        assert.deepEqual(addedFiles, ['file:///var/www/friendlyFile']);
        assert.deepEqual(changedFiles, []);
        // Reset received files
        addedFiles.length = 0;
        changedFiles.length = 0;
        // Simulate modifying files
        hostInstance.events.dispatchEventToListeners(Host.InspectorFrontendHostAPI.Events.FileSystemFilesChangedAddedRemoved, {
            added: [],
            changed: [
                '/var/www/ignoredFile',
                '/var/www/alsoIgnoredFile',
                '/var/www/friendlyFile',
            ],
            removed: [],
        });
        assert.deepEqual(addedFiles, []);
        assert.deepEqual(changedFiles, ['file:///var/www/friendlyFile']);
    });
});
//# sourceMappingURL=IsolatedFileSystemManager.test.js.map