workbenchTestServices.ts 26.9 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';

B
Benjamin Pasero 已提交
8
import 'vs/workbench/parts/files/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';
J
Johannes Rieken 已提交
12
import { EventEmitter } from 'vs/base/common/eventEmitter';
13
import * as paths from 'vs/base/common/paths';
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';
18
import { IEditorGroup, ConfirmResult } from 'vs/workbench/common/editor';
J
Johannes Rieken 已提交
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 24
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IPartService } from 'vs/workbench/services/part/common/partService';
25
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
26
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
27
import { IEditorInput, IEditorOptions, Position, Direction, IEditor, IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
28 29 30
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IMessageService, IConfirmation } from 'vs/platform/message/common/message';
import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
31
import { ILifecycleService, ShutdownEvent, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
J
Johannes Rieken 已提交
32 33 34
import { EditorStacksModel } from 'vs/workbench/common/editor/editorStacksModel';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
I
isidor 已提交
35
import { IEditorGroupService, GroupArrangement, GroupOrientation, ITabOptions } from 'vs/workbench/services/group/common/groupService';
36
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
37
import { FileOperationEvent, IFileService, IResolveContentOptions, IFileOperationResult, IFileStat, IImportResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent } from 'vs/platform/files/common/files';
S
Sandeep Somavarapu 已提交
38
import { IModelService } from 'vs/editor/common/services/modelService';
39
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
J
Johannes Rieken 已提交
40 41 42 43 44 45 46 47 48
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IRawTextContent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { RawText } from 'vs/editor/common/model/textModel';
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 { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
49
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
50
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
51
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
B
Benjamin Pasero 已提交
52

S
Sandeep Somavarapu 已提交
53 54 55 56
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
	return instantiationService.createInstance(FileEditorInput, resource, void 0);
}

57
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
58

59
export class TestContextService implements IWorkspaceContextService {
60
	public _serviceBrand: any;
E
Erich Gamma 已提交
61 62 63 64

	private workspace: any;
	private options: any;

65
	constructor(workspace: any = TestWorkspace, options: any = null) {
E
Erich Gamma 已提交
66
		this.workspace = workspace;
67
		this.options = options || Object.create(null);
E
Erich Gamma 已提交
68 69
	}

B
Benjamin Pasero 已提交
70 71 72 73
	public hasWorkspace(): boolean {
		return !!this.workspace;
	}

E
Erich Gamma 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87
	public getWorkspace(): IWorkspace {
		return this.workspace;
	}

	public getOptions() {
		return this.options;
	}

	public updateOptions() {

	}

	public isInsideWorkspace(resource: URI): boolean {
		if (resource && this.workspace) {
88
			return paths.isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath);
E
Erich Gamma 已提交
89 90 91 92 93 94
		}

		return false;
	}

	public toWorkspaceRelativePath(resource: URI): string {
95
		return paths.makePosixAbsolute(paths.normalize(resource.fsPath.substr('c:'.length)));
E
Erich Gamma 已提交
96 97 98
	}

	public toResource(workspaceRelativePath: string): URI {
99
		return URI.file(paths.join('C:\\', workspaceRelativePath));
E
Erich Gamma 已提交
100 101 102
	}
}

103 104 105
export class TestTextFileService extends TextFileService {
	private promptPath: string;
	private confirmResult: ConfirmResult;
106
	private resolveTextContentError: IFileOperationResult;
A
Alex Dima 已提交
107 108

	constructor(
109 110
		@ILifecycleService lifecycleService: ILifecycleService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
A
Alex Dima 已提交
111 112
		@IConfigurationService configurationService: IConfigurationService,
		@ITelemetryService telemetryService: ITelemetryService,
113
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
A
Alex Dima 已提交
114
		@IFileService fileService: IFileService,
115
		@IUntitledEditorService untitledEditorService: IUntitledEditorService,
116
		@IInstantiationService instantiationService: IInstantiationService,
117 118
		@IMessageService messageService: IMessageService,
		@IBackupFileService backupFileService: IBackupFileService,
B
Benjamin Pasero 已提交
119 120
		@IWindowsService windowsService: IWindowsService,
		@IEditorGroupService editorGroupService: IEditorGroupService
A
Alex Dima 已提交
121
	) {
B
Benjamin Pasero 已提交
122
		super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, editorGroupService, windowsService);
A
Alex Dima 已提交
123
	}
124

125 126 127 128 129 130 131 132
	public setPromptPath(path: string): void {
		this.promptPath = path;
	}

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

133 134 135 136
	public setResolveTextContentErrorOnce(error: IFileOperationResult): void {
		this.resolveTextContentError = error;
	}

137
	public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
138 139 140 141 142 143 144
		if (this.resolveTextContentError) {
			const error = this.resolveTextContentError;
			this.resolveTextContentError = null;

			return TPromise.wrapError(error);
		}

145 146 147
		return this.fileService.resolveContent(resource, options).then((content) => {
			const raw = RawText.fromString(content.value, { defaultEOL: 1, detectIndentation: false, insertSpaces: false, tabSize: 4, trimAutoWhitespace: false });

148
			return <IRawTextContent>{
149
				resource: content.resource,
150 151 152 153 154 155
				name: content.name,
				mtime: content.mtime,
				etag: content.etag,
				encoding: content.encoding,
				value: raw,
				valueLogicalHash: null
156 157 158
			};
		});
	}
159 160 161 162 163 164 165 166

	public promptForPath(defaultPath?: string): string {
		return this.promptPath;
	}

	public confirmSave(resources?: URI[]): ConfirmResult {
		return this.confirmResult;
	}
D
Daniel Imms 已提交
167 168

	public showHotExitMessage(): void { }
A
Alex Dima 已提交
169 170
}

171
export function workbenchInstantiationService(): IInstantiationService {
172
	let instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
173 174 175 176 177 178 179
	instantiationService.stub(IWorkspaceContextService, new TestContextService(TestWorkspace));
	instantiationService.stub(IConfigurationService, new TestConfigurationService());
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
	instantiationService.stub(IStorageService, new TestStorageService());
	instantiationService.stub(IWorkbenchEditorService, new TestEditorService(function () { }));
	instantiationService.stub(IPartService, new TestPartService());
	instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
180
	instantiationService.stub(IModeService, ModeServiceImpl);
181
	instantiationService.stub(IHistoryService, {});
182
	instantiationService.stub(IHistoryService, 'getHistory', []);
S
Sandeep Somavarapu 已提交
183
	instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
184
	instantiationService.stub(IFileService, new TestFileService());
185
	instantiationService.stub(IBackupFileService, new TestBackupFileService());
186 187
	instantiationService.stub(ITelemetryService, NullTelemetryService);
	instantiationService.stub(IMessageService, new TestMessageService());
B
Benjamin Pasero 已提交
188
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
189
	instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(TestTextFileService));
B
Benjamin Pasero 已提交
190
	instantiationService.stub(ITextModelResolverService, <ITextModelResolverService>instantiationService.createInstance(TextModelResolverService));
191
	instantiationService.stub(IWindowsService, new TestWindowsService());
192 193 194 195

	return instantiationService;
}

E
Erich Gamma 已提交
196
export class TestMessageService implements IMessageService {
197
	public _serviceBrand: any;
E
Erich Gamma 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223

	private counter: number;

	constructor() {
		this.counter = 0;
	}

	public show(sev: Severity, message: any): () => void {
		this.counter++;

		return null;
	}

	public getCounter() {
		return this.counter;
	}

	public hideAll(): void {
		// No-op
	}

	public confirm(confirmation: IConfirmation): boolean {
		return false;
	}
}

224
export class TestPartService implements IPartService {
225
	public _serviceBrand: any;
E
Erich Gamma 已提交
226

227 228 229 230 231 232
	private _onTitleBarVisibilityChange = new Emitter<void>();

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

E
Erich Gamma 已提交
233 234 235 236 237 238 239
	public layout(): void { }

	public isCreated(): boolean {
		return true;
	}

	public joinCreation(): Promise {
A
Alex Dima 已提交
240
		return TPromise.as(null);
E
Erich Gamma 已提交
241 242 243 244 245 246 247 248 249 250
	}

	public hasFocus(part): boolean {
		return false;
	}

	public isVisible(part): boolean {
		return true;
	}

251 252 253 254
	public getContainer(part): HTMLElement {
		return null;
	}

B
Benjamin Pasero 已提交
255 256 257 258
	public isTitleBarHidden(): boolean {
		return false;
	}

259 260 261 262
	public getTitleBarOffset(): number {
		return 0;
	}

263 264 265 266
	public isStatusBarHidden(): boolean {
		return false;
	}

S
Sanders Lauture 已提交
267 268 269 270 271 272
	public isActivityBarHidden(): boolean {
		return false;
	}

	public setActivityBarHidden(hidden: boolean): void { }

E
Erich Gamma 已提交
273 274 275 276
	public isSideBarHidden(): boolean {
		return false;
	}

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

I
isidor 已提交
279
	public isPanelHidden(): boolean {
I
isidor 已提交
280 281 282
		return false;
	}

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

I
isidor 已提交
285 286
	public toggleMaximizedPanel(): void { }

E
Erich Gamma 已提交
287 288 289 290 291 292
	public getSideBarPosition() {
		return 0;
	}

	public addClass(clazz: string): void { }
	public removeClass(clazz: string): void { }
293
	public getWorkbenchElementId(): string { return ''; }
B
Benjamin Pasero 已提交
294

I
isidor 已提交
295
	public toggleZenMode(): void { }
E
Erich Gamma 已提交
296 297
}

298
export class TestStorageService extends EventEmitter implements IStorageService {
299
	public _serviceBrand: any;
E
Erich Gamma 已提交
300

B
Benjamin Pasero 已提交
301
	private storage: StorageService;
E
Erich Gamma 已提交
302 303 304 305 306

	constructor() {
		super();

		let context = new TestContextService();
B
Benjamin Pasero 已提交
307
		this.storage = new StorageService(new InMemoryLocalStorage(), null, context);
E
Erich Gamma 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
	}

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

	swap(key: string, valueA: any, valueB: any, scope: StorageScope = StorageScope.GLOBAL, defaultValue?: any): void {
		this.storage.swap(key, valueA, valueB, scope, defaultValue);
	}

	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);
	}
}

335
export class TestEditorGroupService implements IEditorGroupService {
336
	public _serviceBrand: any;
337 338

	private stacksModel: EditorStacksModel;
339 340 341

	private _onEditorsChanged: Emitter<void>;
	private _onEditorOpenFail: Emitter<IEditorInput>;
342
	private _onEditorsMoved: Emitter<void>;
343
	private _onGroupOrientationChanged: Emitter<void>;
I
isidor 已提交
344
	private _onTabOptionsChanged: Emitter<ITabOptions>;
345 346

	constructor(callback?: (method: string) => void) {
347
		this._onEditorsMoved = new Emitter<void>();
348
		this._onEditorsChanged = new Emitter<void>();
349
		this._onGroupOrientationChanged = new Emitter<void>();
350
		this._onEditorOpenFail = new Emitter<IEditorInput>();
I
isidor 已提交
351
		this._onTabOptionsChanged = new Emitter<ITabOptions>();
352

353 354 355
		let services = new ServiceCollection();

		services.set(IStorageService, new TestStorageService());
356
		services.set(IConfigurationService, new TestConfigurationService());
357
		services.set(IWorkspaceContextService, new TestContextService());
358 359
		const lifecycle = new TestLifecycleService();
		services.set(ILifecycleService, lifecycle);
360
		services.set(ITelemetryService, NullTelemetryService);
361 362 363

		let inst = new InstantiationService(services);

364
		this.stacksModel = inst.createInstance(EditorStacksModel, true);
365 366
	}

367 368 369 370 371 372 373 374 375 376 377 378
	public fireChange(): void {
		this._onEditorsChanged.fire();
	}

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

	public get onEditorOpenFail(): Event<IEditorInput> {
		return this._onEditorOpenFail.event;
	}

379 380 381 382
	public get onEditorsMoved(): Event<void> {
		return this._onEditorsMoved.event;
	}

383 384 385 386
	public get onGroupOrientationChanged(): Event<void> {
		return this._onGroupOrientationChanged.event;
	}

I
isidor 已提交
387 388
	public get onTabOptionsChanged(): Event<ITabOptions> {
		return this._onTabOptionsChanged.event;
389 390
	}

391 392 393
	public focusGroup(group: IEditorGroup): void;
	public focusGroup(position: Position): void;
	public focusGroup(arg1: any): void {
394 395 396

	}

397 398 399
	public activateGroup(group: IEditorGroup): void;
	public activateGroup(position: Position): void;
	public activateGroup(arg1: any): void {
400 401 402

	}

403 404 405
	public moveGroup(from: IEditorGroup, to: IEditorGroup): void;
	public moveGroup(from: Position, to: Position): void;
	public moveGroup(arg1: any, arg2: any): void {
406 407 408 409 410 411 412

	}

	public arrangeGroups(arrangement: GroupArrangement): void {

	}

413 414 415 416 417 418 419 420
	public setGroupOrientation(orientation: GroupOrientation): void {

	}

	public getGroupOrientation(): GroupOrientation {
		return 'vertical';
	}

421 422 423
	public pinEditor(group: IEditorGroup, input: IEditorInput): void;
	public pinEditor(position: Position, input: IEditorInput): void;
	public pinEditor(arg1: any, input: IEditorInput): void {
424 425
	}

426 427 428
	public unpinEditor(group: IEditorGroup, input: IEditorInput): void;
	public unpinEditor(position: Position, input: IEditorInput): void;
	public unpinEditor(arg1: any, input: IEditorInput): void {
429 430
	}

431 432 433
	public moveEditor(input: IEditorInput, from: IEditorGroup, to: IEditorGroup, index?: number): void;
	public moveEditor(input: IEditorInput, from: Position, to: Position, index?: number): void;
	public moveEditor(input: IEditorInput, from: any, to: any, index?: number): void {
434 435 436 437 438
	}

	public getStacksModel(): EditorStacksModel {
		return this.stacksModel;
	}
439

I
isidor 已提交
440 441
	public getTabOptions(): ITabOptions {
		return {};
442
	}
443 444
}

445
export class TestEditorService implements IWorkbenchEditorService {
446
	public _serviceBrand: any;
E
Erich Gamma 已提交
447

B
Benjamin Pasero 已提交
448 449 450
	public activeEditorInput: IEditorInput;
	public activeEditorOptions: IEditorOptions;
	public activeEditorPosition: Position;
E
Erich Gamma 已提交
451 452 453 454 455

	private callback: (method: string) => void;

	constructor(callback?: (method: string) => void) {
		this.callback = callback || ((s: string) => { });
B
Benjamin Pasero 已提交
456 457
	}

B
Benjamin Pasero 已提交
458
	public openEditors(inputs): Promise {
A
Alex Dima 已提交
459
		return TPromise.as([]);
E
Erich Gamma 已提交
460 461
	}

462 463 464 465
	public replaceEditors(editors): TPromise<IEditor[]> {
		return TPromise.as([]);
	}

466 467 468 469
	public closeEditors(position: Position, except?: IEditorInput, direction?: Direction): TPromise<void> {
		return TPromise.as(null);
	}

470
	public closeAllEditors(except?: Position): TPromise<void> {
A
Alex Dima 已提交
471
		return TPromise.as(null);
E
Erich Gamma 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
	}

	public isVisible(input: IEditorInput, includeDiff: boolean): boolean {
		return false;
	}

	public getActiveEditor(): IEditor {
		this.callback('getActiveEditor');

		return null;
	}

	public getActiveEditorInput(): IEditorInput {
		this.callback('getActiveEditorInput');

B
Benjamin Pasero 已提交
487
		return this.activeEditorInput;
E
Erich Gamma 已提交
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
	}

	public getVisibleEditors(): IEditor[] {
		this.callback('getVisibleEditors');

		return [];
	}

	public openEditor(input: any, options?: any, position?: any): Promise {
		this.callback('openEditor');

		this.activeEditorInput = input;
		this.activeEditorOptions = options;
		this.activeEditorPosition = position;

A
Alex Dima 已提交
503
		return TPromise.as(null);
E
Erich Gamma 已提交
504 505
	}

506
	public closeEditor(position: Position, input: IEditorInput): TPromise<void> {
E
Erich Gamma 已提交
507 508 509 510 511
		this.callback('closeEditor');

		return TPromise.as(null);
	}

512
	public createInput(input: IResourceInput): TPromise<IEditorInput> {
A
Alex Dima 已提交
513
		return TPromise.as(null);
E
Erich Gamma 已提交
514 515 516
	}
}

517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
export class TestFileService implements IFileService {

	public _serviceBrand: any;

	private _onFileChanges: Emitter<FileChangesEvent>;
	private _onAfterOperation: Emitter<FileOperationEvent>;

	constructor() {
		this._onFileChanges = new Emitter<FileChangesEvent>();
		this._onAfterOperation = new Emitter<FileOperationEvent>();
	}

	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 已提交
546
		return TPromise.as({
547 548
			resource,
			etag: Date.now().toString(),
B
Benjamin Pasero 已提交
549
			encoding: 'utf8',
B
Benjamin Pasero 已提交
550
			mtime: Date.now(),
551 552
			isDirectory: false,
			hasChildren: false,
B
Benjamin Pasero 已提交
553 554
			name: paths.basename(resource.fsPath)
		});
555
	}
B
Benjamin Pasero 已提交
556

557 558 559
	existsFile(resource: URI): TPromise<boolean> {
		return TPromise.as(null);
	}
B
Benjamin Pasero 已提交
560

561
	resolveContent(resource: URI, options?: IResolveContentOptions): TPromise<IContent> {
B
Benjamin Pasero 已提交
562 563
		return TPromise.as({
			resource: resource,
564 565
			value: 'Hello Html',
			etag: 'index.txt',
B
Benjamin Pasero 已提交
566 567
			encoding: 'utf8',
			mtime: Date.now(),
568
			name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
569
		});
570
	}
E
Erich Gamma 已提交
571

572
	resolveStreamContent(resource: URI, options?: IResolveContentOptions): TPromise<IStreamContent> {
A
Alex Dima 已提交
573 574 575
		return TPromise.as({
			resource: resource,
			value: {
576
				on: (event: string, callback: Function): void => {
A
Alex Dima 已提交
577 578 579 580 581 582 583 584 585 586
					if (event === 'data') {
						callback('Hello Html');
					}
					if (event === 'end') {
						callback();
					}
				}
			},
			etag: 'index.txt',
			encoding: 'utf8',
B
Benjamin Pasero 已提交
587
			mtime: Date.now(),
588
			name: paths.basename(resource.fsPath)
A
Alex Dima 已提交
589
		});
590 591 592 593 594
	}

	resolveContents(resources: URI[]): TPromise<IContent[]> {
		return TPromise.as(null);
	}
A
Alex Dima 已提交
595

596
	updateContent(resource: URI, value: string, options?: IUpdateContentOptions): TPromise<IFileStat> {
597
		return TPromise.timeout(1).then(() => {
E
Erich Gamma 已提交
598
			return {
599
				resource,
E
Erich Gamma 已提交
600
				etag: 'index.txt',
B
Benjamin Pasero 已提交
601
				encoding: 'utf8',
B
Benjamin Pasero 已提交
602
				mtime: Date.now(),
603 604 605
				isDirectory: false,
				hasChildren: false,
				name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
606 607
			};
		});
608
	}
D
Daniel Imms 已提交
609

610 611 612
	moveFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
613

614 615 616
	copyFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
617

618 619
	createFile(resource: URI, content?: string): TPromise<IFileStat> {
		return TPromise.as(null);
E
Erich Gamma 已提交
620
	}
621 622 623 624 625 626 627 628

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

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

630 631 632 633 634 635 636 637 638 639 640
	touchFile(resource: URI): TPromise<IFileStat> {
		return TPromise.as(null);
	}

	del(resource: URI, useTrash?: boolean): TPromise<void> {
		return TPromise.as(null);
	}

	importFile(source: URI, targetFolder: URI): TPromise<IImportResult> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
641

642 643 644 645 646 647 648 649 650 651 652 653 654 655
	watchFileChanges(resource: URI): void {
	}

	unwatchFileChanges(resource: URI): void;
	unwatchFileChanges(fsPath: string): void;
	unwatchFileChanges(arg1: any): void {
	}

	updateOptions(options: any): void {
	}

	getEncoding(resource: URI): string {
		return 'utf8';
	}
D
Daniel Imms 已提交
656

657
	dispose(): void {
E
Erich Gamma 已提交
658
	}
659
}
660

661 662
export class TestBackupFileService implements IBackupFileService {
	public _serviceBrand: any;
663 664 665 666 667

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

668
	public hasBackup(resource: URI): TPromise<boolean> {
669 670 671
		return TPromise.as(false);
	}

B
Benjamin Pasero 已提交
672 673 674 675 676 677 678 679 680 681
	public loadBackupResource(resource: URI): TPromise<URI> {
		return this.hasBackup(resource).then(hasBackup => {
			if (hasBackup) {
				return this.getBackupResource(resource);
			}

			return void 0;
		});
	}

D
Daniel Imms 已提交
682 683 684 685 686 687 688 689 690 691 692
	public registerResourceForBackup(resource: URI): TPromise<void> {
		return TPromise.as(void 0);
	}

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

	public getBackupResource(resource: URI): URI {
		return null;
	}
693

694
	public backupResource(resource: URI, content: string): TPromise<void> {
695 696 697
		return TPromise.as(void 0);
	}

698
	public getWorkspaceFileBackups(): TPromise<URI[]> {
699 700 701
		return TPromise.as([]);
	}

702 703 704 705
	public parseBackupContent(rawText: IRawTextContent): string {
		return rawText.value.lines.join('\n');
	}

706
	public discardResourceBackup(resource: URI): TPromise<void> {
707 708 709
		return TPromise.as(void 0);
	}

710
	public discardAllWorkspaceBackups(): TPromise<void> {
711 712
		return TPromise.as(void 0);
	}
D
Daniel Imms 已提交
713 714
};

715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
export class TestWindowService implements IWindowService {

	public _serviceBrand: any;

	getCurrentWindowId(): number {
		return 0;
	}

	openFileFolderPicker(forceNewWindow?: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}

	openFilePicker(forceNewWindow?: boolean, path?: string): TPromise<void> {
		return TPromise.as(void 0);
	}

	openFolderPicker(forceNewWindow?: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}

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

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

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

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

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

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

	addToRecentlyOpen(paths: { path: string, isFile?: boolean }[]): TPromise<void> {
		return TPromise.as(void 0);
	}

	removeFromRecentlyOpen(paths: string[]): TPromise<void> {
		return TPromise.as(void 0);
	}

	getRecentlyOpen(): TPromise<{ files: string[]; folders: string[]; }> {
		return TPromise.as(void 0);
	}

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

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

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

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

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

792 793
export class TestLifecycleService implements ILifecycleService {

794
	public _serviceBrand: any;
795

796
	public willShutdown: boolean;
797

798
	private _onWillShutdown = new Emitter<ShutdownEvent>();
799
	private _onShutdown = new Emitter<ShutdownReason>();
800 801 802 803

	constructor() {
	}

804 805
	public fireShutdown(reason = ShutdownReason.QUIT): void {
		this._onShutdown.fire(reason);
806 807
	}

808 809 810 811
	public fireWillShutdown(event: ShutdownEvent): void {
		this._onWillShutdown.fire(event);
	}

812 813 814 815
	public get onWillShutdown(): Event<ShutdownEvent> {
		return this._onWillShutdown.event;
	}

816
	public get onShutdown(): Event<ShutdownReason> {
817 818
		return this._onShutdown.event;
	}
819 820
}

821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
export class TestWindowsService implements IWindowsService {

	_serviceBrand: any;

	onWindowOpen: Event<number>;
	onWindowFocus: Event<number>;

	openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}
	openFilePicker(windowId: number, forceNewWindow?: boolean, path?: string): TPromise<void> {
		return TPromise.as(void 0);
	}
	openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}
	reloadWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	openDevTools(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	toggleDevTools(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	// TODO@joao: rename, shouldn't this be closeWindow?
	closeFolder(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	toggleFullScreen(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	setRepresentedFilename(windowId: number, fileName: string): TPromise<void> {
		return TPromise.as(void 0);
	}
	addToRecentlyOpen(paths: { path: string, isFile?: boolean }[]): TPromise<void> {
		return TPromise.as(void 0);
	}
	removeFromRecentlyOpen(paths: string[]): TPromise<void> {
		return TPromise.as(void 0);
	}
	getRecentlyOpen(windowId: number): TPromise<{ files: string[]; folders: string[]; }> {
		return TPromise.as(void 0);
	}
	focusWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	isMaximized(windowId: number): TPromise<boolean> {
		return TPromise.as(void 0);
	}
	maximizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	unmaximizeWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}
	quit(): TPromise<void> {
		return TPromise.as(void 0);
	}

	// Global methods
885
	openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean }): TPromise<void> {
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
		return TPromise.as(void 0);
	}
	openNewWindow(): TPromise<void> {
		return TPromise.as(void 0);
	}
	showWindow(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
	getWindows(): TPromise<{ id: number; path: string; title: string; }[]> {
		return TPromise.as(void 0);
	}
	getWindowCount(): TPromise<number> {
		return TPromise.as(void 0);
	}
	log(severity: string, ...messages: string[]): TPromise<void> {
		return TPromise.as(void 0);
	}
	// TODO@joao: what?
	closeExtensionHostWindow(extensionDevelopmentPath: string): TPromise<void> {
		return TPromise.as(void 0);
	}
	showItemInFolder(path: string): TPromise<void> {
		return TPromise.as(void 0);
	}

	// This needs to be handled from browser process to prevent
	// foreground ordering issues on Windows
	openExternal(url: string): TPromise<void> {
		return TPromise.as(void 0);
	}

	// TODO: this is a bit backwards
	startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void> {
		return TPromise.as(void 0);
	}
921
}