editorService.test.ts 25.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import * as assert from 'assert';
import { TPromise } from 'vs/base/common/winjs.base';
import * as paths from 'vs/base/common/paths';
11
import { IEditorModel } from 'vs/platform/editor/common/editor';
12 13
import URI from 'vs/base/common/uri';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
14
import { EditorInput, EditorOptions, IFileEditorInput, IEditorInput } from 'vs/workbench/common/editor';
15 16 17
import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
B
Benjamin Pasero 已提交
18
import { EditorService, DelegatingEditorService } from 'vs/workbench/services/editor/browser/editorService';
19
import { IEditorGroup, IEditorGroupsService, GroupDirection } from 'vs/workbench/services/group/common/editorGroupsService';
20
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
21 22
import { Dimension } from 'vs/base/browser/dom';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
23
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
24 25 26 27 28
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { Registry } from 'vs/platform/registry/common/platform';
B
Benjamin Pasero 已提交
29 30 31
import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
B
Benjamin Pasero 已提交
32
import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
33 34 35

export class TestEditorControl extends BaseEditor {

36
	constructor(@ITelemetryService telemetryService: ITelemetryService) { super('MyTestEditorForEditorService', NullTelemetryService, new TestThemeService()); }
37

B
Benjamin Pasero 已提交
38
	getId(): string { return 'MyTestEditorForEditorService'; }
39 40 41 42 43
	layout(): void { }
	createEditor(): any { }
}

export class TestEditorInput extends EditorInput implements IFileEditorInput {
B
Benjamin Pasero 已提交
44
	public gotDisposed: boolean;
45 46
	constructor(private resource: URI) { super(); }

47
	getTypeId() { return 'testEditorInputForEditorService'; }
48
	resolve(): TPromise<IEditorModel> { return null; }
B
Benjamin Pasero 已提交
49
	matches(other: TestEditorInput): boolean { return other && other.resource && this.resource.toString() === other.resource.toString() && other instanceof TestEditorInput; }
50 51 52 53 54
	setEncoding(encoding: string) { }
	getEncoding(): string { return null; }
	setPreferredEncoding(encoding: string) { }
	getResource(): URI { return this.resource; }
	setForceOpenAsBinary(): void { }
B
Benjamin Pasero 已提交
55 56 57 58
	dispose(): void {
		super.dispose();
		this.gotDisposed = true;
	}
59 60
}

61
suite('Editor service', () => {
62

B
Benjamin Pasero 已提交
63
	function registerTestEditorInput(): void {
64
		Registry.as<IEditorRegistry>(Extensions.Editors).registerEditor(new EditorDescriptor(TestEditorControl, 'MyTestEditorForEditorService', 'My Test Editor For Next Editor Service'), new SyncDescriptor(TestEditorInput));
B
Benjamin Pasero 已提交
65 66 67 68
	}

	registerTestEditorInput();

69 70 71
	test('basics', function () {
		const partInstantiator = workbenchInstantiationService();

72
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
73 74 75
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

76
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
77

B
Benjamin Pasero 已提交
78
		const service: EditorServiceImpl = testInstantiationService.createInstance(EditorService);
79 80

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));
B
Benjamin Pasero 已提交
81
		const otherInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

		let activeEditorChangeEventCounter = 0;
		const activeEditorChangeListener = service.onDidActiveEditorChange(() => {
			activeEditorChangeEventCounter++;
		});

		let visibleEditorChangeEventCounter = 0;
		const visibleEditorChangeListener = service.onDidVisibleEditorsChange(() => {
			visibleEditorChangeEventCounter++;
		});

		let didCloseEditorListenerCounter = 0;
		const didCloseEditorListener = service.onDidCloseEditor(editor => {
			didCloseEditorListenerCounter++;
		});

B
Benjamin Pasero 已提交
98
		// Open input
B
Benjamin Pasero 已提交
99
		return service.openEditor(input, { pinned: true }).then(editor => {
100 101 102 103 104
			assert.ok(editor instanceof TestEditorControl);
			assert.equal(editor, service.activeControl);
			assert.equal(input, service.activeEditor);
			assert.equal(service.visibleControls.length, 1);
			assert.equal(service.visibleControls[0], editor);
105 106
			assert.ok(!service.activeTextEditorWidget);
			assert.equal(service.visibleTextEditorWidgets.length, 0);
107
			assert.equal(service.isOpen(input), true);
B
Benjamin Pasero 已提交
108
			assert.equal(service.isOpen(input, part.activeGroup), true);
109 110 111
			assert.equal(activeEditorChangeEventCounter, 1);
			assert.equal(visibleEditorChangeEventCounter, 1);

B
Benjamin Pasero 已提交
112
			// Close input
113
			editor.group.closeEditor(input);
114
			assert.equal(didCloseEditorListenerCounter, 1);
B
Benjamin Pasero 已提交
115 116
			assert.equal(activeEditorChangeEventCounter, 2);
			assert.equal(visibleEditorChangeEventCounter, 2);
B
Benjamin Pasero 已提交
117
			assert.ok(input.gotDisposed);
B
Benjamin Pasero 已提交
118

B
Benjamin Pasero 已提交
119
			// Open again 2 inputs
B
Benjamin Pasero 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133
			return service.openEditor(input, { pinned: true }).then(editor => {
				return service.openEditor(otherInput, { pinned: true }).then(editor => {
					assert.equal(service.visibleControls.length, 1);
					assert.equal(service.isOpen(input), true);
					assert.equal(service.isOpen(otherInput), true);

					assert.equal(activeEditorChangeEventCounter, 4);
					assert.equal(visibleEditorChangeEventCounter, 4);

					activeEditorChangeListener.dispose();
					visibleEditorChangeListener.dispose();
					didCloseEditorListener.dispose();
				});
			});
134 135 136
		});
	});

137 138 139
	test('openEditors() / replaceEditors()', function () {
		const partInstantiator = workbenchInstantiationService();

140
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
141 142 143
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

144
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
145

146
		const service: IEditorService = testInstantiationService.createInstance(EditorService);
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));
		const otherInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));
		const replaceInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource3'));

		// Open editors
		return service.openEditors([{ editor: input }, { editor: otherInput }]).then(() => {
			assert.equal(part.activeGroup.count, 2);

			return service.replaceEditors([{ editor: input, replacement: replaceInput }], part.activeGroup).then(() => {
				assert.equal(part.activeGroup.count, 2);
				assert.equal(part.activeGroup.getIndexOfEditor(replaceInput), 0);
			});
		});
	});

163 164
	test('caching', function () {
		const instantiationService = workbenchInstantiationService();
165
		const service: EditorService = <any>instantiationService.createInstance(EditorService);
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

		// Cached Input (Files)
		const fileResource1 = toFileResource(this, '/foo/bar/cache1.js');
		const fileInput1 = service.createInput({ resource: fileResource1 });
		assert.ok(fileInput1);

		const fileResource2 = toFileResource(this, '/foo/bar/cache2.js');
		const fileInput2 = service.createInput({ resource: fileResource2 });
		assert.ok(fileInput2);

		assert.notEqual(fileInput1, fileInput2);

		const fileInput1Again = service.createInput({ resource: fileResource1 });
		assert.equal(fileInput1Again, fileInput1);

		fileInput1Again.dispose();

		assert.ok(fileInput1.isDisposed());

		const fileInput1AgainAndAgain = service.createInput({ resource: fileResource1 });
		assert.notEqual(fileInput1AgainAndAgain, fileInput1);
		assert.ok(!fileInput1AgainAndAgain.isDisposed());

		// Cached Input (Resource)
		const resource1 = toResource.call(this, '/foo/bar/cache1.js');
		const input1 = service.createInput({ resource: resource1 });
		assert.ok(input1);

		const resource2 = toResource.call(this, '/foo/bar/cache2.js');
		const input2 = service.createInput({ resource: resource2 });
		assert.ok(input2);

		assert.notEqual(input1, input2);

		const input1Again = service.createInput({ resource: resource1 });
		assert.equal(input1Again, input1);

		input1Again.dispose();

		assert.ok(input1.isDisposed());

		const input1AgainAndAgain = service.createInput({ resource: resource1 });
		assert.notEqual(input1AgainAndAgain, input1);
		assert.ok(!input1AgainAndAgain.isDisposed());
	});

B
Benjamin Pasero 已提交
212 213
	test('createInput', function () {
		const instantiationService = workbenchInstantiationService();
214
		const service: EditorService = <any>instantiationService.createInstance(EditorService);
B
Benjamin Pasero 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

		// Untyped Input (file)
		let input = service.createInput({ resource: toFileResource(this, '/index.html'), options: { selection: { startLineNumber: 1, startColumn: 1 } } });
		assert(input instanceof FileEditorInput);
		let contentInput = <FileEditorInput>input;
		assert.strictEqual(contentInput.getResource().fsPath, toFileResource(this, '/index.html').fsPath);

		// Untyped Input (file, encoding)
		input = service.createInput({ resource: toFileResource(this, '/index.html'), encoding: 'utf16le', options: { selection: { startLineNumber: 1, startColumn: 1 } } });
		assert(input instanceof FileEditorInput);
		contentInput = <FileEditorInput>input;
		assert.equal(contentInput.getPreferredEncoding(), 'utf16le');

		// Untyped Input (untitled)
		input = service.createInput({ options: { selection: { startLineNumber: 1, startColumn: 1 } } });
		assert(input instanceof UntitledEditorInput);

		// Untyped Input (untitled with contents)
		input = service.createInput({ contents: 'Hello Untitled', options: { selection: { startLineNumber: 1, startColumn: 1 } } });
		assert(input instanceof UntitledEditorInput);

		// Untyped Input (untitled with file path)
		input = service.createInput({ filePath: '/some/path.txt', options: { selection: { startLineNumber: 1, startColumn: 1 } } });
		assert(input instanceof UntitledEditorInput);
		assert.ok((input as UntitledEditorInput).hasAssociatedFilePath);
	});

242 243 244 245 246 247 248 249 250 251 252 253 254
	test('delegate', function (done) {
		const instantiationService = workbenchInstantiationService();

		class MyEditor extends BaseEditor {

			constructor(id: string) {
				super(id, null, new TestThemeService());
			}

			getId(): string {
				return 'myEditor';
			}

B
Benjamin Pasero 已提交
255
			layout(): void { }
256

B
Benjamin Pasero 已提交
257
			createEditor(): any { }
258 259 260 261 262
		}

		const ed = instantiationService.createInstance(MyEditor, 'my.editor');

		const inp = instantiationService.createInstance(ResourceEditorInput, 'name', 'description', URI.parse('my://resource'));
B
Benjamin Pasero 已提交
263
		const delegate = instantiationService.createInstance(DelegatingEditorService);
264
		delegate.setEditorOpenHandler((group: IEditorGroup, input: IEditorInput, options?: EditorOptions) => {
265 266 267 268 269 270 271 272 273
			assert.strictEqual(input, inp);

			done();

			return TPromise.as(ed);
		});

		delegate.openEditor(inp);
	});
B
Benjamin Pasero 已提交
274 275 276 277

	test('close editor does not dispose when editor opened in other group', function () {
		const partInstantiator = workbenchInstantiationService();

278
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
B
Benjamin Pasero 已提交
279 280 281
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

282
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
B
Benjamin Pasero 已提交
283

284
		const service: IEditorService = testInstantiationService.createInstance(EditorService);
B
Benjamin Pasero 已提交
285 286 287 288 289 290 291 292 293

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));

		const rootGroup = part.activeGroup;
		const rightGroup = part.addGroup(rootGroup, GroupDirection.RIGHT);

		// Open input
		return service.openEditor(input, { pinned: true }).then(editor => {
			return service.openEditor(input, { pinned: true }, rightGroup).then(editor => {
294 295 296 297
				const editors = service.editors;
				assert.equal(editors.length, 2);
				assert.equal(editors[0], input);
				assert.equal(editors[1], input);
B
Benjamin Pasero 已提交
298 299

				// Close input
300
				return rootGroup.closeEditor(input).then(() => {
B
Benjamin Pasero 已提交
301 302
					assert.equal(input.isDisposed(), false);

303
					return rightGroup.closeEditor(input).then(() => {
B
Benjamin Pasero 已提交
304 305 306 307 308 309 310 311 312 313
						assert.equal(input.isDisposed(), true);
					});
				});
			});
		});
	});

	test('close editor does not dispose when editor opened in other group (diff input)', function () {
		const partInstantiator = workbenchInstantiationService();

314
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
B
Benjamin Pasero 已提交
315 316 317
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

318
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
B
Benjamin Pasero 已提交
319

320
		const service: IEditorService = testInstantiationService.createInstance(EditorService);
B
Benjamin Pasero 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));
		const otherInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));
		const diffInput = new DiffEditorInput('name', 'description', input, otherInput);

		const rootGroup = part.activeGroup;
		const rightGroup = part.addGroup(rootGroup, GroupDirection.RIGHT);

		// Open input
		return service.openEditor(diffInput, { pinned: true }).then(editor => {
			return service.openEditor(diffInput, { pinned: true }, rightGroup).then(editor => {

				// Close input
334
				return rootGroup.closeEditor(diffInput).then(() => {
B
Benjamin Pasero 已提交
335 336 337 338
					assert.equal(diffInput.isDisposed(), false);
					assert.equal(input.isDisposed(), false);
					assert.equal(otherInput.isDisposed(), false);

339
					return rightGroup.closeEditor(diffInput).then(() => {
B
Benjamin Pasero 已提交
340 341 342 343 344 345 346 347 348 349 350 351
						assert.equal(diffInput.isDisposed(), true);
						assert.equal(input.isDisposed(), true);
						assert.equal(otherInput.isDisposed(), true);
					});
				});
			});
		});
	});

	test('close editor disposes properly (diff input)', function () {
		const partInstantiator = workbenchInstantiationService();

352
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
B
Benjamin Pasero 已提交
353 354 355
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

356
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
B
Benjamin Pasero 已提交
357

358
		const service: IEditorService = testInstantiationService.createInstance(EditorService);
B
Benjamin Pasero 已提交
359 360 361 362 363 364 365 366 367

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));
		const otherInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));
		const diffInput = new DiffEditorInput('name', 'description', input, otherInput);

		// Open input
		return service.openEditor(diffInput, { pinned: true }).then(editor => {

			// Close input
368
			return editor.group.closeEditor(diffInput).then(() => {
B
Benjamin Pasero 已提交
369 370 371 372 373 374 375 376 377 378
				assert.equal(diffInput.isDisposed(), true);
				assert.equal(otherInput.isDisposed(), true);
				assert.equal(input.isDisposed(), true);
			});
		});
	});

	test('close editor disposes properly (diff input, left side still opened)', function () {
		const partInstantiator = workbenchInstantiationService();

379
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
B
Benjamin Pasero 已提交
380 381 382
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

383
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
B
Benjamin Pasero 已提交
384

385
		const service: IEditorService = testInstantiationService.createInstance(EditorService);
B
Benjamin Pasero 已提交
386 387 388 389 390 391 392 393 394 395

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));
		const otherInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));
		const diffInput = new DiffEditorInput('name', 'description', input, otherInput);

		// Open input
		return service.openEditor(diffInput, { pinned: true }).then(editor => {
			return service.openEditor(input, { pinned: true }).then(editor => {

				// Close input
396
				return editor.group.closeEditor(diffInput).then(() => {
B
Benjamin Pasero 已提交
397 398 399 400 401 402 403
					assert.equal(diffInput.isDisposed(), true);
					assert.equal(otherInput.isDisposed(), true);
					assert.equal(input.isDisposed(), false);
				});
			});
		});
	});
404 405 406 407

	test('open to the side', function () {
		const partInstantiator = workbenchInstantiationService();

408
		const part = partInstantiator.createInstance(EditorPart, 'id', false);
409 410 411
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

412
		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));
413

414
		const service: IEditorService = testInstantiationService.createInstance(EditorService);
415 416 417 418 419 420 421 422 423 424

		const input1 = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource1'));
		const input2 = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));

		const rootGroup = part.activeGroup;

		return service.openEditor(input1, { pinned: true }, rootGroup).then(editor => {
			return service.openEditor(input1, { pinned: true, preserveFocus: true }, SIDE_GROUP).then(editor => {
				assert.equal(part.activeGroup, rootGroup);
				assert.equal(part.count, 2);
425
				assert.equal(editor.group, part.groups[1]);
426 427 428 429 430

				// Open to the side uses existing neighbour group if any
				return service.openEditor(input2, { pinned: true, preserveFocus: true }, SIDE_GROUP).then(editor => {
					assert.equal(part.activeGroup, rootGroup);
					assert.equal(part.count, 2);
431
					assert.equal(editor.group, part.groups[1]);
432 433 434 435
				});
			});
		});
	});
B
Benjamin Pasero 已提交
436

437
	test('active editor change / visible editor change events', async function () {
B
Benjamin Pasero 已提交
438 439 440 441 442 443 444 445
		const partInstantiator = workbenchInstantiationService();

		const part = partInstantiator.createInstance(EditorPart, 'id', false);
		part.create(document.createElement('div'));
		part.layout(new Dimension(400, 300));

		const testInstantiationService = partInstantiator.createChild(new ServiceCollection([IEditorGroupsService, part]));

B
Benjamin Pasero 已提交
446
		const service: EditorServiceImpl = testInstantiationService.createInstance(EditorService);
B
Benjamin Pasero 已提交
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491

		const input = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource'));
		const otherInput = testInstantiationService.createInstance(TestEditorInput, URI.parse('my://resource2'));

		let activeEditorChangeEventFired = false;
		const activeEditorChangeListener = service.onDidActiveEditorChange(() => {
			activeEditorChangeEventFired = true;
		});

		let visibleEditorChangeEventFired = false;
		const visibleEditorChangeListener = service.onDidVisibleEditorsChange(() => {
			visibleEditorChangeEventFired = true;
		});

		function assertActiveEditorChangedEvent(expected: boolean) {
			assert.equal(activeEditorChangeEventFired, expected, `Unexpected active editor change state (got ${activeEditorChangeEventFired}, expected ${expected})`);
			activeEditorChangeEventFired = false;
		}

		function assertVisibleEditorsChangedEvent(expected: boolean) {
			assert.equal(visibleEditorChangeEventFired, expected, `Unexpected visible editors change state (got ${visibleEditorChangeEventFired}, expected ${expected})`);
			visibleEditorChangeEventFired = false;
		}

		// 1.) open, open same, open other, close
		let editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor = await service.openEditor(input);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		editor = await service.openEditor(otherInput);
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		await editor.group.closeEditor(otherInput);
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		await editor.group.closeEditor(input);
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

492
		// 2.) open, open same (forced open)
B
Benjamin Pasero 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
		editor = await service.openEditor(input);
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor = await service.openEditor(input, { forceOpen: true });
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		await editor.group.closeEditor(input);

		// 3.) open, open inactive, close
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor = await service.openEditor(otherInput, { inactive: true });
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		editor.group.closeAllEditors();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		// 4.) open, open inactive, close inactive
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor = await service.openEditor(otherInput, { inactive: true });
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		editor.group.closeEditor(otherInput);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		editor.group.closeAllEditors();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		// 5.) add group, remove group
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		let rightGroup = part.addGroup(part.activeGroup, GroupDirection.RIGHT);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		rightGroup.focus();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(false);

		part.removeGroup(rightGroup);
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(false);

		editor.group.closeAllEditors();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		// 6.) open editor in inactive group
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		rightGroup = part.addGroup(part.activeGroup, GroupDirection.RIGHT);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		rightGroup.openEditor(otherInput);
564
		assertActiveEditorChangedEvent(true);
B
Benjamin Pasero 已提交
565 566 567
		assertVisibleEditorsChangedEvent(true);

		rightGroup.closeEditor(otherInput);
568
		assertActiveEditorChangedEvent(true);
B
Benjamin Pasero 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
		assertVisibleEditorsChangedEvent(true);

		editor.group.closeAllEditors();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		// 7.) activate group
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		rightGroup = part.addGroup(part.activeGroup, GroupDirection.RIGHT);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		rightGroup.openEditor(otherInput);
585
		assertActiveEditorChangedEvent(true);
B
Benjamin Pasero 已提交
586 587
		assertVisibleEditorsChangedEvent(true);

588
		editor.group.focus();
B
Benjamin Pasero 已提交
589 590 591 592
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(false);

		rightGroup.closeEditor(otherInput);
593
		assertActiveEditorChangedEvent(false);
B
Benjamin Pasero 已提交
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
		assertVisibleEditorsChangedEvent(true);

		editor.group.closeAllEditors();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		// 8.) move editor
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor = await service.openEditor(otherInput, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor.group.moveEditor(otherInput, editor.group, { index: 0 });
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		editor.group.closeAllEditors();
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
		// 9.) close editor in inactive group
		editor = await service.openEditor(input, { pinned: true });
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		rightGroup = part.addGroup(part.activeGroup, GroupDirection.RIGHT);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(false);

		rightGroup.openEditor(otherInput);
		assertActiveEditorChangedEvent(true);
		assertVisibleEditorsChangedEvent(true);

		editor.group.closeEditor(input);
		assertActiveEditorChangedEvent(false);
		assertVisibleEditorsChangedEvent(true);

B
Benjamin Pasero 已提交
634 635 636 637
		// cleanup
		activeEditorChangeListener.dispose();
		visibleEditorChangeListener.dispose();
	});
638 639 640 641 642 643 644 645 646
});

function toResource(path: string) {
	return URI.from({ scheme: 'custom', path });
}

function toFileResource(self: any, path: string) {
	return URI.file(paths.join('C:\\', Buffer.from(self.test.fullTitle()).toString('base64'), path));
}