workbenchTestServices.ts 41.5 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

8
import 'vs/workbench/parts/files/electron-browser/files.contribution'; // load our contribution into the test
S
Sandeep Somavarapu 已提交
9
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
J
Johannes Rieken 已提交
10
import { Promise, TPromise } from 'vs/base/common/winjs.base';
11
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
12
import * as paths from 'vs/base/common/paths';
E
Erich Gamma 已提交
13
import URI from 'vs/base/common/uri';
14 15
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
16
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
B
Benjamin Pasero 已提交
17
import { ConfirmResult, IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent } from 'vs/workbench/common/editor';
B
Benjamin Pasero 已提交
18
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView, EditorGroupsServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
M
Matt Bierner 已提交
19
import { Event, Emitter } from 'vs/base/common/event';
E
Erich Gamma 已提交
20
import Severity from 'vs/base/common/severity';
21
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
22
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
J
Johannes Rieken 已提交
23
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
24
import { IPartService, Parts, Position as PartPosition, IDimension } from 'vs/workbench/services/part/common/partService';
25
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
26
import { ITextModelService } from 'vs/editor/common/services/resolverService';
B
Benjamin Pasero 已提交
27
import { IEditorOptions, IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
28
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
S
Sandeep Somavarapu 已提交
29
import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent } from 'vs/platform/workspace/common/workspace';
30
import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
J
Johannes Rieken 已提交
31
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
32
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
33
import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent, ICreateFileOptions, ITextSnapshot, IResourceEncodings } from 'vs/platform/files/common/files';
34
import { IModelService } from 'vs/editor/common/services/modelService';
35
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
J
Johannes Rieken 已提交
36 37 38 39 40 41
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IRawTextContent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { parseArgs } from 'vs/platform/environment/node/argv';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
42
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
43
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
44
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
45
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
46
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
B
Benjamin Pasero 已提交
47
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
48
import { IThemeService } from 'vs/platform/theme/common/themeService';
49
import { isLinux } from 'vs/base/common/platform';
B
Benjamin Pasero 已提交
50 51
import { generateUuid } from 'vs/base/common/uuid';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
52
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
B
Benjamin Pasero 已提交
53
import { IRecentlyOpened } from 'vs/platform/history/common/history';
54
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
55
import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position';
B
Benjamin Pasero 已提交
56
import { ICommandAction, IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
R
Ramya Achutha Rao 已提交
57
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
I
isidor 已提交
58
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
B
Benjamin Pasero 已提交
59
import { MockContextKeyService, MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
B
Benjamin Pasero 已提交
60
import { ITextBufferFactory, DefaultEndOfLine, EndOfLinePreference, IModelDecorationOptions, ITextModel } from 'vs/editor/common/model';
61
import { Range } from 'vs/editor/common/core/range';
62
import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions } from 'vs/platform/dialogs/common/dialogs';
63 64
import { INotificationService } from 'vs/platform/notification/common/notification';
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
B
Benjamin Pasero 已提交
65 66
import { IExtensionService, ProfileSession, IExtensionsStatus, ExtensionPointContribution, IExtensionDescription } from '../services/extensions/common/extensions';
import { IExtensionPoint } from 'vs/workbench/services/extensions/common/extensionsRegistry';
B
Benjamin Pasero 已提交
67
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
B
Benjamin Pasero 已提交
68 69
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
70
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, EditorsOrder, IFindGroupScope, EditorGroupLayout } from 'vs/workbench/services/group/common/editorGroupsService';
71
import { IEditorService, IOpenEditorOverrideHandler } from 'vs/workbench/services/editor/common/editorService';
B
Benjamin Pasero 已提交
72 73 74
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
B
Benjamin Pasero 已提交
75
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
B
Benjamin Pasero 已提交
76

S
Sandeep Somavarapu 已提交
77 78 79 80
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
	return instantiationService.createInstance(FileEditorInput, resource, void 0);
}

81
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
82

83
export class TestContextService implements IWorkspaceContextService {
84
	public _serviceBrand: any;
E
Erich Gamma 已提交
85

86
	private workspace: IWorkbenchWorkspace;
E
Erich Gamma 已提交
87 88
	private options: any;

M
Matt Bierner 已提交
89 90 91
	private readonly _onDidChangeWorkspaceName: Emitter<void>;
	private readonly _onDidChangeWorkspaceFolders: Emitter<IWorkspaceFoldersChangeEvent>;
	private readonly _onDidChangeWorkbenchState: Emitter<WorkbenchState>;
92

93
	constructor(workspace: any = TestWorkspace, options: any = null) {
E
Erich Gamma 已提交
94
		this.workspace = workspace;
95
		this.options = options || Object.create(null);
96
		this._onDidChangeWorkspaceFolders = new Emitter<IWorkspaceFoldersChangeEvent>();
S
Sandeep Somavarapu 已提交
97
		this._onDidChangeWorkbenchState = new Emitter<WorkbenchState>();
98 99
	}

S
Sandeep Somavarapu 已提交
100 101 102 103
	public get onDidChangeWorkspaceName(): Event<void> {
		return this._onDidChangeWorkspaceName.event;
	}

104
	public get onDidChangeWorkspaceFolders(): Event<IWorkspaceFoldersChangeEvent> {
S
Sandeep Somavarapu 已提交
105
		return this._onDidChangeWorkspaceFolders.event;
106 107
	}

108 109 110 111
	public get onDidChangeWorkbenchState(): Event<WorkbenchState> {
		return this._onDidChangeWorkbenchState.event;
	}

S
Sandeep Somavarapu 已提交
112
	public getFolders(): IWorkspaceFolder[] {
S
Sandeep Somavarapu 已提交
113
		return this.workspace ? this.workspace.folders : [];
E
Erich Gamma 已提交
114 115
	}

116
	public getWorkbenchState(): WorkbenchState {
B
Benjamin Pasero 已提交
117 118 119 120 121
		if (this.workspace.configuration) {
			return WorkbenchState.WORKSPACE;
		}

		if (this.workspace.folders.length) {
122
			return WorkbenchState.FOLDER;
123
		}
B
Benjamin Pasero 已提交
124

125
		return WorkbenchState.EMPTY;
S
Sandeep Somavarapu 已提交
126 127
	}

128
	public getWorkspace(): IWorkbenchWorkspace {
B
Benjamin Pasero 已提交
129
		return this.workspace;
130 131
	}

S
Sandeep Somavarapu 已提交
132
	public getWorkspaceFolder(resource: URI): IWorkspaceFolder {
S
Sandeep Somavarapu 已提交
133
		return this.isInsideWorkspace(resource) ? this.workspace.folders[0] : null;
134 135
	}

D
Daniel Imms 已提交
136 137 138 139
	public setWorkspace(workspace: any): void {
		this.workspace = workspace;
	}

E
Erich Gamma 已提交
140 141 142 143 144 145 146 147 148 149
	public getOptions() {
		return this.options;
	}

	public updateOptions() {

	}

	public isInsideWorkspace(resource: URI): boolean {
		if (resource && this.workspace) {
150
			return paths.isEqualOrParent(resource.fsPath, this.workspace.folders[0].uri.fsPath, !isLinux /* ignorecase */);
E
Erich Gamma 已提交
151 152 153 154 155 156
		}

		return false;
	}

	public toResource(workspaceRelativePath: string): URI {
157
		return URI.file(paths.join('C:\\', workspaceRelativePath));
E
Erich Gamma 已提交
158
	}
159 160

	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
161
		return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) && this.pathEquals(this.workspace.folders[0].uri.fsPath, workspaceIdentifier);
162 163 164 165 166 167 168 169 170 171
	}

	private pathEquals(path1: string, path2: string): boolean {
		if (!isLinux) {
			path1 = path1.toLowerCase();
			path2 = path2.toLowerCase();
		}

		return path1 === path2;
	}
E
Erich Gamma 已提交
172 173
}

174
export class TestTextFileService extends TextFileService {
175 176
	public cleanupBackupsBeforeShutdownCalled: boolean;

177 178
	private promptPath: string;
	private confirmResult: ConfirmResult;
179
	private resolveTextContentError: FileOperationError;
A
Alex Dima 已提交
180 181

	constructor(
182 183
		@ILifecycleService lifecycleService: ILifecycleService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
A
Alex Dima 已提交
184 185
		@IConfigurationService configurationService: IConfigurationService,
		@IFileService fileService: IFileService,
186
		@IUntitledEditorService untitledEditorService: IUntitledEditorService,
187
		@IInstantiationService instantiationService: IInstantiationService,
188
		@INotificationService notificationService: INotificationService,
189
		@IBackupFileService backupFileService: IBackupFileService,
190
		@IWindowsService windowsService: IWindowsService,
I
isidor 已提交
191
		@IHistoryService historyService: IHistoryService,
B
Benjamin Pasero 已提交
192 193
		@IContextKeyService contextKeyService: IContextKeyService,
		@IModelService modelService: IModelService
A
Alex Dima 已提交
194
	) {
195
		super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, notificationService, TestEnvironmentService, backupFileService, windowsService, historyService, contextKeyService, modelService);
A
Alex Dima 已提交
196
	}
197

198 199 200 201 202 203 204 205
	public setPromptPath(path: string): void {
		this.promptPath = path;
	}

	public setConfirmResult(result: ConfirmResult): void {
		this.confirmResult = result;
	}

206
	public setResolveTextContentErrorOnce(error: FileOperationError): void {
207 208 209
		this.resolveTextContentError = error;
	}

210
	public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
211 212 213 214
		if (this.resolveTextContentError) {
			const error = this.resolveTextContentError;
			this.resolveTextContentError = null;

215
			return TPromise.wrapError<IRawTextContent>(error);
216 217
		}

218 219
		return this.fileService.resolveContent(resource, options).then((content): IRawTextContent => {
			return {
220
				resource: content.resource,
221 222 223 224
				name: content.name,
				mtime: content.mtime,
				etag: content.etag,
				encoding: content.encoding,
225
				value: createTextBufferFactory(content.value)
226 227 228
			};
		});
	}
229

230 231
	public promptForPath(defaultPath: string): TPromise<string> {
		return TPromise.wrap(this.promptPath);
232 233
	}

234 235
	public confirmSave(resources?: URI[]): TPromise<ConfirmResult> {
		return TPromise.wrap(this.confirmResult);
236
	}
D
Daniel Imms 已提交
237

238 239
	public onFilesConfigurationChange(configuration: any): void {
		super.onFilesConfigurationChange(configuration);
240 241 242 243 244 245
	}

	protected cleanupBackupsBeforeShutdown(): TPromise<void> {
		this.cleanupBackupsBeforeShutdownCalled = true;
		return TPromise.as(void 0);
	}
A
Alex Dima 已提交
246 247
}

248
export function workbenchInstantiationService(): IInstantiationService {
249
	let instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
I
isidor 已提交
250
	instantiationService.stub(IContextKeyService, <IContextKeyService>instantiationService.createInstance(MockContextKeyService));
251
	instantiationService.stub(IWorkspaceContextService, new TestContextService(TestWorkspace));
252 253 254
	const configService = new TestConfigurationService();
	instantiationService.stub(IConfigurationService, configService);
	instantiationService.stub(ITextResourceConfigurationService, new TestTextResourceConfigurationService(configService));
255 256 257
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
	instantiationService.stub(IStorageService, new TestStorageService());
	instantiationService.stub(IPartService, new TestPartService());
258
	instantiationService.stub(IModeService, ModeServiceImpl);
B
Benjamin Pasero 已提交
259
	instantiationService.stub(IHistoryService, new TestHistoryService());
S
Sandeep Somavarapu 已提交
260
	instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
261
	instantiationService.stub(IFileService, new TestFileService());
262
	instantiationService.stub(IBackupFileService, new TestBackupFileService());
263
	instantiationService.stub(ITelemetryService, NullTelemetryService);
264
	instantiationService.stub(INotificationService, new TestNotificationService());
B
Benjamin Pasero 已提交
265
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
266
	instantiationService.stub(IWindowService, new TestWindowService());
B
Benjamin Pasero 已提交
267 268 269 270
	instantiationService.stub(IMenuService, new TestMenuService());
	instantiationService.stub(IKeybindingService, new MockKeybindingService());
	instantiationService.stub(IDecorationsService, new TestDecorationsService());
	instantiationService.stub(IExtensionService, new TestExtensionService());
271
	instantiationService.stub(IWindowsService, new TestWindowsService());
272
	instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(TestTextFileService));
273
	instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
B
Benjamin Pasero 已提交
274
	instantiationService.stub(IEnvironmentService, TestEnvironmentService);
B
Benjamin Pasero 已提交
275
	instantiationService.stub(IThemeService, new TestThemeService());
R
Ramya Achutha Rao 已提交
276
	instantiationService.stub(IHashService, new TestHashService());
277
	instantiationService.stub(IEditorGroupsService, new TestEditorGroupsService([new TestEditorGroup(0)]));
B
Benjamin Pasero 已提交
278
	const editorService = new TestEditorService();
279
	instantiationService.stub(IEditorService, editorService);
B
Benjamin Pasero 已提交
280
	instantiationService.stub(ICodeEditorService, new TestCodeEditorService());
281 282 283 284

	return instantiationService;
}

B
Benjamin Pasero 已提交
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
export class TestDecorationsService implements IDecorationsService {
	_serviceBrand: any;
	onDidChangeDecorations: Event<IResourceDecorationChangeEvent> = Event.None;
	registerDecorationsProvider(provider: IDecorationsProvider): IDisposable { return toDisposable(); }
	getDecoration(uri: URI, includeChildren: boolean, overwrite?: IDecorationData): IDecoration { return void 0; }
}

export class TestExtensionService implements IExtensionService {
	_serviceBrand: any;
	onDidRegisterExtensions: Event<void> = Event.None;
	onDidChangeExtensionsStatus: Event<string[]> = Event.None;
	activateByEvent(activationEvent: string): Promise<void> { return TPromise.as(void 0); }
	whenInstalledExtensionsRegistered(): Promise<boolean> { return TPromise.as(true); }
	getExtensions(): Promise<IExtensionDescription[]> { return TPromise.as([]); }
	readExtensionPointContributions<T>(extPoint: IExtensionPoint<T>): Promise<ExtensionPointContribution<T>[]> { return TPromise.as(Object.create(null)); }
	getExtensionsStatus(): { [id: string]: IExtensionsStatus; } { return Object.create(null); }
	canProfileExtensionHost(): boolean { return false; }
	startExtensionHostProfile(): Promise<ProfileSession> { return TPromise.as(Object.create(null)); }
	restartExtensionHost(): void { }
	startExtensionHost(): void { }
	stopExtensionHost(): void { }
}

export class TestMenuService implements IMenuService {

	public _serviceBrand: any;

	createMenu(id: MenuId, scopedKeybindingService: IContextKeyService): IMenu {
		return {
			onDidChange: Event.None,
			dispose: () => void 0,
			getActions: () => []
		};
	}
}

B
Benjamin Pasero 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
export class TestHistoryService implements IHistoryService {

	public _serviceBrand: any;

	constructor(private root?: URI) {
	}

	public reopenLastClosedEditor(): void {
	}

	public forward(acrossEditors?: boolean): void {
	}

	public back(acrossEditors?: boolean): void {
	}

337 338 339
	public last(): void {
	}

B
Benjamin Pasero 已提交
340 341 342 343 344 345 346 347 348 349
	public remove(input: IEditorInput | IResourceInput): void {
	}

	public clear(): void {
	}

	public getHistory(): (IEditorInput | IResourceInput)[] {
		return [];
	}

350
	public getLastActiveWorkspaceRoot(schemeFilter?: string): URI {
B
Benjamin Pasero 已提交
351 352
		return this.root;
	}
353 354 355 356

	public getLastActiveFile(): URI {
		return void 0;
	}
B
Benjamin Pasero 已提交
357 358
}

359
export class TestDialogService implements IDialogService {
360 361

	public _serviceBrand: any;
E
Erich Gamma 已提交
362

363
	public confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
364 365
		return TPromise.as({ confirmed: false });
	}
366

367
	public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<number, any> {
368 369
		return TPromise.as(0);
	}
E
Erich Gamma 已提交
370 371
}

372
export class TestPartService implements IPartService {
B
Benjamin Pasero 已提交
373

374
	public _serviceBrand: any;
E
Erich Gamma 已提交
375

376
	private _onTitleBarVisibilityChange = new Emitter<void>();
377
	private _onEditorLayout = new Emitter<IDimension>();
378 379 380 381 382

	public get onTitleBarVisibilityChange(): Event<void> {
		return this._onTitleBarVisibilityChange.event;
	}

383
	public get onEditorLayout(): Event<IDimension> {
384 385 386
		return this._onEditorLayout.event;
	}

E
Erich Gamma 已提交
387 388 389 390 391 392
	public layout(): void { }

	public isCreated(): boolean {
		return true;
	}

M
Matt Bierner 已提交
393
	public hasFocus(part: Parts): boolean {
E
Erich Gamma 已提交
394 395 396
		return false;
	}

M
Matt Bierner 已提交
397
	public isVisible(part: Parts): boolean {
E
Erich Gamma 已提交
398 399 400
		return true;
	}

M
Matt Bierner 已提交
401
	public getContainer(part: Parts): HTMLElement {
402 403 404
		return null;
	}

B
Benjamin Pasero 已提交
405 406 407 408
	public isTitleBarHidden(): boolean {
		return false;
	}

409 410 411 412
	public getTitleBarOffset(): number {
		return 0;
	}

413 414 415 416
	public isStatusBarHidden(): boolean {
		return false;
	}

S
Sanders Lauture 已提交
417 418 419 420 421 422
	public isActivityBarHidden(): boolean {
		return false;
	}

	public setActivityBarHidden(hidden: boolean): void { }

E
Erich Gamma 已提交
423 424 425 426
	public isSideBarHidden(): boolean {
		return false;
	}

427
	public setSideBarHidden(hidden: boolean): TPromise<void> { return TPromise.as(null); }
E
Erich Gamma 已提交
428

I
isidor 已提交
429
	public isPanelHidden(): boolean {
I
isidor 已提交
430 431 432
		return false;
	}

433
	public setPanelHidden(hidden: boolean): TPromise<void> { return TPromise.as(null); }
I
isidor 已提交
434

I
isidor 已提交
435 436
	public toggleMaximizedPanel(): void { }

B
Benjamin Pasero 已提交
437 438 439 440
	public isPanelMaximized(): boolean {
		return false;
	}

E
Erich Gamma 已提交
441 442 443 444
	public getSideBarPosition() {
		return 0;
	}

I
isidor 已提交
445 446 447 448
	public getPanelPosition() {
		return 0;
	}

I
isidor 已提交
449 450 451 452
	public setPanelPosition(position: PartPosition): TPromise<void> {
		return TPromise.as(null);
	}

E
Erich Gamma 已提交
453 454
	public addClass(clazz: string): void { }
	public removeClass(clazz: string): void { }
455
	public getWorkbenchElementId(): string { return ''; }
B
Benjamin Pasero 已提交
456

I
isidor 已提交
457
	public toggleZenMode(): void { }
458

B
Benjamin Pasero 已提交
459
	public isEditorLayoutCentered(): boolean { return false; }
460
	public centerEditorLayout(active: boolean): void { }
S
SrTobi 已提交
461 462


463
	public resizePart(part: Parts, sizeChange: number): void { }
E
Erich Gamma 已提交
464 465
}

466
export class TestStorageService implements IStorageService {
467
	public _serviceBrand: any;
E
Erich Gamma 已提交
468

B
Benjamin Pasero 已提交
469
	private storage: StorageService;
E
Erich Gamma 已提交
470 471 472

	constructor() {
		let context = new TestContextService();
473
		this.storage = new StorageService(new InMemoryLocalStorage(), null, context.getWorkspace().id);
E
Erich Gamma 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
	}

	store(key: string, value: any, scope: StorageScope = StorageScope.GLOBAL): void {
		this.storage.store(key, value, scope);
	}

	remove(key: string, scope: StorageScope = StorageScope.GLOBAL): void {
		this.storage.remove(key, scope);
	}

	get(key: string, scope: StorageScope = StorageScope.GLOBAL, defaultValue?: string): string {
		return this.storage.get(key, scope, defaultValue);
	}

	getInteger(key: string, scope: StorageScope = StorageScope.GLOBAL, defaultValue?: number): number {
		return this.storage.getInteger(key, scope, defaultValue);
	}

	getBoolean(key: string, scope: StorageScope = StorageScope.GLOBAL, defaultValue?: boolean): boolean {
		return this.storage.getBoolean(key, scope, defaultValue);
	}
}

B
Benjamin Pasero 已提交
497
export class TestEditorGroupsService implements EditorGroupsServiceImpl {
498 499
	_serviceBrand: ServiceIdentifier<any>;

B
Benjamin Pasero 已提交
500
	constructor(public groups: TestEditorGroup[] = []) { }
501

502 503 504 505
	onDidActiveGroupChange: Event<IEditorGroup> = Event.None;
	onDidAddGroup: Event<IEditorGroup> = Event.None;
	onDidRemoveGroup: Event<IEditorGroup> = Event.None;
	onDidMoveGroup: Event<IEditorGroup> = Event.None;
506 507

	orientation: any;
508
	whenRestored: TPromise<void> = TPromise.as(void 0);
509

510
	get activeGroup(): IEditorGroup {
511 512 513 514 515 516 517
		return this.groups[0];
	}

	get count(): number {
		return this.groups.length;
	}

518
	getGroups(order?: GroupsOrder): ReadonlyArray<IEditorGroup> {
519 520 521
		return this.groups;
	}

522
	getGroup(identifier: number): IEditorGroup {
523 524 525 526 527 528 529 530 531
		for (let i = 0; i < this.groups.length; i++) {
			if (this.groups[i].id === identifier) {
				return this.groups[i];
			}
		}

		return void 0;
	}

532 533 534 535
	getLabel(identifier: number): string {
		return 'Group 1';
	}

B
Benjamin Pasero 已提交
536
	findGroup(scope: IFindGroupScope, source?: number | IEditorGroup, wrap?: boolean): IEditorGroup {
537 538 539
		return null;
	}

540
	activateGroup(group: number | IEditorGroup): IEditorGroup {
541 542 543
		return null;
	}

544 545
	getSize(group: number | IEditorGroup): number {
		return 100;
546 547
	}

548 549
	setSize(group: number | IEditorGroup, size: number): void { }

550 551
	arrangeGroups(arrangement: GroupsArrangement): void { }

552 553
	applyLayout(layout: EditorGroupLayout): void { }

554 555
	setGroupOrientation(orientation: any): void { }

556
	addGroup(location: number | IEditorGroup, direction: GroupDirection, options?: IAddGroupOptions): IEditorGroup {
557 558 559
		return null;
	}

560
	removeGroup(group: number | IEditorGroup): void { }
561

562
	moveGroup(group: number | IEditorGroup, location: number | IEditorGroup, direction: GroupDirection): IEditorGroup {
563 564 565
		return null;
	}

566
	mergeGroup(group: number | IEditorGroup, target: number | IEditorGroup, options?: IMergeGroupOptions): IEditorGroup {
567 568 569
		return null;
	}

570
	copyGroup(group: number | IEditorGroup, location: number | IEditorGroup, direction: GroupDirection): IEditorGroup {
571 572 573 574
		return null;
	}
}

B
Benjamin Pasero 已提交
575
export class TestEditorGroup implements IEditorGroupView {
576 577 578

	constructor(public id: number) { }

B
Benjamin Pasero 已提交
579
	group: EditorGroup = void 0;
580 581 582 583
	activeControl: IEditor;
	activeEditor: IEditorInput;
	previewEditor: IEditorInput;
	count: number;
B
Benjamin Pasero 已提交
584
	disposed: boolean;
B
Benjamin Pasero 已提交
585
	editors: ReadonlyArray<IEditorInput> = [];
586
	label: string;
B
Benjamin Pasero 已提交
587 588 589 590 591 592
	whenRestored: Promise<void, any> = TPromise.as(void 0);
	element: HTMLElement;
	minimumWidth: number;
	maximumWidth: number;
	minimumHeight: number;
	maximumHeight: number;
593 594

	onWillDispose: Event<void> = Event.None;
595
	onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
B
Benjamin Pasero 已提交
596 597
	onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
598 599
	onWillOpenEditor: Event<IEditorOpeningEvent> = Event.None;
	onDidOpenEditorFail: Event<IEditorInput> = Event.None;
B
Benjamin Pasero 已提交
600 601
	onDidFocus: Event<void> = Event.None;
	onDidChange: Event<{ width: number; height: number; }> = Event.None;
602

B
Benjamin Pasero 已提交
603 604 605 606
	getEditors(order?: EditorsOrder): ReadonlyArray<IEditorInput> {
		return [];
	}

607 608 609 610 611 612 613 614
	getEditor(index: number): IEditorInput {
		return null;
	}

	getIndexOfEditor(editor: IEditorInput): number {
		return -1;
	}

615
	openEditor(editor: IEditorInput, options?: IEditorOptions): TPromise<void> {
616 617 618
		return TPromise.as(void 0);
	}

619
	openEditors(editors: IEditorInputWithOptions[]): TPromise<void> {
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
		return TPromise.as(void 0);
	}

	isOpened(editor: IEditorInput): boolean {
		return false;
	}

	isPinned(editor: IEditorInput): boolean {
		return false;
	}

	isActive(editor: IEditorInput): boolean {
		return false;
	}

635
	moveEditor(editor: IEditorInput, target: IEditorGroup, options?: IMoveEditorOptions): void { }
636

637
	copyEditor(editor: IEditorInput, target: IEditorGroup, options?: ICopyEditorOptions): void { }
638

639
	closeEditor(editor?: IEditorInput): TPromise<void> {
640 641 642
		return TPromise.as(void 0);
	}

643
	closeEditors(editors: IEditorInput[] | { except?: IEditorInput; direction?: CloseDirection; savedOnly?: boolean; }): TPromise<void> {
644 645 646
		return TPromise.as(void 0);
	}

647
	closeAllEditors(): TPromise<void> {
648 649 650
		return TPromise.as(void 0);
	}

651
	replaceEditors(editors: IEditorReplacement[]): TPromise<void> {
652 653 654 655 656 657 658 659 660 661
		return TPromise.as(void 0);
	}

	pinEditor(editor?: IEditorInput): void { }

	focus(): void { }

	invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T {
		return fn(null);
	}
B
Benjamin Pasero 已提交
662 663 664 665 666 667 668 669

	isEmpty(): boolean { return true; }
	setActive(isActive: boolean): void { }
	setLabel(label: string): void { }
	shutdown(): void { }
	dispose(): void { }
	toJSON(): object { return Object.create(null); }
	layout(width: number, height: number): void { }
670 671
}

B
Benjamin Pasero 已提交
672
export class TestEditorService implements EditorServiceImpl {
673 674 675 676 677

	_serviceBrand: ServiceIdentifier<any>;

	onDidActiveEditorChange: Event<void> = Event.None;
	onDidVisibleEditorsChange: Event<void> = Event.None;
B
Benjamin Pasero 已提交
678
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
679 680 681
	onDidOpenEditorFail: Event<IEditorIdentifier> = Event.None;

	activeControl: IEditor;
682
	activeTextEditorWidget: any;
683
	activeEditor: IEditorInput;
684
	editors: ReadonlyArray<IEditorInput> = [];
B
Benjamin Pasero 已提交
685
	visibleControls: ReadonlyArray<IEditor> = [];
686
	visibleTextEditorWidgets = [];
B
Benjamin Pasero 已提交
687
	visibleEditors: ReadonlyArray<IEditorInput> = [];
688

689 690 691 692
	overrideOpenEditor(handler: IOpenEditorOverrideHandler): IDisposable {
		return toDisposable(() => void 0);
	}

693 694 695 696 697 698 699 700 701 702 703 704
	openEditor(editor: any, options?: any, group?: any) {
		return TPromise.as(null);
	}

	openEditors(editors: any, group?: any) {
		return TPromise.as(null);
	}

	isOpen(editor: IEditorInput | IResourceInput | IUntitledResourceInput): boolean {
		return false;
	}

705 706 707 708
	replaceEditors(editors: any, group: any) {
		return TPromise.as(void 0);
	}

709 710 711 712 713 714 715 716 717
	invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
		return fn(null);
	}

	createInput(input: IResourceInput | IUntitledResourceInput | IResourceDiffInput | IResourceSideBySideInput): IEditorInput {
		return null;
	}
}

718 719 720 721
export class TestFileService implements IFileService {

	public _serviceBrand: any;

722 723
	public encoding: IResourceEncodings;

M
Matt Bierner 已提交
724 725
	private readonly _onFileChanges: Emitter<FileChangesEvent>;
	private readonly _onAfterOperation: Emitter<FileOperationEvent>;
726

727 728
	private content = 'Hello Html';

729 730 731 732 733
	constructor() {
		this._onFileChanges = new Emitter<FileChangesEvent>();
		this._onAfterOperation = new Emitter<FileOperationEvent>();
	}

734 735 736 737 738 739 740 741
	public setContent(content: string): void {
		this.content = content;
	}

	public getContent(): string {
		return this.content;
	}

742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
	public get onFileChanges(): Event<FileChangesEvent> {
		return this._onFileChanges.event;
	}

	public fireFileChanges(event: FileChangesEvent): void {
		this._onFileChanges.fire(event);
	}

	public get onAfterOperation(): Event<FileOperationEvent> {
		return this._onAfterOperation.event;
	}

	public fireAfterOperation(event: FileOperationEvent): void {
		this._onAfterOperation.fire(event);
	}

	resolveFile(resource: URI, options?: IResolveFileOptions): TPromise<IFileStat> {
A
Alex Dima 已提交
759
		return TPromise.as({
760 761
			resource,
			etag: Date.now().toString(),
B
Benjamin Pasero 已提交
762
			encoding: 'utf8',
B
Benjamin Pasero 已提交
763
			mtime: Date.now(),
764
			isDirectory: false,
B
Benjamin Pasero 已提交
765 766
			name: paths.basename(resource.fsPath)
		});
767
	}
B
Benjamin Pasero 已提交
768

I
isidor 已提交
769 770
	resolveFiles(toResolve: { resource: URI, options?: IResolveFileOptions }[]): TPromise<IResolveFileResult[]> {
		return TPromise.join(toResolve.map(resourceAndOption => this.resolveFile(resourceAndOption.resource, resourceAndOption.options))).then(stats => stats.map(stat => ({ stat, success: true })));
I
isidor 已提交
771 772
	}

773 774 775
	existsFile(resource: URI): TPromise<boolean> {
		return TPromise.as(null);
	}
B
Benjamin Pasero 已提交
776

777
	resolveContent(resource: URI, options?: IResolveContentOptions): TPromise<IContent> {
B
Benjamin Pasero 已提交
778 779
		return TPromise.as({
			resource: resource,
780
			value: this.content,
781
			etag: 'index.txt',
B
Benjamin Pasero 已提交
782 783
			encoding: 'utf8',
			mtime: Date.now(),
784
			name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
785
		});
786
	}
E
Erich Gamma 已提交
787

788
	resolveStreamContent(resource: URI, options?: IResolveContentOptions): TPromise<IStreamContent> {
A
Alex Dima 已提交
789 790 791
		return TPromise.as({
			resource: resource,
			value: {
792
				on: (event: string, callback: Function): void => {
A
Alex Dima 已提交
793
					if (event === 'data') {
794
						callback(this.content);
A
Alex Dima 已提交
795 796 797 798 799 800 801 802
					}
					if (event === 'end') {
						callback();
					}
				}
			},
			etag: 'index.txt',
			encoding: 'utf8',
B
Benjamin Pasero 已提交
803
			mtime: Date.now(),
804
			name: paths.basename(resource.fsPath)
A
Alex Dima 已提交
805
		});
806 807
	}

808
	updateContent(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): TPromise<IFileStat> {
809
		return TPromise.timeout(1).then(() => {
E
Erich Gamma 已提交
810
			return {
811
				resource,
E
Erich Gamma 已提交
812
				etag: 'index.txt',
B
Benjamin Pasero 已提交
813
				encoding: 'utf8',
B
Benjamin Pasero 已提交
814
				mtime: Date.now(),
815 816
				isDirectory: false,
				name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
817 818
			};
		});
819
	}
D
Daniel Imms 已提交
820

821 822 823
	moveFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
824

825 826 827
	copyFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
828

829
	createFile(resource: URI, content?: string, options?: ICreateFileOptions): TPromise<IFileStat> {
830
		return TPromise.as(null);
E
Erich Gamma 已提交
831
	}
832 833 834 835 836 837 838 839

	createFolder(resource: URI): TPromise<IFileStat> {
		return TPromise.as(null);
	}

	rename(resource: URI, newName: string): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
840

841 842 843 844 845 846
	onDidChangeFileSystemProviderRegistrations = Event.None;

	registerProvider(scheme: string, provider) {
		return { dispose() { } };
	}

847 848 849 850
	canHandleResource(resource: URI): boolean {
		return resource.scheme === 'file';
	}

851 852 853 854 855 856 857
	del(resource: URI, useTrash?: boolean): TPromise<void> {
		return TPromise.as(null);
	}

	watchFileChanges(resource: URI): void {
	}

J
Johannes Rieken 已提交
858
	unwatchFileChanges(resource: URI): void {
859 860
	}

861
	getWriteEncoding(resource: URI): string {
862 863
		return 'utf8';
	}
D
Daniel Imms 已提交
864

865
	dispose(): void {
E
Erich Gamma 已提交
866
	}
867
}
868

869 870
export class TestBackupFileService implements IBackupFileService {
	public _serviceBrand: any;
871

872 873
	public backupEnabled: boolean;

874 875 876 877
	public hasBackups(): TPromise<boolean> {
		return TPromise.as(false);
	}

878
	public hasBackup(resource: URI): TPromise<boolean> {
879 880 881
		return TPromise.as(false);
	}

B
Benjamin Pasero 已提交
882 883 884
	public loadBackupResource(resource: URI): TPromise<URI> {
		return this.hasBackup(resource).then(hasBackup => {
			if (hasBackup) {
885
				return this.toBackupResource(resource);
B
Benjamin Pasero 已提交
886 887 888 889 890 891
			}

			return void 0;
		});
	}

D
Daniel Imms 已提交
892 893 894 895 896 897 898 899
	public registerResourceForBackup(resource: URI): TPromise<void> {
		return TPromise.as(void 0);
	}

	public deregisterResourceForBackup(resource: URI): TPromise<void> {
		return TPromise.as(void 0);
	}

900
	public toBackupResource(resource: URI): URI {
D
Daniel Imms 已提交
901 902
		return null;
	}
903

904
	public backupResource(resource: URI, content: ITextSnapshot): TPromise<void> {
905 906 907
		return TPromise.as(void 0);
	}

908
	public getWorkspaceFileBackups(): TPromise<URI[]> {
909 910 911
		return TPromise.as([]);
	}

912 913 914 915 916
	public parseBackupContent(textBufferFactory: ITextBufferFactory): string {
		const textBuffer = textBufferFactory.create(DefaultEndOfLine.LF);
		const lineCount = textBuffer.getLineCount();
		const range = new Range(1, 1, lineCount, textBuffer.getLineLength(lineCount) + 1);
		return textBuffer.getValueInRange(range, EndOfLinePreference.TextDefined);
917 918
	}

919 920 921 922
	public resolveBackupContent(backup: URI): TPromise<ITextBufferFactory> {
		return TPromise.as(null);
	}

923
	public discardResourceBackup(resource: URI): TPromise<void> {
924 925 926
		return TPromise.as(void 0);
	}

927
	public discardAllWorkspaceBackups(): TPromise<void> {
928 929
		return TPromise.as(void 0);
	}
930
}
D
Daniel Imms 已提交
931

B
Benjamin Pasero 已提交
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
export class TestCodeEditorService implements ICodeEditorService {
	_serviceBrand: any;

	onCodeEditorAdd: Event<ICodeEditor> = Event.None;
	onCodeEditorRemove: Event<ICodeEditor> = Event.None;
	onDiffEditorAdd: Event<IDiffEditor> = Event.None;
	onDiffEditorRemove: Event<IDiffEditor> = Event.None;

	addCodeEditor(editor: ICodeEditor): void { }
	removeCodeEditor(editor: ICodeEditor): void { }
	listCodeEditors(): ICodeEditor[] { return []; }
	addDiffEditor(editor: IDiffEditor): void { }
	removeDiffEditor(editor: IDiffEditor): void { }
	listDiffEditors(): IDiffEditor[] { return []; }
	getFocusedCodeEditor(): ICodeEditor { return null; }
	registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void { }
	removeDecorationType(key: string): void { }
	resolveDecorationOptions(typeKey: string, writable: boolean): IModelDecorationOptions { return Object.create(null); }
	setTransientModelProperty(model: ITextModel, key: string, value: any): void { }
	getTransientModelProperty(model: ITextModel, key: string) { }
952
	getActiveCodeEditor(): ICodeEditor { return null; }
953
	openCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise<ICodeEditor> { return TPromise.as(null); }
B
Benjamin Pasero 已提交
954 955
}

956 957 958 959
export class TestWindowService implements IWindowService {

	public _serviceBrand: any;

960
	onDidChangeFocus: Event<boolean> = new Emitter<boolean>().event;
961

962 963 964 965
	isFocused(): TPromise<boolean> {
		return TPromise.as(false);
	}

966 967 968 969
	getConfiguration(): IWindowConfiguration {
		return Object.create(null);
	}

970 971 972 973
	getCurrentWindowId(): number {
		return 0;
	}

B
Benjamin Pasero 已提交
974
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
975 976 977
		return TPromise.as(void 0);
	}

B
Benjamin Pasero 已提交
978
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
979 980 981
		return TPromise.as(void 0);
	}

B
Benjamin Pasero 已提交
982
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
983 984 985
		return TPromise.as(void 0);
	}

986 987 988 989
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
		return TPromise.as(void 0);
	}

990 991 992 993 994 995 996 997 998 999 1000 1001
	reloadWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}

	openDevTools(): TPromise<void> {
		return TPromise.as(void 0);
	}

	toggleDevTools(): TPromise<void> {
		return TPromise.as(void 0);
	}

1002
	closeWorkspace(): TPromise<void> {
1003 1004 1005
		return TPromise.as(void 0);
	}

1006
	createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
1007 1008 1009
		return TPromise.as(void 0);
	}

1010
	saveAndEnterWorkspace(path: string): TPromise<IEnterWorkspaceResult> {
1011 1012 1013
		return TPromise.as(void 0);
	}

1014 1015 1016 1017 1018 1019 1020 1021
	toggleFullScreen(): TPromise<void> {
		return TPromise.as(void 0);
	}

	setRepresentedFilename(fileName: string): TPromise<void> {
		return TPromise.as(void 0);
	}

1022
	getRecentlyOpened(): TPromise<IRecentlyOpened> {
1023 1024 1025 1026 1027 1028 1029
		return TPromise.as(void 0);
	}

	focusWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}

B
Benjamin Pasero 已提交
1030 1031 1032 1033
	openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): TPromise<void> {
		return TPromise.as(void 0);
	}

1034 1035 1036 1037
	closeWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}

1038 1039 1040 1041
	setDocumentEdited(flag: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}

1042 1043 1044
	onWindowTitleDoubleClick(): TPromise<void> {
		return TPromise.as(void 0);
	}
1045

J
Joao 已提交
1046 1047 1048 1049
	show(): TPromise<void> {
		return TPromise.as(void 0);
	}

1050 1051
	showMessageBox(options: Electron.MessageBoxOptions): TPromise<IMessageBoxResult> {
		return TPromise.wrap({ button: 0 });
1052 1053
	}

1054 1055
	showSaveDialog(options: Electron.SaveDialogOptions): TPromise<string> {
		return TPromise.wrap(void 0);
1056
	}
1057

1058 1059
	showOpenDialog(options: Electron.OpenDialogOptions): TPromise<string[]> {
		return TPromise.wrap(void 0);
1060
	}
1061 1062 1063 1064

	updateTouchBar(items: ICommandAction[][]): Promise<void> {
		return TPromise.as(void 0);
	}
1065 1066
}

1067 1068
export class TestLifecycleService implements ILifecycleService {

1069
	public _serviceBrand: any;
1070

1071
	public phase: LifecyclePhase;
1072
	public startupKind: StartupKind;
1073

1074
	private _onWillShutdown = new Emitter<ShutdownEvent>();
1075
	private _onShutdown = new Emitter<ShutdownReason>();
1076

1077
	when(): TPromise<void> {
1078
		return TPromise.as(void 0);
B
Benjamin Pasero 已提交
1079
	}
1080

1081 1082
	public fireShutdown(reason = ShutdownReason.QUIT): void {
		this._onShutdown.fire(reason);
1083 1084
	}

1085 1086 1087 1088
	public fireWillShutdown(event: ShutdownEvent): void {
		this._onWillShutdown.fire(event);
	}

1089 1090 1091 1092
	public get onWillShutdown(): Event<ShutdownEvent> {
		return this._onWillShutdown.event;
	}

1093
	public get onShutdown(): Event<ShutdownReason> {
1094 1095
		return this._onShutdown.event;
	}
1096 1097
}

1098 1099 1100 1101
export class TestWindowsService implements IWindowsService {

	_serviceBrand: any;

1102 1103
	public windowCount = 1;

1104 1105
	onWindowOpen: Event<number>;
	onWindowFocus: Event<number>;
1106
	onWindowBlur: Event<number>;
1107

1108 1109 1110 1111
	isFocused(windowId: number): TPromise<boolean> {
		return TPromise.as(false);
	}

B
Benjamin Pasero 已提交
1112
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
1113 1114
		return TPromise.as(void 0);
	}
1115

B
Benjamin Pasero 已提交
1116
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
1117 1118
		return TPromise.as(void 0);
	}
1119

B
Benjamin Pasero 已提交
1120
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
1121 1122
		return TPromise.as(void 0);
	}
1123

1124 1125 1126 1127
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
		return TPromise.as(void 0);
	}

1128 1129 1130
	reloadWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1131

1132 1133 1134
	openDevTools(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1135

1136 1137 1138
	toggleDevTools(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1139

1140
	closeWorkspace(windowId: number): TPromise<void> {
1141 1142
		return TPromise.as(void 0);
	}
1143

1144
	createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
1145 1146 1147
		return TPromise.as(void 0);
	}

1148
	saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
1149 1150 1151
		return TPromise.as(void 0);
	}

1152 1153 1154
	toggleFullScreen(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1155

1156 1157 1158
	setRepresentedFilename(windowId: number, fileName: string): TPromise<void> {
		return TPromise.as(void 0);
	}
1159

1160
	addRecentlyOpened(files: string[]): TPromise<void> {
1161 1162
		return TPromise.as(void 0);
	}
1163

1164
	removeFromRecentlyOpened(paths: string[]): TPromise<void> {
1165 1166
		return TPromise.as(void 0);
	}
1167

B
Benjamin Pasero 已提交
1168
	clearRecentlyOpened(): TPromise<void> {
C
22768  
Cristian 已提交
1169 1170
		return TPromise.as(void 0);
	}
1171

1172
	getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened> {
1173 1174
		return TPromise.as(void 0);
	}
1175

1176 1177 1178
	focusWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1179

1180 1181 1182 1183
	closeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}

1184 1185 1186
	isMaximized(windowId: number): TPromise<boolean> {
		return TPromise.as(void 0);
	}
1187

1188 1189 1190
	maximizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1191

1192 1193 1194
	unmaximizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1195

1196 1197 1198
	onWindowTitleDoubleClick(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1199

1200 1201 1202
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}
1203

1204 1205 1206
	quit(): TPromise<void> {
		return TPromise.as(void 0);
	}
1207

J
Johannes Rieken 已提交
1208 1209 1210
	relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void> {
		return TPromise.as(void 0);
	}
1211

1212 1213 1214
	whenSharedProcessReady(): TPromise<void> {
		return TPromise.as(void 0);
	}
1215

1216 1217 1218
	toggleSharedProcess(): TPromise<void> {
		return TPromise.as(void 0);
	}
1219

1220
	// Global methods
B
Benjamin Pasero 已提交
1221
	openWindow(windowId: number, paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): TPromise<void> {
1222 1223
		return TPromise.as(void 0);
	}
1224

1225 1226 1227
	openNewWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}
1228

1229 1230 1231
	showWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1232

1233
	getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]> {
1234 1235
		return TPromise.as(void 0);
	}
1236

1237
	getWindowCount(): TPromise<number> {
1238
		return TPromise.as(this.windowCount);
1239
	}
1240

1241 1242 1243
	log(severity: string, ...messages: string[]): TPromise<void> {
		return TPromise.as(void 0);
	}
1244

1245 1246 1247 1248
	showItemInFolder(path: string): TPromise<void> {
		return TPromise.as(void 0);
	}

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
	showPreviousWindowTab(): Promise<void> {
		return TPromise.as(void 0);
	}

	showNextWindowTab(): Promise<void> {
		return TPromise.as(void 0);
	}

	moveWindowTabToNewWindow(): Promise<void> {
		return TPromise.as(void 0);
	}

	mergeAllWindowTabs(): Promise<void> {
		return TPromise.as(void 0);
	}

	toggleWindowTabsBar(): Promise<void> {
		return TPromise.as(void 0);
1267 1268 1269 1270
	}

	updateTouchBar(windowId: number, items: ICommandAction[][]): Promise<void> {
		return TPromise.as(void 0);
1271 1272
	}

1273 1274
	// This needs to be handled from browser process to prevent
	// foreground ordering issues on Windows
1275 1276
	openExternal(url: string): TPromise<boolean> {
		return TPromise.as(true);
1277 1278 1279 1280 1281 1282
	}

	// TODO: this is a bit backwards
	startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void> {
		return TPromise.as(void 0);
	}
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294

	showMessageBox(windowId: number, options: Electron.MessageBoxOptions): TPromise<IMessageBoxResult> {
		return TPromise.as(void 0);
	}

	showSaveDialog(windowId: number, options: Electron.SaveDialogOptions): TPromise<string> {
		return TPromise.as(void 0);
	}

	showOpenDialog(windowId: number, options: Electron.OpenDialogOptions): TPromise<string[]> {
		return TPromise.as(void 0);
	}
J
Joao Moreno 已提交
1295 1296 1297 1298

	openAboutDialog(): TPromise<void> {
		return TPromise.as(void 0);
	}
1299
}
B
Benjamin Pasero 已提交
1300

1301 1302 1303 1304 1305 1306 1307
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

	constructor(private configurationService = new TestConfigurationService()) {
	}

1308
	public onDidChangeConfiguration() {
1309 1310 1311
		return { dispose() { } };
	}

1312 1313 1314 1315
	getValue<T>(resource: URI, arg2?: any, arg3?: any): T {
		const position: IPosition = EditorPosition.isIPosition(arg2) ? arg2 : null;
		const section: string = position ? (typeof arg3 === 'string' ? arg3 : void 0) : (typeof arg2 === 'string' ? arg2 : void 0);
		return this.configurationService.getValue(section, { resource });
1316
	}
B
Benjamin Pasero 已提交
1317 1318
}

R
Ramya Achutha Rao 已提交
1319 1320 1321 1322 1323 1324 1325 1326
export class TestHashService implements IHashService {
	_serviceBrand: any;

	createSHA1(content: string): string {
		return content;
	}
}

B
Benjamin Pasero 已提交
1327 1328
export function getRandomTestPath(tmpdir: string, ...segments: string[]): string {
	return paths.join(tmpdir, ...segments, generateUuid());
1329
}