workbenchTestServices.ts 43.1 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';
13
import * as resources from 'vs/base/common/resources';
E
Erich Gamma 已提交
14
import URI from 'vs/base/common/uri';
15 16
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
17
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
B
Benjamin Pasero 已提交
18
import { ConfirmResult, IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent } from 'vs/workbench/common/editor';
B
Benjamin Pasero 已提交
19
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView, EditorGroupsServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
M
Matt Bierner 已提交
20
import { Event, Emitter } from 'vs/base/common/event';
E
Erich Gamma 已提交
21
import Severity from 'vs/base/common/severity';
22
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
23
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
J
Johannes Rieken 已提交
24
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
25
import { IPartService, Parts, Position as PartPosition, IDimension } from 'vs/workbench/services/part/common/partService';
26
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
27
import { ITextModelService } from 'vs/editor/common/services/resolverService';
B
Benjamin Pasero 已提交
28
import { IEditorOptions, IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
29
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
S
Sandeep Somavarapu 已提交
30
import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkbenchState, IWorkspaceFolder, IWorkspaceFoldersChangeEvent } from 'vs/platform/workspace/common/workspace';
31
import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
J
Johannes Rieken 已提交
32
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
33
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
34
import { FileOperationEvent, IFileService, IResolveContentOptions, FileOperationError, IFileStat, IResolveFileResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent, ICreateFileOptions, ITextSnapshot, IResourceEncodings } from 'vs/platform/files/common/files';
35
import { IModelService } from 'vs/editor/common/services/modelService';
36
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
J
Johannes Rieken 已提交
37 38 39 40 41 42
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';
43
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
44
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
45
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
46
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
47
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
B
Benjamin Pasero 已提交
48
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
49
import { IThemeService } from 'vs/platform/theme/common/themeService';
B
Benjamin Pasero 已提交
50 51
import { generateUuid } from 'vs/base/common/uuid';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
52
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } 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 { IMenuService, MenuId, IMenu, ISerializableCommandAction } 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
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
J
Joao Moreno 已提交
69
import { IDisposable, toDisposable, Disposable } 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';
76
import { Dimension } from 'vs/base/browser/dom';
I
isidor 已提交
77
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
B
Benjamin Pasero 已提交
78

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

83
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
84

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

88
	private workspace: IWorkbenchWorkspace;
E
Erich Gamma 已提交
89 90
	private options: any;

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

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

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

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

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

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

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

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

127
		return WorkbenchState.EMPTY;
S
Sandeep Somavarapu 已提交
128 129
	}

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

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

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

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

	public updateOptions() {

	}

	public isInsideWorkspace(resource: URI): boolean {
		if (resource && this.workspace) {
152
			return resources.isEqualOrParent(resource, this.workspace.folders[0].uri, resources.hasToIgnoreCase(resource));
E
Erich Gamma 已提交
153 154 155 156 157 158
		}

		return false;
	}

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

162 163
	public isCurrentWorkspace(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): boolean {
		return isSingleFolderWorkspaceIdentifier(workspaceIdentifier) && resources.isEqual(this.workspace.folders[0].uri, workspaceIdentifier, resources.hasToIgnoreCase(workspaceIdentifier));
164
	}
E
Erich Gamma 已提交
165 166
}

167
export class TestTextFileService extends TextFileService {
168 169
	public cleanupBackupsBeforeShutdownCalled: boolean;

170 171
	private promptPath: string;
	private confirmResult: ConfirmResult;
172
	private resolveTextContentError: FileOperationError;
A
Alex Dima 已提交
173 174

	constructor(
175 176
		@ILifecycleService lifecycleService: ILifecycleService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
A
Alex Dima 已提交
177 178
		@IConfigurationService configurationService: IConfigurationService,
		@IFileService fileService: IFileService,
179
		@IUntitledEditorService untitledEditorService: IUntitledEditorService,
180
		@IInstantiationService instantiationService: IInstantiationService,
181
		@INotificationService notificationService: INotificationService,
182
		@IBackupFileService backupFileService: IBackupFileService,
183
		@IWindowsService windowsService: IWindowsService,
I
isidor 已提交
184
		@IHistoryService historyService: IHistoryService,
B
Benjamin Pasero 已提交
185 186
		@IContextKeyService contextKeyService: IContextKeyService,
		@IModelService modelService: IModelService
A
Alex Dima 已提交
187
	) {
188
		super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, notificationService, TestEnvironmentService, backupFileService, windowsService, historyService, contextKeyService, modelService);
A
Alex Dima 已提交
189
	}
190

191 192 193 194 195 196 197 198
	public setPromptPath(path: string): void {
		this.promptPath = path;
	}

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

199
	public setResolveTextContentErrorOnce(error: FileOperationError): void {
200 201 202
		this.resolveTextContentError = error;
	}

203
	public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
204 205 206 207
		if (this.resolveTextContentError) {
			const error = this.resolveTextContentError;
			this.resolveTextContentError = null;

208
			return TPromise.wrapError<IRawTextContent>(error);
209 210
		}

211 212
		return this.fileService.resolveContent(resource, options).then((content): IRawTextContent => {
			return {
213
				resource: content.resource,
214 215 216 217
				name: content.name,
				mtime: content.mtime,
				etag: content.etag,
				encoding: content.encoding,
218
				value: createTextBufferFactory(content.value)
219 220 221
			};
		});
	}
222

223 224
	public promptForPath(defaultPath: string): TPromise<string> {
		return TPromise.wrap(this.promptPath);
225 226
	}

227 228
	public confirmSave(resources?: URI[]): TPromise<ConfirmResult> {
		return TPromise.wrap(this.confirmResult);
229
	}
D
Daniel Imms 已提交
230

231 232
	public onFilesConfigurationChange(configuration: any): void {
		super.onFilesConfigurationChange(configuration);
233 234 235 236 237 238
	}

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

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

	return instantiationService;
}

I
isidor 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291
export class TestLogService implements ILogService {
	_serviceBrand: any; onDidChangeLogLevel: Event<LogLevel>;
	getLevel(): LogLevel { return LogLevel.Info; }
	setLevel(level: LogLevel): void { }
	trace(message: string, ...args: any[]): void { }
	debug(message: string, ...args: any[]): void { }
	info(message: string, ...args: any[]): void { }
	warn(message: string, ...args: any[]): void { }
	error(message: string | Error, ...args: any[]): void { }
	critical(message: string | Error, ...args: any[]): void { }
	dispose(): void { }
}

B
Benjamin Pasero 已提交
292 293 294
export class TestDecorationsService implements IDecorationsService {
	_serviceBrand: any;
	onDidChangeDecorations: Event<IResourceDecorationChangeEvent> = Event.None;
J
Joao Moreno 已提交
295
	registerDecorationsProvider(provider: IDecorationsProvider): IDisposable { return Disposable.None; }
B
Benjamin Pasero 已提交
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 321 322 323 324 325 326 327
	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 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
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 {
	}

344 345 346
	public last(): void {
	}

B
Benjamin Pasero 已提交
347 348 349 350 351 352 353 354 355 356
	public remove(input: IEditorInput | IResourceInput): void {
	}

	public clear(): void {
	}

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

357
	public getLastActiveWorkspaceRoot(schemeFilter?: string): URI {
B
Benjamin Pasero 已提交
358 359
		return this.root;
	}
360 361 362 363

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

366
export class TestDialogService implements IDialogService {
367 368

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

370
	public confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
371 372
		return TPromise.as({ confirmed: false });
	}
373

374
	public show(severity: Severity, message: string, buttons: string[], options?: IDialogOptions): Promise<number, any> {
375 376
		return TPromise.as(0);
	}
E
Erich Gamma 已提交
377 378
}

379
export class TestPartService implements IPartService {
B
Benjamin Pasero 已提交
380

381
	public _serviceBrand: any;
E
Erich Gamma 已提交
382

383
	private _onTitleBarVisibilityChange = new Emitter<void>();
384
	private _onMenubarVisibilityChange = new Emitter<Dimension>();
385
	private _onEditorLayout = new Emitter<IDimension>();
386 387 388 389 390

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

391 392 393 394
	public get onMenubarVisibilityChange(): Event<Dimension> {
		return this._onMenubarVisibilityChange.event;
	}

395
	public get onEditorLayout(): Event<IDimension> {
396 397 398
		return this._onEditorLayout.event;
	}

E
Erich Gamma 已提交
399 400 401 402 403 404
	public layout(): void { }

	public isCreated(): boolean {
		return true;
	}

M
Matt Bierner 已提交
405
	public hasFocus(part: Parts): boolean {
E
Erich Gamma 已提交
406 407 408
		return false;
	}

M
Matt Bierner 已提交
409
	public isVisible(part: Parts): boolean {
E
Erich Gamma 已提交
410 411 412
		return true;
	}

M
Matt Bierner 已提交
413
	public getContainer(part: Parts): HTMLElement {
414 415 416
		return null;
	}

B
Benjamin Pasero 已提交
417 418 419 420
	public isTitleBarHidden(): boolean {
		return false;
	}

421 422 423 424
	public getTitleBarOffset(): number {
		return 0;
	}

425 426 427 428
	public isStatusBarHidden(): boolean {
		return false;
	}

S
Sanders Lauture 已提交
429 430 431 432 433 434
	public isActivityBarHidden(): boolean {
		return false;
	}

	public setActivityBarHidden(hidden: boolean): void { }

E
Erich Gamma 已提交
435 436 437 438
	public isSideBarHidden(): boolean {
		return false;
	}

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

I
isidor 已提交
441
	public isPanelHidden(): boolean {
I
isidor 已提交
442 443 444
		return false;
	}

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

I
isidor 已提交
447 448
	public toggleMaximizedPanel(): void { }

B
Benjamin Pasero 已提交
449 450 451 452
	public isPanelMaximized(): boolean {
		return false;
	}

E
Erich Gamma 已提交
453 454 455 456
	public getSideBarPosition() {
		return 0;
	}

I
isidor 已提交
457 458 459 460
	public getPanelPosition() {
		return 0;
	}

I
isidor 已提交
461 462 463 464
	public setPanelPosition(position: PartPosition): TPromise<void> {
		return TPromise.as(null);
	}

E
Erich Gamma 已提交
465 466
	public addClass(clazz: string): void { }
	public removeClass(clazz: string): void { }
467
	public getWorkbenchElementId(): string { return ''; }
B
Benjamin Pasero 已提交
468

I
isidor 已提交
469
	public toggleZenMode(): void { }
470

B
Benjamin Pasero 已提交
471
	public isEditorLayoutCentered(): boolean { return false; }
472
	public centerEditorLayout(active: boolean): void { }
S
SrTobi 已提交
473 474


475
	public resizePart(part: Parts, sizeChange: number): void { }
E
Erich Gamma 已提交
476 477
}

478
export class TestStorageService implements IStorageService {
479
	public _serviceBrand: any;
E
Erich Gamma 已提交
480

B
Benjamin Pasero 已提交
481
	private storage: StorageService;
E
Erich Gamma 已提交
482 483 484

	constructor() {
		let context = new TestContextService();
485
		this.storage = new StorageService(new InMemoryLocalStorage(), null, context.getWorkspace().id);
E
Erich Gamma 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
	}

	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 已提交
509
export class TestEditorGroupsService implements EditorGroupsServiceImpl {
510 511
	_serviceBrand: ServiceIdentifier<any>;

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

514 515 516 517
	onDidActiveGroupChange: Event<IEditorGroup> = Event.None;
	onDidAddGroup: Event<IEditorGroup> = Event.None;
	onDidRemoveGroup: Event<IEditorGroup> = Event.None;
	onDidMoveGroup: Event<IEditorGroup> = Event.None;
518 519

	orientation: any;
520
	whenRestored: TPromise<void> = TPromise.as(void 0);
521

522
	get activeGroup(): IEditorGroup {
523 524 525 526 527 528 529
		return this.groups[0];
	}

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

530
	getGroups(order?: GroupsOrder): ReadonlyArray<IEditorGroup> {
531 532 533
		return this.groups;
	}

534
	getGroup(identifier: number): IEditorGroup {
535 536 537 538 539 540 541 542 543
		for (let i = 0; i < this.groups.length; i++) {
			if (this.groups[i].id === identifier) {
				return this.groups[i];
			}
		}

		return void 0;
	}

544 545 546 547
	getLabel(identifier: number): string {
		return 'Group 1';
	}

B
Benjamin Pasero 已提交
548
	findGroup(scope: IFindGroupScope, source?: number | IEditorGroup, wrap?: boolean): IEditorGroup {
549 550 551
		return null;
	}

552
	activateGroup(group: number | IEditorGroup): IEditorGroup {
553 554 555
		return null;
	}

556 557
	getSize(group: number | IEditorGroup): number {
		return 100;
558 559
	}

560 561
	setSize(group: number | IEditorGroup, size: number): void { }

562 563
	arrangeGroups(arrangement: GroupsArrangement): void { }

564 565
	applyLayout(layout: EditorGroupLayout): void { }

566 567
	setGroupOrientation(orientation: any): void { }

568
	addGroup(location: number | IEditorGroup, direction: GroupDirection, options?: IAddGroupOptions): IEditorGroup {
569 570 571
		return null;
	}

572
	removeGroup(group: number | IEditorGroup): void { }
573

574
	moveGroup(group: number | IEditorGroup, location: number | IEditorGroup, direction: GroupDirection): IEditorGroup {
575 576 577
		return null;
	}

578
	mergeGroup(group: number | IEditorGroup, target: number | IEditorGroup, options?: IMergeGroupOptions): IEditorGroup {
579 580 581
		return null;
	}

582
	copyGroup(group: number | IEditorGroup, location: number | IEditorGroup, direction: GroupDirection): IEditorGroup {
583 584 585 586
		return null;
	}
}

B
Benjamin Pasero 已提交
587
export class TestEditorGroup implements IEditorGroupView {
588 589 590

	constructor(public id: number) { }

B
Benjamin Pasero 已提交
591
	group: EditorGroup = void 0;
592 593 594 595
	activeControl: IEditor;
	activeEditor: IEditorInput;
	previewEditor: IEditorInput;
	count: number;
B
Benjamin Pasero 已提交
596
	disposed: boolean;
B
Benjamin Pasero 已提交
597
	editors: ReadonlyArray<IEditorInput> = [];
598
	label: string;
B
Benjamin Pasero 已提交
599 600 601 602 603 604
	whenRestored: Promise<void, any> = TPromise.as(void 0);
	element: HTMLElement;
	minimumWidth: number;
	maximumWidth: number;
	minimumHeight: number;
	maximumHeight: number;
605 606

	onWillDispose: Event<void> = Event.None;
607
	onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
B
Benjamin Pasero 已提交
608 609
	onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
610 611
	onWillOpenEditor: Event<IEditorOpeningEvent> = Event.None;
	onDidOpenEditorFail: Event<IEditorInput> = Event.None;
B
Benjamin Pasero 已提交
612 613
	onDidFocus: Event<void> = Event.None;
	onDidChange: Event<{ width: number; height: number; }> = Event.None;
614

B
Benjamin Pasero 已提交
615 616 617 618
	getEditors(order?: EditorsOrder): ReadonlyArray<IEditorInput> {
		return [];
	}

619 620 621 622 623 624 625 626
	getEditor(index: number): IEditorInput {
		return null;
	}

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

627
	openEditor(editor: IEditorInput, options?: IEditorOptions): TPromise<void> {
628 629 630
		return TPromise.as(void 0);
	}

631
	openEditors(editors: IEditorInputWithOptions[]): TPromise<void> {
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
		return TPromise.as(void 0);
	}

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

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

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

647
	moveEditor(editor: IEditorInput, target: IEditorGroup, options?: IMoveEditorOptions): void { }
648

649
	copyEditor(editor: IEditorInput, target: IEditorGroup, options?: ICopyEditorOptions): void { }
650

651
	closeEditor(editor?: IEditorInput): TPromise<void> {
652 653 654
		return TPromise.as(void 0);
	}

655
	closeEditors(editors: IEditorInput[] | { except?: IEditorInput; direction?: CloseDirection; savedOnly?: boolean; }): TPromise<void> {
656 657 658
		return TPromise.as(void 0);
	}

659
	closeAllEditors(): TPromise<void> {
660 661 662
		return TPromise.as(void 0);
	}

663
	replaceEditors(editors: IEditorReplacement[]): TPromise<void> {
664 665 666 667 668 669 670 671 672 673
		return TPromise.as(void 0);
	}

	pinEditor(editor?: IEditorInput): void { }

	focus(): void { }

	invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T {
		return fn(null);
	}
B
Benjamin Pasero 已提交
674 675 676 677 678 679 680 681

	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 { }
682
	relayout() { }
683 684
}

B
Benjamin Pasero 已提交
685
export class TestEditorService implements EditorServiceImpl {
686 687 688 689 690

	_serviceBrand: ServiceIdentifier<any>;

	onDidActiveEditorChange: Event<void> = Event.None;
	onDidVisibleEditorsChange: Event<void> = Event.None;
B
Benjamin Pasero 已提交
691
	onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
692 693 694
	onDidOpenEditorFail: Event<IEditorIdentifier> = Event.None;

	activeControl: IEditor;
695
	activeTextEditorWidget: any;
696
	activeEditor: IEditorInput;
697
	editors: ReadonlyArray<IEditorInput> = [];
B
Benjamin Pasero 已提交
698
	visibleControls: ReadonlyArray<IEditor> = [];
699
	visibleTextEditorWidgets = [];
B
Benjamin Pasero 已提交
700
	visibleEditors: ReadonlyArray<IEditorInput> = [];
701

702 703 704 705
	overrideOpenEditor(handler: IOpenEditorOverrideHandler): IDisposable {
		return toDisposable(() => void 0);
	}

706 707 708 709 710 711 712 713 714 715 716 717
	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;
	}

718 719 720 721
	replaceEditors(editors: any, group: any) {
		return TPromise.as(void 0);
	}

722 723 724 725 726 727 728 729 730
	invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
		return fn(null);
	}

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

731 732 733 734
export class TestFileService implements IFileService {

	public _serviceBrand: any;

735 736
	public encoding: IResourceEncodings;

M
Matt Bierner 已提交
737 738
	private readonly _onFileChanges: Emitter<FileChangesEvent>;
	private readonly _onAfterOperation: Emitter<FileOperationEvent>;
739

740 741
	private content = 'Hello Html';

742 743 744 745 746
	constructor() {
		this._onFileChanges = new Emitter<FileChangesEvent>();
		this._onAfterOperation = new Emitter<FileOperationEvent>();
	}

747 748 749 750 751 752 753 754
	public setContent(content: string): void {
		this.content = content;
	}

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

755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
	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 已提交
772
		return TPromise.as({
773 774
			resource,
			etag: Date.now().toString(),
B
Benjamin Pasero 已提交
775
			encoding: 'utf8',
B
Benjamin Pasero 已提交
776
			mtime: Date.now(),
777
			isDirectory: false,
B
Benjamin Pasero 已提交
778 779
			name: paths.basename(resource.fsPath)
		});
780
	}
B
Benjamin Pasero 已提交
781

I
isidor 已提交
782 783
	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 已提交
784 785
	}

786 787 788
	existsFile(resource: URI): TPromise<boolean> {
		return TPromise.as(null);
	}
B
Benjamin Pasero 已提交
789

790
	resolveContent(resource: URI, options?: IResolveContentOptions): TPromise<IContent> {
B
Benjamin Pasero 已提交
791 792
		return TPromise.as({
			resource: resource,
793
			value: this.content,
794
			etag: 'index.txt',
B
Benjamin Pasero 已提交
795 796
			encoding: 'utf8',
			mtime: Date.now(),
797
			name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
798
		});
799
	}
E
Erich Gamma 已提交
800

801
	resolveStreamContent(resource: URI, options?: IResolveContentOptions): TPromise<IStreamContent> {
A
Alex Dima 已提交
802 803 804
		return TPromise.as({
			resource: resource,
			value: {
805
				on: (event: string, callback: Function): void => {
A
Alex Dima 已提交
806
					if (event === 'data') {
807
						callback(this.content);
A
Alex Dima 已提交
808 809 810 811 812 813 814 815
					}
					if (event === 'end') {
						callback();
					}
				}
			},
			etag: 'index.txt',
			encoding: 'utf8',
B
Benjamin Pasero 已提交
816
			mtime: Date.now(),
817
			name: paths.basename(resource.fsPath)
A
Alex Dima 已提交
818
		});
819 820
	}

821
	updateContent(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): TPromise<IFileStat> {
822
		return TPromise.timeout(1).then(() => {
E
Erich Gamma 已提交
823
			return {
824
				resource,
E
Erich Gamma 已提交
825
				etag: 'index.txt',
B
Benjamin Pasero 已提交
826
				encoding: 'utf8',
B
Benjamin Pasero 已提交
827
				mtime: Date.now(),
828 829
				isDirectory: false,
				name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
830 831
			};
		});
832
	}
D
Daniel Imms 已提交
833

834 835 836
	moveFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
837

838 839 840
	copyFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
841

842
	createFile(resource: URI, content?: string, options?: ICreateFileOptions): TPromise<IFileStat> {
843
		return TPromise.as(null);
E
Erich Gamma 已提交
844
	}
845 846 847 848 849

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

850 851 852 853 854 855
	onDidChangeFileSystemProviderRegistrations = Event.None;

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

856 857 858 859
	canHandleResource(resource: URI): boolean {
		return resource.scheme === 'file';
	}

860
	del(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): TPromise<void> {
861 862 863 864 865 866
		return TPromise.as(null);
	}

	watchFileChanges(resource: URI): void {
	}

J
Johannes Rieken 已提交
867
	unwatchFileChanges(resource: URI): void {
868 869
	}

870
	getWriteEncoding(resource: URI): string {
871 872
		return 'utf8';
	}
D
Daniel Imms 已提交
873

874
	dispose(): void {
E
Erich Gamma 已提交
875
	}
876
}
877

878 879
export class TestBackupFileService implements IBackupFileService {
	public _serviceBrand: any;
880 881 882 883 884

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

885
	public hasBackup(resource: URI): TPromise<boolean> {
886 887 888
		return TPromise.as(false);
	}

B
Benjamin Pasero 已提交
889 890 891
	public loadBackupResource(resource: URI): TPromise<URI> {
		return this.hasBackup(resource).then(hasBackup => {
			if (hasBackup) {
892
				return this.toBackupResource(resource);
B
Benjamin Pasero 已提交
893 894 895 896 897 898
			}

			return void 0;
		});
	}

D
Daniel Imms 已提交
899 900 901 902 903 904 905 906
	public registerResourceForBackup(resource: URI): TPromise<void> {
		return TPromise.as(void 0);
	}

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

907
	public toBackupResource(resource: URI): URI {
D
Daniel Imms 已提交
908 909
		return null;
	}
910

911
	public backupResource(resource: URI, content: ITextSnapshot): TPromise<void> {
912 913 914
		return TPromise.as(void 0);
	}

915
	public getWorkspaceFileBackups(): TPromise<URI[]> {
916 917 918
		return TPromise.as([]);
	}

919 920 921 922 923
	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);
924 925
	}

926 927 928 929
	public resolveBackupContent(backup: URI): TPromise<ITextBufferFactory> {
		return TPromise.as(null);
	}

930
	public discardResourceBackup(resource: URI): TPromise<void> {
931 932 933
		return TPromise.as(void 0);
	}

934
	public discardAllWorkspaceBackups(): TPromise<void> {
935 936
		return TPromise.as(void 0);
	}
937
}
D
Daniel Imms 已提交
938

B
Benjamin Pasero 已提交
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
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) { }
959
	getActiveCodeEditor(): ICodeEditor { return null; }
960
	openCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise<ICodeEditor> { return TPromise.as(null); }
B
Benjamin Pasero 已提交
961 962
}

963 964 965 966
export class TestWindowService implements IWindowService {

	public _serviceBrand: any;

967
	onDidChangeFocus: Event<boolean> = new Emitter<boolean>().event;
S
SteVen Batten 已提交
968
	onDidChangeMaximize: Event<boolean>;
969

970 971 972 973
	isFocused(): TPromise<boolean> {
		return TPromise.as(false);
	}

S
SteVen Batten 已提交
974 975 976 977
	isMaximized(): TPromise<boolean> {
		return TPromise.as(false);
	}

978 979 980 981
	getConfiguration(): IWindowConfiguration {
		return Object.create(null);
	}

982 983 984 985
	getCurrentWindowId(): number {
		return 0;
	}

B
Benjamin Pasero 已提交
986
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
987 988 989
		return TPromise.as(void 0);
	}

B
Benjamin Pasero 已提交
990
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
991 992 993
		return TPromise.as(void 0);
	}

B
Benjamin Pasero 已提交
994
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
995 996 997
		return TPromise.as(void 0);
	}

998 999 1000 1001
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
		return TPromise.as(void 0);
	}

1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
	reloadWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}

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

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

1014
	closeWorkspace(): TPromise<void> {
1015 1016 1017
		return TPromise.as(void 0);
	}

1018 1019 1020 1021
	enterWorkspace(path: string): TPromise<IEnterWorkspaceResult> {
		return TPromise.as(void 0);
	}

1022
	createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
1023 1024 1025
		return TPromise.as(void 0);
	}

1026
	saveAndEnterWorkspace(path: string): TPromise<IEnterWorkspaceResult> {
1027 1028 1029
		return TPromise.as(void 0);
	}

1030 1031 1032 1033 1034 1035 1036 1037
	toggleFullScreen(): TPromise<void> {
		return TPromise.as(void 0);
	}

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

1038
	getRecentlyOpened(): TPromise<IRecentlyOpened> {
1039 1040 1041 1042 1043 1044 1045
		return TPromise.as(void 0);
	}

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

S
SteVen Batten 已提交
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
	maximizeWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}

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

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

1058
	openWindow(paths: URI[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): TPromise<void> {
B
Benjamin Pasero 已提交
1059 1060 1061
		return TPromise.as(void 0);
	}

1062 1063 1064 1065
	closeWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}

1066 1067 1068 1069
	setDocumentEdited(flag: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}

1070 1071 1072
	onWindowTitleDoubleClick(): TPromise<void> {
		return TPromise.as(void 0);
	}
1073

J
Joao 已提交
1074 1075 1076 1077
	show(): TPromise<void> {
		return TPromise.as(void 0);
	}

1078 1079
	showMessageBox(options: Electron.MessageBoxOptions): TPromise<IMessageBoxResult> {
		return TPromise.wrap({ button: 0 });
1080 1081
	}

1082 1083
	showSaveDialog(options: Electron.SaveDialogOptions): TPromise<string> {
		return TPromise.wrap(void 0);
1084
	}
1085

1086 1087
	showOpenDialog(options: Electron.OpenDialogOptions): TPromise<string[]> {
		return TPromise.wrap(void 0);
1088
	}
1089

B
Benjamin Pasero 已提交
1090
	updateTouchBar(items: ISerializableCommandAction[][]): Promise<void> {
1091 1092
		return TPromise.as(void 0);
	}
1093 1094
}

1095 1096
export class TestLifecycleService implements ILifecycleService {

1097
	public _serviceBrand: any;
1098

1099
	public phase: LifecyclePhase;
1100
	public startupKind: StartupKind;
1101

1102
	private _onWillShutdown = new Emitter<ShutdownEvent>();
1103
	private _onShutdown = new Emitter<ShutdownReason>();
1104

1105
	when(): TPromise<void> {
1106
		return TPromise.as(void 0);
B
Benjamin Pasero 已提交
1107
	}
1108

1109 1110
	public fireShutdown(reason = ShutdownReason.QUIT): void {
		this._onShutdown.fire(reason);
1111 1112
	}

1113 1114 1115 1116
	public fireWillShutdown(event: ShutdownEvent): void {
		this._onWillShutdown.fire(event);
	}

1117 1118 1119 1120
	public get onWillShutdown(): Event<ShutdownEvent> {
		return this._onWillShutdown.event;
	}

1121
	public get onShutdown(): Event<ShutdownReason> {
1122 1123
		return this._onShutdown.event;
	}
1124 1125
}

1126 1127 1128 1129
export class TestWindowsService implements IWindowsService {

	_serviceBrand: any;

1130 1131
	public windowCount = 1;

1132 1133
	onWindowOpen: Event<number>;
	onWindowFocus: Event<number>;
1134
	onWindowBlur: Event<number>;
S
SteVen Batten 已提交
1135 1136
	onWindowMaximize: Event<number>;
	onWindowUnmaximize: Event<number>;
S
SteVen Batten 已提交
1137
	onRecentlyOpenedChange: Event<void>;
1138

1139 1140 1141 1142
	isFocused(windowId: number): TPromise<boolean> {
		return TPromise.as(false);
	}

B
Benjamin Pasero 已提交
1143
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
1144 1145
		return TPromise.as(void 0);
	}
1146

B
Benjamin Pasero 已提交
1147
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
1148 1149
		return TPromise.as(void 0);
	}
1150

B
Benjamin Pasero 已提交
1151
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
1152 1153
		return TPromise.as(void 0);
	}
1154

1155 1156 1157 1158
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
		return TPromise.as(void 0);
	}

1159 1160 1161
	reloadWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1162

1163 1164 1165
	openDevTools(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1166

1167 1168 1169
	toggleDevTools(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1170

1171
	closeWorkspace(windowId: number): TPromise<void> {
1172 1173
		return TPromise.as(void 0);
	}
1174

1175 1176 1177 1178
	enterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
		return TPromise.as(void 0);
	}

1179
	createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
1180 1181 1182
		return TPromise.as(void 0);
	}

1183
	saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
1184 1185 1186
		return TPromise.as(void 0);
	}

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

1191 1192 1193
	setRepresentedFilename(windowId: number, fileName: string): TPromise<void> {
		return TPromise.as(void 0);
	}
1194

1195
	addRecentlyOpened(files: string[]): TPromise<void> {
1196 1197
		return TPromise.as(void 0);
	}
1198

1199
	removeFromRecentlyOpened(paths: string[]): TPromise<void> {
1200 1201
		return TPromise.as(void 0);
	}
1202

B
Benjamin Pasero 已提交
1203
	clearRecentlyOpened(): TPromise<void> {
C
22768  
Cristian 已提交
1204 1205
		return TPromise.as(void 0);
	}
1206

1207
	getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened> {
1208 1209
		return TPromise.as(void 0);
	}
1210

1211 1212 1213
	focusWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1214

1215 1216 1217 1218
	closeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}

1219 1220 1221
	isMaximized(windowId: number): TPromise<boolean> {
		return TPromise.as(void 0);
	}
1222

1223 1224 1225
	maximizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1226

S
SteVen Batten 已提交
1227 1228 1229 1230
	minimizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}

1231 1232 1233
	unmaximizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1234

1235 1236 1237
	onWindowTitleDoubleClick(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1238

1239 1240 1241
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}
1242

1243 1244 1245
	quit(): TPromise<void> {
		return TPromise.as(void 0);
	}
1246

J
Johannes Rieken 已提交
1247 1248 1249
	relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void> {
		return TPromise.as(void 0);
	}
1250

1251 1252 1253
	whenSharedProcessReady(): TPromise<void> {
		return TPromise.as(void 0);
	}
1254

1255 1256 1257
	toggleSharedProcess(): TPromise<void> {
		return TPromise.as(void 0);
	}
1258

1259
	// Global methods
1260
	openWindow(windowId: number, paths: URI[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): TPromise<void> {
1261 1262
		return TPromise.as(void 0);
	}
1263

1264 1265 1266
	openNewWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}
1267

1268 1269 1270
	showWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
1271

1272
	getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]> {
1273 1274
		return TPromise.as(void 0);
	}
1275

1276
	getWindowCount(): TPromise<number> {
1277
		return TPromise.as(this.windowCount);
1278
	}
1279

1280 1281 1282
	log(severity: string, ...messages: string[]): TPromise<void> {
		return TPromise.as(void 0);
	}
1283

1284 1285 1286 1287
	showItemInFolder(path: string): TPromise<void> {
		return TPromise.as(void 0);
	}

1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
	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);
1306 1307
	}

B
Benjamin Pasero 已提交
1308
	updateTouchBar(windowId: number, items: ISerializableCommandAction[][]): Promise<void> {
1309
		return TPromise.as(void 0);
1310 1311
	}

J
Joao Moreno 已提交
1312 1313 1314 1315
	getActiveWindowId(): TPromise<number | undefined> {
		return TPromise.as(undefined);
	}

1316 1317
	// This needs to be handled from browser process to prevent
	// foreground ordering issues on Windows
1318 1319
	openExternal(url: string): TPromise<boolean> {
		return TPromise.as(true);
1320 1321 1322 1323 1324 1325
	}

	// TODO: this is a bit backwards
	startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void> {
		return TPromise.as(void 0);
	}
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337

	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 已提交
1338

S
SteVen Batten 已提交
1339 1340 1341 1342
	openAccessibilityOptions(): TPromise<void> {
		return TPromise.as(void 0);
	}

J
Joao Moreno 已提交
1343 1344 1345
	openAboutDialog(): TPromise<void> {
		return TPromise.as(void 0);
	}
1346
}
B
Benjamin Pasero 已提交
1347

1348 1349 1350 1351 1352 1353 1354
export class TestTextResourceConfigurationService implements ITextResourceConfigurationService {

	_serviceBrand: any;

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

1355
	public onDidChangeConfiguration() {
1356 1357 1358
		return { dispose() { } };
	}

1359 1360 1361 1362
	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 });
1363
	}
B
Benjamin Pasero 已提交
1364 1365
}

R
Ramya Achutha Rao 已提交
1366 1367 1368 1369 1370 1371 1372 1373
export class TestHashService implements IHashService {
	_serviceBrand: any;

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

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