2021-07-08 11:00:56 +02:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
|
|
|
import { URI } from 'vs/base/common/uri';
|
|
|
|
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
|
|
|
import { workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
|
|
|
|
import { IDialogService, IFileDialogService, IOpenDialogOptions, ISaveDialogOptions } from 'vs/platform/dialogs/common/dialogs';
|
|
|
|
import { Schemas } from 'vs/base/common/network';
|
|
|
|
import { BrowserWorkspaceEditingService } from 'vs/workbench/services/workspaces/browser/workspaceEditingService';
|
|
|
|
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
|
|
|
|
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
|
|
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
|
|
|
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
|
|
|
import { FileDialogService } from 'vs/workbench/services/dialogs/electron-sandbox/fileDialogService';
|
|
|
|
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
|
|
|
import { mock } from 'vs/base/test/common/mock';
|
|
|
|
import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
|
|
|
|
import { IModeService } from 'vs/editor/common/services/modeService';
|
|
|
|
import { IFileService } from 'vs/platform/files/common/files';
|
|
|
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
|
|
|
import { ILabelService } from 'vs/platform/label/common/label';
|
|
|
|
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
|
|
|
|
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
|
|
|
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
|
|
|
import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
|
|
|
|
import { IHistoryService } from 'vs/workbench/services/history/common/history';
|
|
|
|
import { IHostService } from 'vs/workbench/services/host/browser/host';
|
|
|
|
import { SimpleFileDialog } from 'vs/workbench/services/dialogs/browser/simpleFileDialog';
|
2021-08-26 09:22:39 +02:00
|
|
|
import { ICommandService } from 'vs/platform/commands/common/commands';
|
2021-09-07 11:27:10 +02:00
|
|
|
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
|
|
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
2021-10-18 10:29:16 +02:00
|
|
|
import { DisposableStore } from 'vs/base/common/lifecycle';
|
2021-07-08 11:00:56 +02:00
|
|
|
|
|
|
|
class TestFileDialogService extends FileDialogService {
|
|
|
|
constructor(
|
|
|
|
private simple: SimpleFileDialog,
|
|
|
|
@IHostService hostService: IHostService,
|
|
|
|
@IWorkspaceContextService contextService: IWorkspaceContextService,
|
|
|
|
@IHistoryService historyService: IHistoryService,
|
|
|
|
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
|
|
|
|
@IInstantiationService instantiationService: IInstantiationService,
|
|
|
|
@IConfigurationService configurationService: IConfigurationService,
|
|
|
|
@IFileService fileService: IFileService,
|
|
|
|
@IOpenerService openerService: IOpenerService,
|
|
|
|
@INativeHostService nativeHostService: INativeHostService,
|
|
|
|
@IDialogService dialogService: IDialogService,
|
|
|
|
@IModeService modeService: IModeService,
|
|
|
|
@IWorkspacesService workspacesService: IWorkspacesService,
|
|
|
|
@ILabelService labelService: ILabelService,
|
2021-08-26 09:22:39 +02:00
|
|
|
@IPathService pathService: IPathService,
|
2021-09-07 11:27:10 +02:00
|
|
|
@ICommandService commandService: ICommandService,
|
|
|
|
@IEditorService editorService: IEditorService,
|
|
|
|
@ICodeEditorService codeEditorService: ICodeEditorService
|
2021-07-08 11:00:56 +02:00
|
|
|
) {
|
|
|
|
super(hostService, contextService, historyService, environmentService, instantiationService, configurationService, fileService,
|
2021-09-07 11:27:10 +02:00
|
|
|
openerService, nativeHostService, dialogService, modeService, workspacesService, labelService, pathService, commandService, editorService, codeEditorService);
|
2021-07-08 11:00:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override getSimpleFileDialog() {
|
|
|
|
if (this.simple) {
|
|
|
|
return this.simple;
|
|
|
|
} else {
|
|
|
|
return super.getSimpleFileDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
suite('FileDialogService', function () {
|
|
|
|
|
2021-10-18 10:29:16 +02:00
|
|
|
let disposables: DisposableStore;
|
2021-07-08 11:00:56 +02:00
|
|
|
let instantiationService: TestInstantiationService;
|
|
|
|
const testFile: URI = URI.file('/test/file');
|
|
|
|
|
|
|
|
setup(async function () {
|
2021-10-18 10:29:16 +02:00
|
|
|
disposables = new DisposableStore();
|
|
|
|
instantiationService = <TestInstantiationService>workbenchInstantiationService(undefined, disposables);
|
2021-07-08 11:00:56 +02:00
|
|
|
const configurationService = new TestConfigurationService();
|
|
|
|
await configurationService.setUserConfiguration('files', { simpleDialog: { enable: true } });
|
|
|
|
instantiationService.stub(IConfigurationService, configurationService);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-10-18 10:29:16 +02:00
|
|
|
teardown(() => {
|
|
|
|
disposables.dispose();
|
|
|
|
});
|
|
|
|
|
2021-07-08 11:00:56 +02:00
|
|
|
test('Local - open/save workspaces availableFilesystems', async function () {
|
|
|
|
class TestSimpleFileDialog {
|
|
|
|
async showOpenDialog(options: IOpenDialogOptions): Promise<URI | undefined> {
|
|
|
|
assert.strictEqual(options.availableFileSystems?.length, 1);
|
|
|
|
assert.strictEqual(options.availableFileSystems[0], Schemas.file);
|
|
|
|
return testFile;
|
|
|
|
}
|
|
|
|
async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
|
|
|
|
assert.strictEqual(options.availableFileSystems?.length, 1);
|
|
|
|
assert.strictEqual(options.availableFileSystems[0], Schemas.file);
|
|
|
|
return testFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const dialogService = instantiationService.createInstance(TestFileDialogService, new TestSimpleFileDialog());
|
|
|
|
instantiationService.set(IFileDialogService, dialogService);
|
|
|
|
const workspaceService: IWorkspaceEditingService = instantiationService.createInstance(BrowserWorkspaceEditingService);
|
|
|
|
assert.strictEqual((await workspaceService.pickNewWorkspacePath())?.path.startsWith(testFile.path), true);
|
|
|
|
assert.strictEqual(await dialogService.pickWorkspaceAndOpen({}), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Virtual - open/save workspaces availableFilesystems', async function () {
|
|
|
|
class TestSimpleFileDialog {
|
|
|
|
async showOpenDialog(options: IOpenDialogOptions): Promise<URI | undefined> {
|
|
|
|
assert.strictEqual(options.availableFileSystems?.length, 1);
|
|
|
|
assert.strictEqual(options.availableFileSystems[0], Schemas.file);
|
|
|
|
return testFile;
|
|
|
|
}
|
|
|
|
async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
|
|
|
|
assert.strictEqual(options.availableFileSystems?.length, 1);
|
|
|
|
assert.strictEqual(options.availableFileSystems[0], Schemas.file);
|
|
|
|
return testFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
instantiationService.stub(IPathService, new class {
|
|
|
|
defaultUriScheme: string = 'vscode-virtual-test';
|
|
|
|
userHome = async () => URI.file('/user/home');
|
|
|
|
});
|
|
|
|
const dialogService = instantiationService.createInstance(TestFileDialogService, new TestSimpleFileDialog());
|
|
|
|
instantiationService.set(IFileDialogService, dialogService);
|
|
|
|
const workspaceService: IWorkspaceEditingService = instantiationService.createInstance(BrowserWorkspaceEditingService);
|
|
|
|
assert.strictEqual((await workspaceService.pickNewWorkspacePath())?.path.startsWith(testFile.path), true);
|
|
|
|
assert.strictEqual(await dialogService.pickWorkspaceAndOpen({}), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Remote - open/save workspaces availableFilesystems', async function () {
|
|
|
|
class TestSimpleFileDialog {
|
|
|
|
async showOpenDialog(options: IOpenDialogOptions): Promise<URI | undefined> {
|
|
|
|
assert.strictEqual(options.availableFileSystems?.length, 2);
|
|
|
|
assert.strictEqual(options.availableFileSystems[0], Schemas.vscodeRemote);
|
|
|
|
assert.strictEqual(options.availableFileSystems[1], Schemas.file);
|
|
|
|
return testFile;
|
|
|
|
}
|
|
|
|
async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
|
|
|
|
assert.strictEqual(options.availableFileSystems?.length, 2);
|
|
|
|
assert.strictEqual(options.availableFileSystems[0], Schemas.vscodeRemote);
|
|
|
|
assert.strictEqual(options.availableFileSystems[1], Schemas.file);
|
|
|
|
return testFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
instantiationService.set(IWorkbenchEnvironmentService, new class extends mock<BrowserWorkbenchEnvironmentService>() {
|
|
|
|
override get remoteAuthority() {
|
|
|
|
return 'testRemote';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
instantiationService.stub(IPathService, new class {
|
|
|
|
defaultUriScheme: string = Schemas.vscodeRemote;
|
|
|
|
userHome = async () => URI.file('/user/home');
|
|
|
|
});
|
|
|
|
const dialogService = instantiationService.createInstance(TestFileDialogService, new TestSimpleFileDialog());
|
|
|
|
instantiationService.set(IFileDialogService, dialogService);
|
|
|
|
const workspaceService: IWorkspaceEditingService = instantiationService.createInstance(BrowserWorkspaceEditingService);
|
|
|
|
assert.strictEqual((await workspaceService.pickNewWorkspacePath())?.path.startsWith(testFile.path), true);
|
|
|
|
assert.strictEqual(await dialogService.pickWorkspaceAndOpen({}), undefined);
|
|
|
|
});
|
|
|
|
});
|