workbenchTestServices.ts 31.0 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
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
24
import { IPartService, Parts } 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';
27
import { IEditorInput, IEditorOptions, Position, Direction, IEditor, IResourceInput } from 'vs/platform/editor/common/editor';
J
Johannes Rieken 已提交
28 29
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IMessageService, IConfirmation } from 'vs/platform/message/common/message';
30
import { ILegacyWorkspace, IWorkspaceContextService, IWorkspace2 } from 'vs/platform/workspace/common/workspace';
31
import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase } 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';
35
import { IEditorGroupService, GroupArrangement, GroupOrientation, ITabOptions, IMoveOptions } from 'vs/workbench/services/group/common/groupService';
36
import { TextFileService } from 'vs/workbench/services/textfile/common/textFileService';
B
Benjamin Pasero 已提交
37
import { FileOperationEvent, IFileService, IResolveContentOptions, IFileOperationResult, IFileStat, IImportResult, FileChangesEvent, IResolveFileOptions, IContent, IUpdateContentOptions, IStreamContent, isEqualOrParent } from 'vs/platform/files/common/files';
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
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 { 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';
48
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
49
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
50
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
A
Alex Dima 已提交
51
import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
B
Benjamin Pasero 已提交
52
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
53
import { IThemeService, ITheme, DARK } from 'vs/platform/theme/common/themeService';
54
import { Color } from 'vs/base/common/color';
55
import { isLinux } from 'vs/base/common/platform';
56
import { generateUuid } from "vs/base/common/uuid";
B
Benjamin Pasero 已提交
57

S
Sandeep Somavarapu 已提交
58 59 60 61
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
	return instantiationService.createInstance(FileEditorInput, resource, void 0);
}

62
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
63

64
export class TestContextService implements IWorkspaceContextService {
65
	public _serviceBrand: any;
E
Erich Gamma 已提交
66

67
	private workspace: ILegacyWorkspace;
68
	private id: string;
E
Erich Gamma 已提交
69 70
	private options: any;

71
	private _onDidChangeWorkspaceRoots: Emitter<URI[]>;
72

73
	constructor(workspace: any = TestWorkspace, options: any = null) {
E
Erich Gamma 已提交
74
		this.workspace = workspace;
75
		this.id = generateUuid();
76
		this.options = options || Object.create(null);
77
		this._onDidChangeWorkspaceRoots = new Emitter<URI[]>();
78 79
	}

80 81
	public get onDidChangeWorkspaceRoots(): Event<URI[]> {
		return this._onDidChangeWorkspaceRoots.event;
82 83 84 85
	}

	public getFolders(): URI[] {
		return this.workspace ? [this.workspace.resource] : [];
E
Erich Gamma 已提交
86 87
	}

B
Benjamin Pasero 已提交
88 89 90 91
	public hasWorkspace(): boolean {
		return !!this.workspace;
	}

92
	public getWorkspace(): ILegacyWorkspace {
E
Erich Gamma 已提交
93 94 95
		return this.workspace;
	}

96
	public getWorkspace2(): IWorkspace2 {
B
Benjamin Pasero 已提交
97
		return this.workspace ? { id: this.id, roots: [this.workspace.resource], name: this.workspace.resource.fsPath } : void 0;
98 99
	}

100 101 102 103
	public getRoot(resource: URI): URI {
		return this.isInsideWorkspace(resource) ? this.workspace.resource : null;
	}

D
Daniel Imms 已提交
104 105 106 107
	public setWorkspace(workspace: any): void {
		this.workspace = workspace;
	}

E
Erich Gamma 已提交
108 109 110 111 112 113 114 115 116 117
	public getOptions() {
		return this.options;
	}

	public updateOptions() {

	}

	public isInsideWorkspace(resource: URI): boolean {
		if (resource && this.workspace) {
118
			return isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath, !isLinux /* ignorecase */);
E
Erich Gamma 已提交
119 120 121 122 123
		}

		return false;
	}

124
	public toWorkspaceRelativePath(resource: URI, toOSPath?: boolean): string {
B
Benjamin Pasero 已提交
125
		return makePosixAbsolute(paths.normalize(resource.fsPath.substr('c:'.length), toOSPath));
E
Erich Gamma 已提交
126 127 128
	}

	public toResource(workspaceRelativePath: string): URI {
129
		return URI.file(paths.join('C:\\', workspaceRelativePath));
E
Erich Gamma 已提交
130 131 132
	}
}

B
Benjamin Pasero 已提交
133 134 135 136 137 138 139 140
function isPosixAbsolute(path: string): boolean {
	return path && path[0] === '/';
}

function makePosixAbsolute(path: string): string {
	return isPosixAbsolute(paths.normalize(path)) ? path : paths.sep + path;
}

141
export class TestTextFileService extends TextFileService {
142 143
	public cleanupBackupsBeforeShutdownCalled: boolean;

144 145
	private promptPath: string;
	private confirmResult: ConfirmResult;
146
	private resolveTextContentError: IFileOperationResult;
A
Alex Dima 已提交
147 148

	constructor(
149 150
		@ILifecycleService lifecycleService: ILifecycleService,
		@IWorkspaceContextService contextService: IWorkspaceContextService,
A
Alex Dima 已提交
151 152
		@IConfigurationService configurationService: IConfigurationService,
		@ITelemetryService telemetryService: ITelemetryService,
153
		@IWorkbenchEditorService editorService: IWorkbenchEditorService,
A
Alex Dima 已提交
154
		@IFileService fileService: IFileService,
155
		@IUntitledEditorService untitledEditorService: IUntitledEditorService,
156
		@IInstantiationService instantiationService: IInstantiationService,
157 158
		@IMessageService messageService: IMessageService,
		@IBackupFileService backupFileService: IBackupFileService,
B
Benjamin Pasero 已提交
159 160
		@IWindowsService windowsService: IWindowsService,
		@IEditorGroupService editorGroupService: IEditorGroupService
A
Alex Dima 已提交
161
	) {
B
Benjamin Pasero 已提交
162
		super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, editorGroupService, windowsService);
A
Alex Dima 已提交
163
	}
164

165 166 167 168 169 170 171 172
	public setPromptPath(path: string): void {
		this.promptPath = path;
	}

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

173 174 175 176
	public setResolveTextContentErrorOnce(error: IFileOperationResult): void {
		this.resolveTextContentError = error;
	}

177
	public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
178 179 180 181
		if (this.resolveTextContentError) {
			const error = this.resolveTextContentError;
			this.resolveTextContentError = null;

182
			return TPromise.wrapError<IRawTextContent>(error);
183 184
		}

185
		return this.fileService.resolveContent(resource, options).then((content) => {
A
Alex Dima 已提交
186
			const textSource = RawTextSource.fromString(content.value);
187
			return <IRawTextContent>{
188
				resource: content.resource,
189 190 191 192
				name: content.name,
				mtime: content.mtime,
				etag: content.etag,
				encoding: content.encoding,
193
				value: textSource,
194
				valueLogicalHash: null
195 196 197
			};
		});
	}
198 199 200 201 202 203 204 205

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

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

207 208 209 210 211 212 213 214
	public onConfigurationChange(configuration: any): void {
		super.onConfigurationChange(configuration);
	}

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

217
export function workbenchInstantiationService(): IInstantiationService {
218
	let instantiationService = new TestInstantiationService(new ServiceCollection([ILifecycleService, new TestLifecycleService()]));
219 220 221 222
	instantiationService.stub(IWorkspaceContextService, new TestContextService(TestWorkspace));
	instantiationService.stub(IConfigurationService, new TestConfigurationService());
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
	instantiationService.stub(IStorageService, new TestStorageService());
223
	instantiationService.stub(IWorkbenchEditorService, new TestEditorService());
224 225
	instantiationService.stub(IPartService, new TestPartService());
	instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
226
	instantiationService.stub(IModeService, ModeServiceImpl);
227
	instantiationService.stub(IHistoryService, {});
228
	instantiationService.stub(IHistoryService, 'getHistory', []);
S
Sandeep Somavarapu 已提交
229
	instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
230
	instantiationService.stub(IFileService, new TestFileService());
231
	instantiationService.stub(IBackupFileService, new TestBackupFileService());
232 233
	instantiationService.stub(ITelemetryService, NullTelemetryService);
	instantiationService.stub(IMessageService, new TestMessageService());
B
Benjamin Pasero 已提交
234
	instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
235
	instantiationService.stub(IWindowsService, new TestWindowsService());
236
	instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(TestTextFileService));
237
	instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
B
Benjamin Pasero 已提交
238
	instantiationService.stub(IEnvironmentService, TestEnvironmentService);
B
Benjamin Pasero 已提交
239
	instantiationService.stub(IThemeService, new TestThemeService());
240 241 242 243

	return instantiationService;
}

E
Erich Gamma 已提交
244
export class TestMessageService implements IMessageService {
245
	public _serviceBrand: any;
E
Erich Gamma 已提交
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

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

272
export class TestPartService implements IPartService {
B
Benjamin Pasero 已提交
273

274
	public _serviceBrand: any;
E
Erich Gamma 已提交
275

276
	private _onTitleBarVisibilityChange = new Emitter<void>();
277
	private _onEditorLayout = new Emitter<void>();
278 279 280 281 282

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

283 284 285 286
	public get onEditorLayout(): Event<void> {
		return this._onEditorLayout.event;
	}

E
Erich Gamma 已提交
287 288 289 290 291 292 293
	public layout(): void { }

	public isCreated(): boolean {
		return true;
	}

	public joinCreation(): Promise {
A
Alex Dima 已提交
294
		return TPromise.as(null);
E
Erich Gamma 已提交
295 296 297 298 299 300 301 302 303 304
	}

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

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

305 306 307 308
	public getContainer(part): HTMLElement {
		return null;
	}

B
Benjamin Pasero 已提交
309 310 311 312
	public isTitleBarHidden(): boolean {
		return false;
	}

313 314 315 316
	public getTitleBarOffset(): number {
		return 0;
	}

317 318 319 320
	public isStatusBarHidden(): boolean {
		return false;
	}

S
Sanders Lauture 已提交
321 322 323 324 325 326
	public isActivityBarHidden(): boolean {
		return false;
	}

	public setActivityBarHidden(hidden: boolean): void { }

E
Erich Gamma 已提交
327 328 329 330
	public isSideBarHidden(): boolean {
		return false;
	}

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

I
isidor 已提交
333
	public isPanelHidden(): boolean {
I
isidor 已提交
334 335 336
		return false;
	}

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

I
isidor 已提交
339 340
	public toggleMaximizedPanel(): void { }

B
Benjamin Pasero 已提交
341 342 343 344
	public isPanelMaximized(): boolean {
		return false;
	}

E
Erich Gamma 已提交
345 346 347 348 349 350
	public getSideBarPosition() {
		return 0;
	}

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

I
isidor 已提交
353
	public toggleZenMode(): void { }
354 355

	public resizePart(part: Parts, sizeChange: number): void { }
E
Erich Gamma 已提交
356 357
}

358
export class TestStorageService extends EventEmitter implements IStorageService {
359
	public _serviceBrand: any;
E
Erich Gamma 已提交
360

B
Benjamin Pasero 已提交
361
	private storage: StorageService;
E
Erich Gamma 已提交
362 363 364 365 366

	constructor() {
		super();

		let context = new TestContextService();
367
		this.storage = new StorageService(new InMemoryLocalStorage(), null, context.getWorkspace());
E
Erich Gamma 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
	}

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

395
export class TestEditorGroupService implements IEditorGroupService {
396
	public _serviceBrand: any;
397 398

	private stacksModel: EditorStacksModel;
399 400 401

	private _onEditorsChanged: Emitter<void>;
	private _onEditorOpenFail: Emitter<IEditorInput>;
402
	private _onEditorsMoved: Emitter<void>;
403
	private _onGroupOrientationChanged: Emitter<void>;
I
isidor 已提交
404
	private _onTabOptionsChanged: Emitter<ITabOptions>;
405 406

	constructor(callback?: (method: string) => void) {
407
		this._onEditorsMoved = new Emitter<void>();
408
		this._onEditorsChanged = new Emitter<void>();
409
		this._onGroupOrientationChanged = new Emitter<void>();
410
		this._onEditorOpenFail = new Emitter<IEditorInput>();
I
isidor 已提交
411
		this._onTabOptionsChanged = new Emitter<ITabOptions>();
412

413 414 415
		let services = new ServiceCollection();

		services.set(IStorageService, new TestStorageService());
416
		services.set(IConfigurationService, new TestConfigurationService());
417
		services.set(IWorkspaceContextService, new TestContextService());
418 419
		const lifecycle = new TestLifecycleService();
		services.set(ILifecycleService, lifecycle);
420
		services.set(ITelemetryService, NullTelemetryService);
421 422 423

		let inst = new InstantiationService(services);

424
		this.stacksModel = inst.createInstance(EditorStacksModel, true);
425 426
	}

427 428 429 430 431 432 433 434 435 436 437 438
	public fireChange(): void {
		this._onEditorsChanged.fire();
	}

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

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

439 440 441 442
	public get onEditorsMoved(): Event<void> {
		return this._onEditorsMoved.event;
	}

443 444 445 446
	public get onGroupOrientationChanged(): Event<void> {
		return this._onGroupOrientationChanged.event;
	}

I
isidor 已提交
447 448
	public get onTabOptionsChanged(): Event<ITabOptions> {
		return this._onTabOptionsChanged.event;
449 450
	}

451 452 453
	public focusGroup(group: IEditorGroup): void;
	public focusGroup(position: Position): void;
	public focusGroup(arg1: any): void {
454 455 456

	}

457 458 459
	public activateGroup(group: IEditorGroup): void;
	public activateGroup(position: Position): void;
	public activateGroup(arg1: any): void {
460 461 462

	}

463 464 465
	public moveGroup(from: IEditorGroup, to: IEditorGroup): void;
	public moveGroup(from: Position, to: Position): void;
	public moveGroup(arg1: any, arg2: any): void {
466 467 468 469 470 471 472

	}

	public arrangeGroups(arrangement: GroupArrangement): void {

	}

473 474 475 476 477 478 479 480
	public setGroupOrientation(orientation: GroupOrientation): void {

	}

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

B
Benjamin Pasero 已提交
481 482
	public resizeGroup(position: Position, groupSizeChange: number): void {

483 484
	}

485 486 487
	public pinEditor(group: IEditorGroup, input: IEditorInput): void;
	public pinEditor(position: Position, input: IEditorInput): void;
	public pinEditor(arg1: any, input: IEditorInput): void {
488 489
	}

490 491 492
	public unpinEditor(group: IEditorGroup, input: IEditorInput): void;
	public unpinEditor(position: Position, input: IEditorInput): void;
	public unpinEditor(arg1: any, input: IEditorInput): void {
493 494
	}

495 496 497
	public moveEditor(input: IEditorInput, from: IEditorGroup, to: IEditorGroup, moveOptions?: IMoveOptions): void;
	public moveEditor(input: IEditorInput, from: Position, to: Position, moveOptions?: IMoveOptions): void;
	public moveEditor(input: IEditorInput, from: any, to: any, moveOptions?: IMoveOptions): void {
498 499 500 501 502
	}

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

I
isidor 已提交
504 505
	public getTabOptions(): ITabOptions {
		return {};
506
	}
507 508
}

509
export class TestEditorService implements IWorkbenchEditorService {
510
	public _serviceBrand: any;
E
Erich Gamma 已提交
511

B
Benjamin Pasero 已提交
512 513 514
	public activeEditorInput: IEditorInput;
	public activeEditorOptions: IEditorOptions;
	public activeEditorPosition: Position;
515
	public mockLineNumber: number;
E
Erich Gamma 已提交
516 517 518 519 520

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

	constructor(callback?: (method: string) => void) {
		this.callback = callback || ((s: string) => { });
521
		this.mockLineNumber = 15;
B
Benjamin Pasero 已提交
522 523
	}

B
Benjamin Pasero 已提交
524
	public openEditors(inputs): Promise {
A
Alex Dima 已提交
525
		return TPromise.as([]);
E
Erich Gamma 已提交
526 527
	}

528 529 530 531
	public replaceEditors(editors): TPromise<IEditor[]> {
		return TPromise.as([]);
	}

B
Benjamin Pasero 已提交
532
	public closeEditors(position: Position, filter?: { except?: IEditorInput, direction?: Direction, unmodifiedOnly?: boolean }): TPromise<void> {
533 534 535
		return TPromise.as(null);
	}

536
	public closeAllEditors(except?: Position): TPromise<void> {
A
Alex Dima 已提交
537
		return TPromise.as(null);
E
Erich Gamma 已提交
538 539 540 541 542 543 544 545 546
	}

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

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

547 548 549 550 551 552 553
		return {
			input: null,
			options: null,
			position: null,
			getId: () => { return null; },
			getControl: () => {
				return {
554
					getSelection: () => { return { positionLineNumber: this.mockLineNumber }; }
555 556 557 558 559
				};
			},
			focus: () => { },
			isVisible: () => { return true; }
		};
E
Erich Gamma 已提交
560 561 562 563 564
	}

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

B
Benjamin Pasero 已提交
565
		return this.activeEditorInput;
E
Erich Gamma 已提交
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
	}

	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 已提交
581
		return TPromise.as(null);
E
Erich Gamma 已提交
582 583
	}

584
	public closeEditor(position: Position, input: IEditorInput): TPromise<void> {
E
Erich Gamma 已提交
585 586 587 588 589
		this.callback('closeEditor');

		return TPromise.as(null);
	}

590 591
	public createInput(input: IResourceInput): IEditorInput {
		return null;
E
Erich Gamma 已提交
592 593 594
	}
}

595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
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 已提交
624
		return TPromise.as({
625 626
			resource,
			etag: Date.now().toString(),
B
Benjamin Pasero 已提交
627
			encoding: 'utf8',
B
Benjamin Pasero 已提交
628
			mtime: Date.now(),
629 630
			isDirectory: false,
			hasChildren: false,
B
Benjamin Pasero 已提交
631 632
			name: paths.basename(resource.fsPath)
		});
633
	}
B
Benjamin Pasero 已提交
634

635 636 637
	existsFile(resource: URI): TPromise<boolean> {
		return TPromise.as(null);
	}
B
Benjamin Pasero 已提交
638

639
	resolveContent(resource: URI, options?: IResolveContentOptions): TPromise<IContent> {
B
Benjamin Pasero 已提交
640 641
		return TPromise.as({
			resource: resource,
642 643
			value: 'Hello Html',
			etag: 'index.txt',
B
Benjamin Pasero 已提交
644 645
			encoding: 'utf8',
			mtime: Date.now(),
646
			name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
647
		});
648
	}
E
Erich Gamma 已提交
649

650
	resolveStreamContent(resource: URI, options?: IResolveContentOptions): TPromise<IStreamContent> {
A
Alex Dima 已提交
651 652 653
		return TPromise.as({
			resource: resource,
			value: {
654
				on: (event: string, callback: Function): void => {
A
Alex Dima 已提交
655 656 657 658 659 660 661 662 663 664
					if (event === 'data') {
						callback('Hello Html');
					}
					if (event === 'end') {
						callback();
					}
				}
			},
			etag: 'index.txt',
			encoding: 'utf8',
B
Benjamin Pasero 已提交
665
			mtime: Date.now(),
666
			name: paths.basename(resource.fsPath)
A
Alex Dima 已提交
667
		});
668 669 670 671 672
	}

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

674
	updateContent(resource: URI, value: string, options?: IUpdateContentOptions): TPromise<IFileStat> {
675
		return TPromise.timeout(1).then(() => {
E
Erich Gamma 已提交
676
			return {
677
				resource,
E
Erich Gamma 已提交
678
				etag: 'index.txt',
B
Benjamin Pasero 已提交
679
				encoding: 'utf8',
B
Benjamin Pasero 已提交
680
				mtime: Date.now(),
681 682 683
				isDirectory: false,
				hasChildren: false,
				name: paths.basename(resource.fsPath)
E
Erich Gamma 已提交
684 685
			};
		});
686
	}
D
Daniel Imms 已提交
687

688 689 690
	moveFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
691

692 693 694
	copyFile(source: URI, target: URI, overwrite?: boolean): TPromise<IFileStat> {
		return TPromise.as(null);
	}
D
Daniel Imms 已提交
695

696 697
	createFile(resource: URI, content?: string): TPromise<IFileStat> {
		return TPromise.as(null);
E
Erich Gamma 已提交
698
	}
699 700 701 702 703 704 705 706

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

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

708 709 710 711 712 713 714 715 716 717 718
	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 已提交
719

720 721 722 723 724 725 726 727 728 729 730 731 732 733
	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 已提交
734

735
	dispose(): void {
E
Erich Gamma 已提交
736
	}
737
}
738

739 740
export class TestBackupFileService implements IBackupFileService {
	public _serviceBrand: any;
741

742 743
	public backupEnabled: boolean;

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

748
	public hasBackup(resource: URI): TPromise<boolean> {
749 750 751
		return TPromise.as(false);
	}

B
Benjamin Pasero 已提交
752 753 754 755 756 757 758 759 760 761
	public loadBackupResource(resource: URI): TPromise<URI> {
		return this.hasBackup(resource).then(hasBackup => {
			if (hasBackup) {
				return this.getBackupResource(resource);
			}

			return void 0;
		});
	}

D
Daniel Imms 已提交
762 763 764 765 766 767 768 769 770 771 772
	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;
	}
773

774
	public backupResource(resource: URI, content: string): TPromise<void> {
775 776 777
		return TPromise.as(void 0);
	}

778
	public getWorkspaceFileBackups(): TPromise<URI[]> {
779 780 781
		return TPromise.as([]);
	}

A
Alex Dima 已提交
782
	public parseBackupContent(rawText: IRawTextSource): string {
783
		return rawText.lines.join('\n');
784 785
	}

786
	public discardResourceBackup(resource: URI): TPromise<void> {
787 788 789
		return TPromise.as(void 0);
	}

790
	public discardAllWorkspaceBackups(): TPromise<void> {
791 792
		return TPromise.as(void 0);
	}
D
Daniel Imms 已提交
793 794
};

795 796 797 798
export class TestWindowService implements IWindowService {

	public _serviceBrand: any;

799 800 801 802
	isFocused(): TPromise<boolean> {
		return TPromise.as(false);
	}

803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 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
	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);
	}
874 875 876 877

	onWindowTitleDoubleClick(): TPromise<void> {
		return TPromise.as(void 0);
	}
878 879
}

880 881
export class TestLifecycleService implements ILifecycleService {

882
	public _serviceBrand: any;
883

884
	public phase: LifecyclePhase;
885
	public startupKind: StartupKind;
886

887
	private _onDidChangePhase = new Emitter<LifecyclePhase>();
888
	private _onWillShutdown = new Emitter<ShutdownEvent>();
889
	private _onShutdown = new Emitter<ShutdownReason>();
890 891


892 893
	public fireShutdown(reason = ShutdownReason.QUIT): void {
		this._onShutdown.fire(reason);
894 895
	}

896 897 898 899
	public fireWillShutdown(event: ShutdownEvent): void {
		this._onWillShutdown.fire(event);
	}

900 901 902 903
	public get onDidChangePhase(): Event<LifecyclePhase> {
		return this._onDidChangePhase.event;
	}

904 905 906 907
	public get onWillShutdown(): Event<ShutdownEvent> {
		return this._onWillShutdown.event;
	}

908
	public get onShutdown(): Event<ShutdownReason> {
909 910
		return this._onShutdown.event;
	}
911 912
}

913 914 915 916
export class TestWindowsService implements IWindowsService {

	_serviceBrand: any;

917 918
	public windowCount = 1;

919 920 921
	onWindowOpen: Event<number>;
	onWindowFocus: Event<number>;

922 923 924 925
	isFocused(windowId: number): TPromise<boolean> {
		return TPromise.as(false);
	}

926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
	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);
	}
C
22768  
Cristian 已提交
960 961 962
	clearRecentPathsList(): TPromise<void> {
		return TPromise.as(void 0);
	}
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
	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);
	}
978 979 980
	onWindowTitleDoubleClick(windowId: number): TPromise<void> {
		return TPromise.as(void 0);
	}
981 982 983 984 985 986
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
		return TPromise.as(void 0);
	}
	quit(): TPromise<void> {
		return TPromise.as(void 0);
	}
J
Johannes Rieken 已提交
987 988 989
	relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void> {
		return TPromise.as(void 0);
	}
990 991 992
	whenSharedProcessReady(): TPromise<void> {
		return TPromise.as(void 0);
	}
993 994 995
	toggleSharedProcess(): TPromise<void> {
		return TPromise.as(void 0);
	}
996
	// Global methods
997
	openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean }): TPromise<void> {
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
		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> {
1010
		return TPromise.as(this.windowCount);
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
	}
	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
1025 1026
	openExternal(url: string): TPromise<boolean> {
		return TPromise.as(true);
1027 1028 1029 1030 1031 1032
	}

	// TODO: this is a bit backwards
	startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void> {
		return TPromise.as(void 0);
	}
1033
}
B
Benjamin Pasero 已提交
1034

B
Benjamin Pasero 已提交
1035
export class TestTheme implements ITheme {
1036 1037 1038

	constructor(private colors: { [id: string]: string; } = {}, public type = DARK) {
	}
B
Benjamin Pasero 已提交
1039 1040

	getColor(color: string, useDefault?: boolean): Color {
1041 1042 1043 1044 1045
		let value = this.colors[color];
		if (value) {
			return Color.fromHex(value);
		}
		return void 0;
B
Benjamin Pasero 已提交
1046 1047
	}

1048
	defines(color: string): boolean {
B
Benjamin Pasero 已提交
1049 1050 1051 1052
		throw new Error('Method not implemented.');
	}
}

B
Benjamin Pasero 已提交
1053 1054 1055
export class TestThemeService implements IThemeService {

	_serviceBrand: any;
1056 1057 1058 1059 1060 1061
	_theme: ITheme;
	_onThemeChange = new Emitter<ITheme>();

	constructor(theme = new TestTheme()) {
		this._theme = theme;
	}
B
Benjamin Pasero 已提交
1062 1063

	getTheme(): ITheme {
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
		return this._theme;
	}

	setTheme(theme: ITheme) {
		this._theme = theme;
		this.fireThemeChange();
	}

	fireThemeChange() {
		this._onThemeChange.fire(this._theme);
B
Benjamin Pasero 已提交
1074 1075
	}

1076 1077
	public get onThemeChange(): Event<ITheme> {
		return this._onThemeChange.event;
B
Benjamin Pasero 已提交
1078
	}
1079
}