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

import * as assert from 'assert';
import { assign } from 'vs/base/common/objects';
import { generateUuid } from 'vs/base/common/uuid';
9 10 11
import { IExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/common/extensions';
import * as ExtensionsActions from 'vs/workbench/contrib/extensions/electron-browser/extensionsActions';
import { ExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/node/extensionsWorkbenchService';
12
import {
13 14
	IExtensionManagementService, IExtensionGalleryService, IExtensionEnablementService, IExtensionTipsService, ILocalExtension, IGalleryExtension,
	DidInstallExtensionEvent, DidUninstallExtensionEvent, InstallExtensionEvent, IExtensionIdentifier, EnablementState, InstallOperation, IExtensionManagementServerService, IExtensionManagementServer
15
} from 'vs/platform/extensionManagement/common/extensionManagement';
16
import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
17
import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService';
18
import { ExtensionTipsService } from 'vs/workbench/contrib/extensions/electron-browser/extensionTipsService';
19
import { TestExtensionEnablementService } from 'vs/platform/extensionManagement/test/electron-browser/extensionEnablementService.test';
20 21
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService';
import { IURLService } from 'vs/platform/url/common/url';
22
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
23 24
import { Emitter } from 'vs/base/common/event';
import { IPager } from 'vs/base/common/paging';
25 26
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
S
#66931  
Sandeep Somavarapu 已提交
27
import { IExtensionService, IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
28
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
29
import { TestContextService, TestWindowService, TestSharedProcessService } from 'vs/workbench/test/workbenchTestServices';
S
Sandeep Somavarapu 已提交
30
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
B
Benjamin Pasero 已提交
31 32
import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { IWindowService } from 'vs/platform/windows/common/windows';
33
import { URLService } from 'vs/platform/url/common/urlService';
34
import { URI } from 'vs/base/common/uri';
J
Johannes Rieken 已提交
35
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
36 37 38
import { ExtensionManagementServerService } from 'vs/workbench/services/extensions/node/extensionManagementServerService';
import { IRemoteAgentService } from 'vs/workbench/services/remote/node/remoteAgentService';
import { RemoteAgentService } from 'vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl';
39
import { ExtensionIdentifier, IExtensionContributions, ExtensionType } from 'vs/platform/extensions/common/extensions';
40
import { ISharedProcessService } from 'vs/platform/sharedProcess/node/sharedProcessService';
41

S
Sandeep Somavarapu 已提交
42
suite('ExtensionsActions Test', () => {
43 44 45

	let instantiationService: TestInstantiationService;

S
Sandeep Somavarapu 已提交
46 47
	let installEvent: Emitter<InstallExtensionEvent>,
		didInstallEvent: Emitter<DidInstallExtensionEvent>,
S
Sandeep Somavarapu 已提交
48
		uninstallEvent: Emitter<IExtensionIdentifier>,
S
Sandeep Somavarapu 已提交
49 50 51 52
		didUninstallEvent: Emitter<DidUninstallExtensionEvent>;


	suiteSetup(() => {
53 54
		installEvent = new Emitter<InstallExtensionEvent>();
		didInstallEvent = new Emitter<DidInstallExtensionEvent>();
S
Sandeep Somavarapu 已提交
55
		uninstallEvent = new Emitter<IExtensionIdentifier>();
56
		didUninstallEvent = new Emitter<DidUninstallExtensionEvent>();
57 58 59

		instantiationService = new TestInstantiationService();
		instantiationService.stub(ITelemetryService, NullTelemetryService);
B
Benjamin Pasero 已提交
60 61
		instantiationService.stub(ILogService, NullLogService);
		instantiationService.stub(IWindowService, TestWindowService);
62

63
		instantiationService.stub(IWorkspaceContextService, new TestContextService());
J
Johannes Rieken 已提交
64
		instantiationService.stub(IConfigurationService, new TestConfigurationService());
B
Benjamin Pasero 已提交
65

66
		instantiationService.stub(IExtensionGalleryService, ExtensionGalleryService);
67
		instantiationService.stub(ISharedProcessService, TestSharedProcessService);
68

69 70 71 72 73
		instantiationService.stub(IExtensionManagementService, ExtensionManagementService);
		instantiationService.stub(IExtensionManagementService, 'onInstallExtension', installEvent.event);
		instantiationService.stub(IExtensionManagementService, 'onDidInstallExtension', didInstallEvent.event);
		instantiationService.stub(IExtensionManagementService, 'onUninstallExtension', uninstallEvent.event);
		instantiationService.stub(IExtensionManagementService, 'onDidUninstallExtension', didUninstallEvent.event);
74
		instantiationService.stub(IRemoteAgentService, RemoteAgentService);
75

76
		instantiationService.stub(IExtensionManagementServerService, instantiationService.createInstance(ExtensionManagementServerService, <IExtensionManagementServer>{ authority: 'vscode-local', extensionManagementService: instantiationService.get(IExtensionManagementService), label: 'local' }));
77

78
		instantiationService.stub(IExtensionEnablementService, new TestExtensionEnablementService(instantiationService));
79

S
Sandeep Somavarapu 已提交
80
		instantiationService.set(IExtensionTipsService, instantiationService.createInstance(ExtensionTipsService));
81
		instantiationService.stub(IURLService, URLService);
S
Sandeep Somavarapu 已提交
82 83
	});

S
Sandeep Somavarapu 已提交
84
	setup(async () => {
S
Sandeep Somavarapu 已提交
85
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', []);
J
Joao Moreno 已提交
86
		instantiationService.stubPromise(IExtensionManagementService, 'getExtensionsReport', []);
S
Sandeep Somavarapu 已提交
87
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage());
M
Matt Bierner 已提交
88
		instantiationService.stub(IExtensionService, <Partial<IExtensionService>>{ getExtensions: () => Promise.resolve([]), onDidChangeExtensions: new Emitter<void>().event, canAddExtension: (extension: IExtensionDescription) => false, canRemoveExtension: (extension: IExtensionDescription) => false });
S
Sandeep Somavarapu 已提交
89
		await (<TestExtensionEnablementService>instantiationService.get(IExtensionEnablementService)).reset();
S
Sandeep Somavarapu 已提交
90 91

		instantiationService.set(IExtensionsWorkbenchService, instantiationService.createInstance(ExtensionsWorkbenchService));
92 93 94 95 96 97 98
	});

	teardown(() => {
		(<ExtensionsWorkbenchService>instantiationService.get(IExtensionsWorkbenchService)).dispose();
	});

	test('Install action is disabled when there is no extension', () => {
S
Sandeep Somavarapu 已提交
99
		const testObject: ExtensionsActions.InstallAction = instantiationService.createInstance(ExtensionsActions.InstallAction);
100 101 102 103

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
104
	test('Test Install action when state is installed', () => {
105
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
S
Sandeep Somavarapu 已提交
106
		const testObject: ExtensionsActions.InstallAction = instantiationService.createInstance(ExtensionsActions.InstallAction);
S
Sandeep Somavarapu 已提交
107
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
108 109
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
S
Sandeep Somavarapu 已提交
110 111 112 113 114 115 116 117 118 119
		return workbenchService.queryLocal()
			.then(() => {
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', { identifier: local.identifier })));
				return workbenchService.queryGallery()
					.then((paged) => {
						testObject.extension = paged.firstPage[0];
						assert.ok(!testObject.enabled);
						assert.equal('Install', testObject.label);
						assert.equal('extension-action prominent install', testObject.class);
					});
120 121 122
			});
	});

S
Sandeep Somavarapu 已提交
123
	test('Test Install action when state is installing', () => {
124
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
S
Sandeep Somavarapu 已提交
125
		const testObject: ExtensionsActions.InstallAction = instantiationService.createInstance(ExtensionsActions.InstallAction);
S
Sandeep Somavarapu 已提交
126
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
127 128
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
129 130 131 132 133 134 135 136 137
		return workbenchService.queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
				installEvent.fire({ identifier: gallery.identifier, gallery });

				assert.ok(!testObject.enabled);
				assert.equal('Installing', testObject.label);
				assert.equal('extension-action install installing', testObject.class);
			});
138 139
	});

S
Sandeep Somavarapu 已提交
140
	test('Test Install action when state is uninstalled', () => {
141
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
S
Sandeep Somavarapu 已提交
142
		const testObject: ExtensionsActions.InstallAction = instantiationService.createInstance(ExtensionsActions.InstallAction);
S
Sandeep Somavarapu 已提交
143
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
144 145
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
146 147 148 149 150 151
		return workbenchService.queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
				assert.ok(testObject.enabled);
				assert.equal('Install', testObject.label);
			});
152 153
	});

S
Sandeep Somavarapu 已提交
154
	test('Test Install action when extension is system action', () => {
S
Sandeep Somavarapu 已提交
155
		const testObject: ExtensionsActions.InstallAction = instantiationService.createInstance(ExtensionsActions.InstallAction);
S
Sandeep Somavarapu 已提交
156
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
157
		const local = aLocalExtension('a', {}, { type: ExtensionType.System });
158 159
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
160 161 162 163 164 165 166
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				uninstallEvent.fire(local.identifier);
				didUninstallEvent.fire({ identifier: local.identifier });
				testObject.extension = extensions[0];
				assert.ok(!testObject.enabled);
			});
167 168
	});

S
Sandeep Somavarapu 已提交
169
	test('Test Install action when extension doesnot has gallery', () => {
S
Sandeep Somavarapu 已提交
170
		const testObject: ExtensionsActions.InstallAction = instantiationService.createInstance(ExtensionsActions.InstallAction);
S
Sandeep Somavarapu 已提交
171
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
172 173 174
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
175 176 177 178 179 180 181
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				uninstallEvent.fire(local.identifier);
				didUninstallEvent.fire({ identifier: local.identifier });
				testObject.extension = extensions[0];
				assert.ok(!testObject.enabled);
			});
182 183 184 185
	});

	test('Uninstall action is disabled when there is no extension', () => {
		const testObject: ExtensionsActions.UninstallAction = instantiationService.createInstance(ExtensionsActions.UninstallAction);
S
Sandeep Somavarapu 已提交
186
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
187 188 189 190

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
191
	test('Test Uninstall action when state is uninstalling', () => {
192
		const testObject: ExtensionsActions.UninstallAction = instantiationService.createInstance(ExtensionsActions.UninstallAction);
S
Sandeep Somavarapu 已提交
193
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
194 195 196
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
197 198 199 200 201 202
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				uninstallEvent.fire(local.identifier);
				assert.ok(!testObject.enabled);
				assert.equal('Uninstalling', testObject.label);
S
Sandeep Somavarapu 已提交
203
				assert.equal('extension-action uninstall uninstalling', testObject.class);
S
Sandeep Somavarapu 已提交
204
			});
205 206
	});

S
Sandeep Somavarapu 已提交
207
	test('Test Uninstall action when state is installed and is user extension', () => {
208
		const testObject: ExtensionsActions.UninstallAction = instantiationService.createInstance(ExtensionsActions.UninstallAction);
S
Sandeep Somavarapu 已提交
209
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
210 211 212
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
213 214 215 216 217
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				assert.ok(testObject.enabled);
				assert.equal('Uninstall', testObject.label);
S
Sandeep Somavarapu 已提交
218
				assert.equal('extension-action uninstall', testObject.class);
S
Sandeep Somavarapu 已提交
219
			});
220 221
	});

S
Sandeep Somavarapu 已提交
222
	test('Test Uninstall action when state is installed and is system extension', () => {
223
		const testObject: ExtensionsActions.UninstallAction = instantiationService.createInstance(ExtensionsActions.UninstallAction);
S
Sandeep Somavarapu 已提交
224
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
225
		const local = aLocalExtension('a', {}, { type: ExtensionType.System });
226 227
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
228 229 230 231 232
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				assert.ok(!testObject.enabled);
				assert.equal('Uninstall', testObject.label);
S
Sandeep Somavarapu 已提交
233
				assert.equal('extension-action uninstall', testObject.class);
S
Sandeep Somavarapu 已提交
234
			});
235 236
	});

S
Sandeep Somavarapu 已提交
237 238
	test('Test Uninstall action when state is installing and is user extension', () => {
		const testObject: ExtensionsActions.UninstallAction = instantiationService.createInstance(ExtensionsActions.UninstallAction);
S
Sandeep Somavarapu 已提交
239
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
240 241 242 243 244 245
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				const gallery = aGalleryExtension('a');
S
Sandeep Somavarapu 已提交
246 247
				const extension = extensions[0];
				extension.gallery = gallery;
S
Sandeep Somavarapu 已提交
248
				installEvent.fire({ identifier: gallery.identifier, gallery });
S
Sandeep Somavarapu 已提交
249
				testObject.extension = extension;
S
Sandeep Somavarapu 已提交
250 251 252 253
				assert.ok(!testObject.enabled);
			});
	});

S
Sandeep Somavarapu 已提交
254
	test('Test Uninstall action after extension is installed', () => {
255
		const testObject: ExtensionsActions.UninstallAction = instantiationService.createInstance(ExtensionsActions.UninstallAction);
S
Sandeep Somavarapu 已提交
256
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
257 258 259
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
260 261 262
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(paged => {
				testObject.extension = paged.firstPage[0];
263

S
Sandeep Somavarapu 已提交
264
				installEvent.fire({ identifier: gallery.identifier, gallery });
S
Sandeep Somavarapu 已提交
265
				didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
266

S
Sandeep Somavarapu 已提交
267 268
				assert.ok(testObject.enabled);
				assert.equal('Uninstall', testObject.label);
S
Sandeep Somavarapu 已提交
269
				assert.equal('extension-action uninstall', testObject.class);
S
Sandeep Somavarapu 已提交
270
			});
271 272 273
	});

	test('Test CombinedInstallAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
274
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
275
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
276 277

		assert.ok(!testObject.enabled);
S
Sandeep Somavarapu 已提交
278
		assert.equal('extension-action prominent install no-extension', testObject.class);
279 280
	});

S
Sandeep Somavarapu 已提交
281
	test('Test CombinedInstallAction when extension is system extension', () => {
S
Sandeep Somavarapu 已提交
282
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
283
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
284
		const local = aLocalExtension('a', {}, { type: ExtensionType.System });
285 286
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
287 288 289 290 291 292
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				assert.ok(!testObject.enabled);
				assert.equal('extension-action prominent install no-extension', testObject.class);
			});
293 294
	});

S
Sandeep Somavarapu 已提交
295
	test('Test CombinedInstallAction when installAction is enabled', () => {
296
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
S
Sandeep Somavarapu 已提交
297
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
298
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
299 300 301
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
302 303 304 305 306 307 308
		return workbenchService.queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
				assert.ok(testObject.enabled);
				assert.equal('Install', testObject.label);
				assert.equal('extension-action prominent install', testObject.class);
			});
309 310
	});

S
Sandeep Somavarapu 已提交
311
	test('Test CombinedInstallAction when unInstallAction is enabled', () => {
S
Sandeep Somavarapu 已提交
312
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
313
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
314 315 316
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
317 318 319 320 321
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				assert.ok(testObject.enabled);
				assert.equal('Uninstall', testObject.label);
S
Sandeep Somavarapu 已提交
322
				assert.equal('extension-action uninstall', testObject.class);
S
Sandeep Somavarapu 已提交
323
			});
324 325
	});

S
Sandeep Somavarapu 已提交
326
	test('Test CombinedInstallAction when state is installing', () => {
S
Sandeep Somavarapu 已提交
327
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
328
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
329 330 331
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
332 333 334 335 336 337 338 339 340
		return workbenchService.queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
				installEvent.fire({ identifier: gallery.identifier, gallery });

				assert.ok(!testObject.enabled);
				assert.equal('Installing', testObject.label);
				assert.equal('extension-action install installing', testObject.class);
			});
341 342
	});

S
Sandeep Somavarapu 已提交
343 344
	test('Test CombinedInstallAction when state is installing during update', () => {
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
345
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
346 347 348 349 350 351
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				const gallery = aGalleryExtension('a');
S
Sandeep Somavarapu 已提交
352 353 354
				const extension = extensions[0];
				extension.gallery = gallery;
				testObject.extension = extension;
S
Sandeep Somavarapu 已提交
355 356 357 358 359 360 361
				installEvent.fire({ identifier: gallery.identifier, gallery });
				assert.ok(!testObject.enabled);
				assert.equal('Installing', testObject.label);
				assert.equal('extension-action install installing', testObject.class);
			});
	});

S
Sandeep Somavarapu 已提交
362
	test('Test CombinedInstallAction when state is uninstalling', () => {
S
Sandeep Somavarapu 已提交
363
		const testObject: ExtensionsActions.CombinedInstallAction = instantiationService.createInstance(ExtensionsActions.CombinedInstallAction);
S
Sandeep Somavarapu 已提交
364
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
365 366 367
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
368 369 370 371 372 373
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				uninstallEvent.fire(local.identifier);
				assert.ok(!testObject.enabled);
				assert.equal('Uninstalling', testObject.label);
S
Sandeep Somavarapu 已提交
374
				assert.equal('extension-action uninstall uninstalling', testObject.class);
S
Sandeep Somavarapu 已提交
375
			});
376 377 378
	});

	test('Test UpdateAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
379
		const testObject: ExtensionsActions.UpdateAction = instantiationService.createInstance(ExtensionsActions.UpdateAction);
S
Sandeep Somavarapu 已提交
380
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
381 382 383 384

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
385
	test('Test UpdateAction when extension is uninstalled', () => {
S
Sandeep Somavarapu 已提交
386
		const testObject: ExtensionsActions.UpdateAction = instantiationService.createInstance(ExtensionsActions.UpdateAction);
S
Sandeep Somavarapu 已提交
387
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
388 389
		const gallery = aGalleryExtension('a', { version: '1.0.0' });
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
390 391 392 393 394
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
				assert.ok(!testObject.enabled);
			});
395 396
	});

S
Sandeep Somavarapu 已提交
397
	test('Test UpdateAction when extension is installed and not outdated', () => {
S
Sandeep Somavarapu 已提交
398
		const testObject: ExtensionsActions.UpdateAction = instantiationService.createInstance(ExtensionsActions.UpdateAction);
S
Sandeep Somavarapu 已提交
399
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
400 401 402
		const local = aLocalExtension('a', { version: '1.0.0' });
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
403 404 405 406 407 408
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', { identifier: local.identifier, version: local.manifest.version })));
				return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
					.then(extensions => assert.ok(!testObject.enabled));
409 410 411
			});
	});

S
Sandeep Somavarapu 已提交
412
	test('Test UpdateAction when extension is installed outdated and system extension', () => {
S
Sandeep Somavarapu 已提交
413
		const testObject: ExtensionsActions.UpdateAction = instantiationService.createInstance(ExtensionsActions.UpdateAction);
S
Sandeep Somavarapu 已提交
414
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
415
		const local = aLocalExtension('a', { version: '1.0.0' }, { type: ExtensionType.System });
416 417
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
418 419 420 421 422 423
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', { identifier: local.identifier, version: '1.0.1' })));
				return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
					.then(extensions => assert.ok(!testObject.enabled));
424 425 426
			});
	});

S
Sandeep Somavarapu 已提交
427
	test('Test UpdateAction when extension is installed outdated and user extension', () => {
S
Sandeep Somavarapu 已提交
428
		const testObject: ExtensionsActions.UpdateAction = instantiationService.createInstance(ExtensionsActions.UpdateAction);
S
Sandeep Somavarapu 已提交
429
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
430 431 432
		const local = aLocalExtension('a', { version: '1.0.0' });
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
433 434
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		return workbenchService.queryLocal()
S
Sandeep Somavarapu 已提交
435
			.then(async extensions => {
S
Sandeep Somavarapu 已提交
436 437
				testObject.extension = extensions[0];
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', { identifier: local.identifier, version: '1.0.1' })));
S
Sandeep Somavarapu 已提交
438 439 440 441 442 443 444 445 446
				assert.ok(!testObject.enabled);
				return new Promise(c => {
					testObject.onDidChange(() => {
						if (testObject.enabled) {
							c();
						}
					});
					instantiationService.get(IExtensionsWorkbenchService).queryGallery();
				});
447 448 449
			});
	});

S
Sandeep Somavarapu 已提交
450
	test('Test UpdateAction when extension is installing and outdated and user extension', () => {
S
Sandeep Somavarapu 已提交
451
		const testObject: ExtensionsActions.UpdateAction = instantiationService.createInstance(ExtensionsActions.UpdateAction);
S
Sandeep Somavarapu 已提交
452
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
453 454 455
		const local = aLocalExtension('a', { version: '1.0.0' });
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
456 457 458 459 460 461 462 463 464 465
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				const gallery = aGalleryExtension('a', { identifier: local.identifier, version: '1.0.1' });
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
				return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
					.then(extensions => {
						installEvent.fire({ identifier: local.identifier, gallery });
						assert.ok(!testObject.enabled);
					});
466 467 468 469 470
			});
	});

	test('Test ManageExtensionAction when there is no extension', () => {
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
471
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
472 473 474 475

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
476
	test('Test ManageExtensionAction when extension is installed', () => {
477
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
478
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
479 480 481
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
482 483 484 485 486 487 488
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				assert.ok(testObject.enabled);
				assert.equal('extension-action manage', testObject.class);
				assert.equal('', testObject.tooltip);
			});
489 490
	});

S
Sandeep Somavarapu 已提交
491
	test('Test ManageExtensionAction when extension is uninstalled', () => {
492
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
493
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
494 495 496
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
497 498 499 500 501 502 503
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
				testObject.extension = page.firstPage[0];
				assert.ok(!testObject.enabled);
				assert.equal('extension-action manage hide', testObject.class);
				assert.equal('', testObject.tooltip);
			});
504 505
	});

S
Sandeep Somavarapu 已提交
506
	test('Test ManageExtensionAction when extension is installing', () => {
507
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
508
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
509 510 511
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
512 513 514
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
				testObject.extension = page.firstPage[0];
515

S
Sandeep Somavarapu 已提交
516 517 518 519 520
				installEvent.fire({ identifier: gallery.identifier, gallery });
				assert.ok(!testObject.enabled);
				assert.equal('extension-action manage hide', testObject.class);
				assert.equal('', testObject.tooltip);
			});
S
Sandeep Somavarapu 已提交
521 522
	});

S
Sandeep Somavarapu 已提交
523
	test('Test ManageExtensionAction when extension is queried from gallery and installed', () => {
S
Sandeep Somavarapu 已提交
524
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
525
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
526 527 528
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
529 530 531 532
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
				testObject.extension = page.firstPage[0];
				installEvent.fire({ identifier: gallery.identifier, gallery });
S
Sandeep Somavarapu 已提交
533
				didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
S
Sandeep Somavarapu 已提交
534

S
Sandeep Somavarapu 已提交
535 536 537 538
				assert.ok(testObject.enabled);
				assert.equal('extension-action manage', testObject.class);
				assert.equal('', testObject.tooltip);
			});
S
Sandeep Somavarapu 已提交
539 540
	});

S
Sandeep Somavarapu 已提交
541
	test('Test ManageExtensionAction when extension is system extension', () => {
S
Sandeep Somavarapu 已提交
542
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
543
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
544
		const local = aLocalExtension('a', {}, { type: ExtensionType.System });
S
Sandeep Somavarapu 已提交
545 546
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
547 548 549
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
550 551
				assert.ok(testObject.enabled);
				assert.equal('extension-action manage', testObject.class);
S
Sandeep Somavarapu 已提交
552 553
				assert.equal('', testObject.tooltip);
			});
554 555
	});

S
Sandeep Somavarapu 已提交
556
	test('Test ManageExtensionAction when extension is uninstalling', () => {
557
		const testObject: ExtensionsActions.ManageExtensionAction = instantiationService.createInstance(ExtensionsActions.ManageExtensionAction);
S
Sandeep Somavarapu 已提交
558
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
559 560 561
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
562 563 564 565
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				uninstallEvent.fire(local.identifier);
566

S
Sandeep Somavarapu 已提交
567 568 569 570
				assert.ok(!testObject.enabled);
				assert.equal('extension-action manage', testObject.class);
				assert.equal('Uninstalling', testObject.tooltip);
			});
571 572 573
	});

	test('Test EnableForWorkspaceAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
574
		const testObject: ExtensionsActions.EnableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.EnableForWorkspaceAction);
575 576 577 578

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
579
	test('Test EnableForWorkspaceAction when there extension is not disabled', () => {
580 581 582
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
583 584
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
585 586
				const testObject: ExtensionsActions.EnableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.EnableForWorkspaceAction);
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
587 588
				assert.ok(!testObject.enabled);
			});
589 590
	});

S
Sandeep Somavarapu 已提交
591
	test('Test EnableForWorkspaceAction when the extension is disabled globally', () => {
592
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
593
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
594 595 596 597 598
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
599 600
						const testObject: ExtensionsActions.EnableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.EnableForWorkspaceAction);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
601 602
						assert.ok(testObject.enabled);
					});
S
Sandeep Somavarapu 已提交
603
			});
604 605
	});

S
Sandeep Somavarapu 已提交
606
	test('Test EnableForWorkspaceAction when extension is disabled for workspace', () => {
607
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
608
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled)
S
Sandeep Somavarapu 已提交
609 610 611 612 613
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
614 615
						const testObject: ExtensionsActions.EnableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.EnableForWorkspaceAction);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
616 617
						assert.ok(testObject.enabled);
					});
S
Sandeep Somavarapu 已提交
618
			});
619 620
	});

S
Sandeep Somavarapu 已提交
621
	test('Test EnableForWorkspaceAction when the extension is disabled globally and workspace', () => {
622
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
623 624
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
			.then(() => instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled))
S
Sandeep Somavarapu 已提交
625 626 627 628 629
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
630 631
						const testObject: ExtensionsActions.EnableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.EnableForWorkspaceAction);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
632 633
						assert.ok(testObject.enabled);
					});
S
Sandeep Somavarapu 已提交
634
			});
635 636 637
	});

	test('Test EnableGloballyAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
638
		const testObject: ExtensionsActions.EnableGloballyAction = instantiationService.createInstance(ExtensionsActions.EnableGloballyAction);
639 640 641 642

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
643
	test('Test EnableGloballyAction when the extension is not disabled', () => {
644 645 646
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
647 648
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
649 650
				const testObject: ExtensionsActions.EnableGloballyAction = instantiationService.createInstance(ExtensionsActions.EnableGloballyAction);
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
651 652
				assert.ok(!testObject.enabled);
			});
653 654
	});

S
Sandeep Somavarapu 已提交
655
	test('Test EnableGloballyAction when the extension is disabled for workspace', () => {
656
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
657
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled)
S
Sandeep Somavarapu 已提交
658 659 660 661 662
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
663 664
						const testObject: ExtensionsActions.EnableGloballyAction = instantiationService.createInstance(ExtensionsActions.EnableGloballyAction);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
665
						assert.ok(!testObject.enabled);
S
Sandeep Somavarapu 已提交
666 667
					});
			});
668 669
	});

S
Sandeep Somavarapu 已提交
670
	test('Test EnableGloballyAction when the extension is disabled globally', () => {
671
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
672
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
673 674 675 676 677
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
678 679
						const testObject: ExtensionsActions.EnableGloballyAction = instantiationService.createInstance(ExtensionsActions.EnableGloballyAction);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
680 681 682
						assert.ok(testObject.enabled);
					});
			});
683 684
	});

S
Sandeep Somavarapu 已提交
685
	test('Test EnableGloballyAction when the extension is disabled in both', () => {
686
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
687 688
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
			.then(() => instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled))
S
Sandeep Somavarapu 已提交
689 690 691 692 693
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
694 695
						const testObject: ExtensionsActions.EnableGloballyAction = instantiationService.createInstance(ExtensionsActions.EnableGloballyAction);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
696
						assert.ok(!testObject.enabled);
S
Sandeep Somavarapu 已提交
697 698
					});
			});
699 700 701
	});

	test('Test EnableAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
702
		const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
703 704 705 706

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
707
	test('Test EnableDropDownAction when extension is installed and enabled', () => {
708 709 710
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
711 712
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
713
				const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
S
Sandeep Somavarapu 已提交
714
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
715 716
				assert.ok(!testObject.enabled);
			});
717 718
	});

S
Sandeep Somavarapu 已提交
719
	test('Test EnableDropDownAction when extension is installed and disabled globally', () => {
720
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
721
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
722 723 724 725 726
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
727
						const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
S
Sandeep Somavarapu 已提交
728
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
729 730 731
						assert.ok(testObject.enabled);
					});
			});
732 733
	});

S
Sandeep Somavarapu 已提交
734
	test('Test EnableDropDownAction when extension is installed and disabled for workspace', () => {
735
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
736
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled)
S
Sandeep Somavarapu 已提交
737 738 739 740 741
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
742
						const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
S
Sandeep Somavarapu 已提交
743
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
744 745 746
						assert.ok(testObject.enabled);
					});
			});
747 748
	});

S
Sandeep Somavarapu 已提交
749
	test('Test EnableDropDownAction when extension is uninstalled', () => {
750 751 752
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
753 754
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
S
Sandeep Somavarapu 已提交
755
				const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
S
Sandeep Somavarapu 已提交
756
				testObject.extension = page.firstPage[0];
S
Sandeep Somavarapu 已提交
757 758
				assert.ok(!testObject.enabled);
			});
759 760
	});

S
Sandeep Somavarapu 已提交
761
	test('Test EnableDropDownAction when extension is installing', () => {
762 763 764
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
765 766
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
S
Sandeep Somavarapu 已提交
767
				const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
S
Sandeep Somavarapu 已提交
768 769
				testObject.extension = page.firstPage[0];
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
770

S
Sandeep Somavarapu 已提交
771 772 773
				installEvent.fire({ identifier: gallery.identifier, gallery });
				assert.ok(!testObject.enabled);
			});
774 775
	});

S
Sandeep Somavarapu 已提交
776
	test('Test EnableDropDownAction when extension is uninstalling', () => {
777 778 779
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
780 781
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
782
				const testObject: ExtensionsActions.EnableDropDownAction = instantiationService.createInstance(ExtensionsActions.EnableDropDownAction);
S
Sandeep Somavarapu 已提交
783
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
784 785 786
				uninstallEvent.fire(local.identifier);
				assert.ok(!testObject.enabled);
			});
787 788 789
	});

	test('Test DisableForWorkspaceAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
790
		const testObject: ExtensionsActions.DisableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.DisableForWorkspaceAction, []);
791 792 793 794

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
795
	test('Test DisableForWorkspaceAction when the extension is disabled globally', () => {
796
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
797
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
798 799 800 801 802
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
803 804
						const testObject: ExtensionsActions.DisableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.DisableForWorkspaceAction, []);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
805 806 807
						assert.ok(!testObject.enabled);
					});
			});
808 809
	});

S
Sandeep Somavarapu 已提交
810
	test('Test DisableForWorkspaceAction when the extension is disabled workspace', () => {
811
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
812
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
813 814 815 816 817
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
818 819
						const testObject: ExtensionsActions.DisableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.DisableForWorkspaceAction, []);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
820 821 822
						assert.ok(!testObject.enabled);
					});
			});
823 824
	});

S
Sandeep Somavarapu 已提交
825
	test('Test DisableForWorkspaceAction when extension is enabled', () => {
826 827 828
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
829 830
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
831 832
				const testObject: ExtensionsActions.DisableForWorkspaceAction = instantiationService.createInstance(ExtensionsActions.DisableForWorkspaceAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
833
				assert.ok(testObject.enabled);
S
Sandeep Somavarapu 已提交
834
			});
835 836 837
	});

	test('Test DisableGloballyAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
838
		const testObject: ExtensionsActions.DisableGloballyAction = instantiationService.createInstance(ExtensionsActions.DisableGloballyAction, []);
839 840 841 842

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
843
	test('Test DisableGloballyAction when the extension is disabled globally', () => {
844
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
845
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
846 847 848 849 850
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
851 852
						const testObject: ExtensionsActions.DisableGloballyAction = instantiationService.createInstance(ExtensionsActions.DisableGloballyAction, []);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
853 854 855
						assert.ok(!testObject.enabled);
					});
			});
856 857
	});

S
Sandeep Somavarapu 已提交
858
	test('Test DisableGloballyAction when the extension is disabled for workspace', () => {
859
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
860
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled)
S
Sandeep Somavarapu 已提交
861 862 863 864 865
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
866 867
						const testObject: ExtensionsActions.DisableGloballyAction = instantiationService.createInstance(ExtensionsActions.DisableGloballyAction, []);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
868 869 870
						assert.ok(!testObject.enabled);
					});
			});
871 872
	});

S
Sandeep Somavarapu 已提交
873
	test('Test DisableGloballyAction when the extension is enabled', () => {
874 875 876
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
877 878
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
879 880
				const testObject: ExtensionsActions.DisableGloballyAction = instantiationService.createInstance(ExtensionsActions.DisableGloballyAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
881
				assert.ok(testObject.enabled);
S
Sandeep Somavarapu 已提交
882
			});
883 884
	});

S
Sandeep Somavarapu 已提交
885
	test('Test DisableDropDownAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
886
		const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, []);
887 888 889 890

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
891
	test('Test DisableDropDownAction when extension is installed and enabled', () => {
892 893 894
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
895 896
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
897 898
				const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
				testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
899
				assert.ok(testObject.enabled);
S
Sandeep Somavarapu 已提交
900
			});
901 902
	});

S
Sandeep Somavarapu 已提交
903
	test('Test DisableDropDownAction when extension is installed and disabled globally', () => {
904
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
905
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
906 907 908 909 910
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
911 912
						const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
913 914 915
						assert.ok(!testObject.enabled);
					});
			});
916 917
	});

S
Sandeep Somavarapu 已提交
918
	test('Test DisableDropDownAction when extension is installed and disabled for workspace', () => {
919
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
920
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.WorkspaceDisabled)
S
Sandeep Somavarapu 已提交
921 922 923 924 925
			.then(() => {
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

				return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
					.then(extensions => {
S
Sandeep Somavarapu 已提交
926 927
						const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
						testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
928 929 930
						assert.ok(!testObject.enabled);
					});
			});
931 932
	});

S
Sandeep Somavarapu 已提交
933
	test('Test DisableDropDownAction when extension is uninstalled', () => {
934 935 936
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
937 938
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
S
Sandeep Somavarapu 已提交
939 940
				const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
				testObject.extension = page.firstPage[0];
S
Sandeep Somavarapu 已提交
941 942
				assert.ok(!testObject.enabled);
			});
943 944
	});

S
Sandeep Somavarapu 已提交
945
	test('Test DisableDropDownAction when extension is installing', () => {
946 947 948
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

S
Sandeep Somavarapu 已提交
949 950
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then(page => {
S
Sandeep Somavarapu 已提交
951 952 953
				const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
				testObject.extension = page.firstPage[0];
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
954 955 956
				installEvent.fire({ identifier: gallery.identifier, gallery });
				assert.ok(!testObject.enabled);
			});
957 958
	});

S
Sandeep Somavarapu 已提交
959
	test('Test DisableDropDownAction when extension is uninstalling', () => {
960 961 962
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
963 964
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
S
Sandeep Somavarapu 已提交
965 966 967
				const testObject: ExtensionsActions.DisableDropDownAction = instantiationService.createInstance(ExtensionsActions.DisableDropDownAction, [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
				testObject.extension = extensions[0];
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
968 969 970
				uninstallEvent.fire(local.identifier);
				assert.ok(!testObject.enabled);
			});
971 972 973 974 975 976 977 978
	});

	test('Test UpdateAllAction when no installed extensions', () => {
		const testObject: ExtensionsActions.UpdateAllAction = instantiationService.createInstance(ExtensionsActions.UpdateAllAction, 'id', 'label');

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
979
	test('Test UpdateAllAction when installed extensions are not outdated', () => {
980 981
		const testObject: ExtensionsActions.UpdateAllAction = instantiationService.createInstance(ExtensionsActions.UpdateAllAction, 'id', 'label');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [aLocalExtension('a'), aLocalExtension('b')]);
S
Sandeep Somavarapu 已提交
982 983
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => assert.ok(!testObject.enabled));
984 985
	});

S
Sandeep Somavarapu 已提交
986
	test('Test UpdateAllAction when some installed extensions are outdated', () => {
987 988 989 990
		const testObject: ExtensionsActions.UpdateAllAction = instantiationService.createInstance(ExtensionsActions.UpdateAllAction, 'id', 'label');
		const local = [aLocalExtension('a', { version: '1.0.1' }), aLocalExtension('b', { version: '1.0.1' }), aLocalExtension('c', { version: '1.0.1' })];
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', local);
S
Sandeep Somavarapu 已提交
991
		return workbenchService.queryLocal()
S
Sandeep Somavarapu 已提交
992 993
			.then(async () => {
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', { identifier: local[0].identifier, version: '1.0.2' }), aGalleryExtension('b', { identifier: local[1].identifier, version: '1.0.2' }), aGalleryExtension('c', local[2].manifest)));
S
Sandeep Somavarapu 已提交
994 995 996 997 998 999 1000 1001 1002
				assert.ok(!testObject.enabled);
				return new Promise(c => {
					testObject.onDidChange(() => {
						if (testObject.enabled) {
							c();
						}
					});
					workbenchService.queryGallery();
				});
1003 1004 1005
			});
	});

S
Sandeep Somavarapu 已提交
1006
	test('Test UpdateAllAction when some installed extensions are outdated and some outdated are being installed', () => {
1007 1008
		const testObject: ExtensionsActions.UpdateAllAction = instantiationService.createInstance(ExtensionsActions.UpdateAllAction, 'id', 'label');
		const local = [aLocalExtension('a', { version: '1.0.1' }), aLocalExtension('b', { version: '1.0.1' }), aLocalExtension('c', { version: '1.0.1' })];
S
Sandeep Somavarapu 已提交
1009
		const gallery = [aGalleryExtension('a', { identifier: local[0].identifier, version: '1.0.2' }), aGalleryExtension('b', { identifier: local[1].identifier, version: '1.0.2' }), aGalleryExtension('c', local[2].manifest)];
1010 1011
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', local);
S
Sandeep Somavarapu 已提交
1012
		return workbenchService.queryLocal()
S
Sandeep Somavarapu 已提交
1013 1014
			.then(async () => {
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(...gallery));
S
Sandeep Somavarapu 已提交
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
				assert.ok(!testObject.enabled);
				return new Promise(c => {
					installEvent.fire({ identifier: local[0].identifier, gallery: gallery[0] });
					testObject.onDidChange(() => {
						if (testObject.enabled) {
							c();
						}
					});
					workbenchService.queryGallery();
				});
1025 1026 1027
			});
	});

S
Sandeep Somavarapu 已提交
1028
	test('Test UpdateAllAction when some installed extensions are outdated and all outdated are being installed', () => {
1029 1030
		const testObject: ExtensionsActions.UpdateAllAction = instantiationService.createInstance(ExtensionsActions.UpdateAllAction, 'id', 'label');
		const local = [aLocalExtension('a', { version: '1.0.1' }), aLocalExtension('b', { version: '1.0.1' }), aLocalExtension('c', { version: '1.0.1' })];
S
Sandeep Somavarapu 已提交
1031
		const gallery = [aGalleryExtension('a', { identifier: local[0].identifier, version: '1.0.2' }), aGalleryExtension('b', { identifier: local[1].identifier, version: '1.0.2' }), aGalleryExtension('c', local[2].manifest)];
1032 1033
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', local);
S
Sandeep Somavarapu 已提交
1034 1035 1036 1037 1038 1039 1040 1041 1042
		return workbenchService.queryLocal()
			.then(() => {
				instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(...gallery));
				return workbenchService.queryGallery()
					.then(() => {
						installEvent.fire({ identifier: local[0].identifier, gallery: gallery[0] });
						installEvent.fire({ identifier: local[1].identifier, gallery: gallery[1] });
						assert.ok(!testObject.enabled);
					});
1043 1044 1045 1046
			});
	});

	test('Test ReloadAction when there is no extension', () => {
S
Sandeep Somavarapu 已提交
1047
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1048
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1049 1050 1051 1052

		assert.ok(!testObject.enabled);
	});

S
Sandeep Somavarapu 已提交
1053
	test('Test ReloadAction when extension state is installing', () => {
S
Sandeep Somavarapu 已提交
1054
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1055
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1056 1057 1058
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
1059 1060 1061 1062
		return workbenchService.queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
				installEvent.fire({ identifier: gallery.identifier, gallery });
1063

S
Sandeep Somavarapu 已提交
1064 1065
				assert.ok(!testObject.enabled);
			});
1066 1067
	});

S
Sandeep Somavarapu 已提交
1068
	test('Test ReloadAction when extension state is uninstalling', () => {
S
Sandeep Somavarapu 已提交
1069
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1070
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1071 1072 1073
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);

S
Sandeep Somavarapu 已提交
1074 1075 1076 1077 1078 1079
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				uninstallEvent.fire(local.identifier);
				assert.ok(!testObject.enabled);
			});
1080 1081
	});

S
Sandeep Somavarapu 已提交
1082
	test('Test ReloadAction when extension is newly installed', async () => {
1083
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
S
Sandeep Somavarapu 已提交
1084
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1085
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1086 1087
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
1088

S
Sandeep Somavarapu 已提交
1089 1090 1091 1092 1093 1094
		const paged = await instantiationService.get(IExtensionsWorkbenchService).queryGallery();
		testObject.extension = paged.firstPage[0];
		assert.ok(!testObject.enabled);

		return new Promise(c => {
			testObject.onDidChange(() => {
R
Rob Lourens 已提交
1095
				if (testObject.enabled && testObject.tooltip === 'Please reload Visual Studio Code to complete the installation of this extension.') {
S
Sandeep Somavarapu 已提交
1096 1097
					c();
				}
S
Sandeep Somavarapu 已提交
1098
			});
S
Sandeep Somavarapu 已提交
1099 1100 1101
			installEvent.fire({ identifier: gallery.identifier, gallery });
			didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
		});
1102 1103
	});

S
Sandeep Somavarapu 已提交
1104
	test('Test ReloadAction when extension is installed and uninstalled', () => {
1105
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
S
Sandeep Somavarapu 已提交
1106
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1107
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1108 1109
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
S
Sandeep Somavarapu 已提交
1110 1111 1112
		return instantiationService.get(IExtensionsWorkbenchService).queryGallery()
			.then((paged) => {
				testObject.extension = paged.firstPage[0];
1113 1114 1115
				const identifier = gallery.identifier;
				installEvent.fire({ identifier, gallery });
				didInstallEvent.fire({ identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, { identifier }) });
S
Sandeep Somavarapu 已提交
1116
				uninstallEvent.fire(identifier);
1117
				didUninstallEvent.fire({ identifier });
S
Sandeep Somavarapu 已提交
1118 1119 1120

				assert.ok(!testObject.enabled);
			});
1121 1122
	});

S
Sandeep Somavarapu 已提交
1123
	test('Test ReloadAction when extension is uninstalled', async () => {
1124
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
S
Sandeep Somavarapu 已提交
1125
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1126
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1127 1128
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
S
Sandeep Somavarapu 已提交
1129 1130 1131 1132 1133
		const extensions = await instantiationService.get(IExtensionsWorkbenchService).queryLocal();
		testObject.extension = extensions[0];

		return new Promise(c => {
			testObject.onDidChange(() => {
R
Rob Lourens 已提交
1134
				if (testObject.enabled && testObject.tooltip === 'Please reload Visual Studio Code to complete the uninstallation of this extension.') {
S
Sandeep Somavarapu 已提交
1135 1136
					c();
				}
S
Sandeep Somavarapu 已提交
1137
			});
S
Sandeep Somavarapu 已提交
1138 1139 1140
			uninstallEvent.fire(local.identifier);
			didUninstallEvent.fire({ identifier: local.identifier });
		});
1141 1142
	});

S
Sandeep Somavarapu 已提交
1143
	test('Test ReloadAction when extension is uninstalled and installed', () => {
1144
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.a'), version: '1.0.0', extensionLocation: URI.file('pub.a') }]);
S
Sandeep Somavarapu 已提交
1145
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1146
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1147 1148
		const local = aLocalExtension('a');
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
S
Sandeep Somavarapu 已提交
1149 1150 1151 1152 1153
		return instantiationService.get(IExtensionsWorkbenchService).queryLocal()
			.then(extensions => {
				testObject.extension = extensions[0];
				uninstallEvent.fire(local.identifier);
				didUninstallEvent.fire({ identifier: local.identifier });
1154

S
Sandeep Somavarapu 已提交
1155
				const gallery = aGalleryExtension('a');
1156 1157 1158
				const identifier = gallery.identifier;
				installEvent.fire({ identifier, gallery });
				didInstallEvent.fire({ identifier, gallery, operation: InstallOperation.Install, local });
1159

S
Sandeep Somavarapu 已提交
1160 1161
				assert.ok(!testObject.enabled);
			});
1162 1163
	});

S
Sandeep Somavarapu 已提交
1164
	test('Test ReloadAction when extension is updated while running', async () => {
1165
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.a'), version: '1.0.1', extensionLocation: URI.file('pub.a') }]);
S
Sandeep Somavarapu 已提交
1166
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1167
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1168 1169 1170
		const local = aLocalExtension('a', { version: '1.0.1' });
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
S
Sandeep Somavarapu 已提交
1171 1172 1173 1174 1175
		const extensions = await workbenchService.queryLocal();
		testObject.extension = extensions[0];

		return new Promise(c => {
			testObject.onDidChange(() => {
1176
				if (testObject.enabled && testObject.tooltip === 'Please reload Visual Studio Code to complete the updating of this extension.') {
S
Sandeep Somavarapu 已提交
1177 1178
					c();
				}
S
Sandeep Somavarapu 已提交
1179
			});
S
Sandeep Somavarapu 已提交
1180 1181 1182 1183
			const gallery = aGalleryExtension('a', { uuid: local.identifier.id, version: '1.0.2' });
			installEvent.fire({ identifier: gallery.identifier, gallery });
			didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
		});
1184 1185
	});

S
Sandeep Somavarapu 已提交
1186
	test('Test ReloadAction when extension is updated when not running', () => {
1187
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
1188
		const local = aLocalExtension('a', { version: '1.0.1' });
S
Sandeep Somavarapu 已提交
1189
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
1190
			.then(() => {
S
Sandeep Somavarapu 已提交
1191
				const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1192
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
1193 1194 1195 1196 1197 1198 1199 1200
				const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
				return workbenchService.queryLocal()
					.then(extensions => {
						testObject.extension = extensions[0];

						const gallery = aGalleryExtension('a', { identifier: local.identifier, version: '1.0.2' });
						installEvent.fire({ identifier: gallery.identifier, gallery });
S
Sandeep Somavarapu 已提交
1201
						didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
S
Sandeep Somavarapu 已提交
1202 1203 1204 1205

						assert.ok(!testObject.enabled);
					});
			});
1206 1207
	});

S
Sandeep Somavarapu 已提交
1208
	test('Test ReloadAction when extension is disabled when running', () => {
1209
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.a'), extensionLocation: URI.file('pub.a') }]);
S
Sandeep Somavarapu 已提交
1210
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1211
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1212 1213 1214
		const local = aLocalExtension('a');
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
S
Sandeep Somavarapu 已提交
1215
		return workbenchService.queryLocal().then(extensions => {
1216
			testObject.extension = extensions[0];
S
Sandeep Somavarapu 已提交
1217
			return workbenchService.setEnablement(extensions[0], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
1218
				.then(() => testObject.update())
S
Sandeep Somavarapu 已提交
1219 1220
				.then(() => {
					assert.ok(testObject.enabled);
1221
					assert.equal('Please reload Visual Studio Code to complete the disabling of this extension.', testObject.tooltip);
S
Sandeep Somavarapu 已提交
1222
				});
1223 1224 1225
		});
	});

S
Sandeep Somavarapu 已提交
1226
	test('Test ReloadAction when extension enablement is toggled when running', () => {
1227
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.a'), version: '1.0.0', extensionLocation: URI.file('pub.a') }]);
S
Sandeep Somavarapu 已提交
1228
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1229
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
1230 1231 1232
		const local = aLocalExtension('a');
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
S
Sandeep Somavarapu 已提交
1233 1234 1235 1236 1237 1238 1239
		return workbenchService.queryLocal().
			then(extensions => {
				testObject.extension = extensions[0];
				return workbenchService.setEnablement(extensions[0], EnablementState.Disabled)
					.then(() => workbenchService.setEnablement(extensions[0], EnablementState.Enabled))
					.then(() => assert.ok(!testObject.enabled));
			});
1240 1241
	});

S
Sandeep Somavarapu 已提交
1242
	test('Test ReloadAction when extension is enabled when not running', () => {
1243
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
1244
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
1245
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
1246
			.then(() => {
S
Sandeep Somavarapu 已提交
1247
				const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1248
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
1249 1250 1251 1252 1253 1254
				const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
				return workbenchService.queryLocal()
					.then(extensions => {
						testObject.extension = extensions[0];
						return workbenchService.setEnablement(extensions[0], EnablementState.Enabled)
S
Sandeep Somavarapu 已提交
1255
							.then(() => testObject.update())
S
Sandeep Somavarapu 已提交
1256 1257
							.then(() => {
								assert.ok(testObject.enabled);
1258
								assert.equal('Please reload Visual Studio Code to complete the enabling of this extension.', testObject.tooltip);
S
Sandeep Somavarapu 已提交
1259 1260 1261
							});
					});
			});
1262 1263
	});

S
Sandeep Somavarapu 已提交
1264
	test('Test ReloadAction when extension enablement is toggled when not running', () => {
1265
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
1266
		const local = aLocalExtension('a');
S
Sandeep Somavarapu 已提交
1267
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
1268
			.then(() => {
S
Sandeep Somavarapu 已提交
1269
				const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1270
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
				const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
				return workbenchService.queryLocal()
					.then(extensions => {
						testObject.extension = extensions[0];
						return workbenchService.setEnablement(extensions[0], EnablementState.Enabled)
							.then(() => workbenchService.setEnablement(extensions[0], EnablementState.Disabled))
							.then(() => assert.ok(!testObject.enabled));
					});
			});
1281 1282
	});

S
Sandeep Somavarapu 已提交
1283
	test('Test ReloadAction when extension is updated when not running and enabled', () => {
1284
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
1285
		const local = aLocalExtension('a', { version: '1.0.1' });
S
Sandeep Somavarapu 已提交
1286
		return instantiationService.get(IExtensionEnablementService).setEnablement([local], EnablementState.Disabled)
S
Sandeep Somavarapu 已提交
1287
			.then(() => {
S
Sandeep Somavarapu 已提交
1288
				const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1289
				instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
1290 1291 1292 1293 1294 1295 1296 1297
				const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
				instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
				return workbenchService.queryLocal()
					.then(extensions => {
						testObject.extension = extensions[0];

						const gallery = aGalleryExtension('a', { identifier: local.identifier, version: '1.0.2' });
						installEvent.fire({ identifier: gallery.identifier, gallery });
S
Sandeep Somavarapu 已提交
1298
						didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', gallery, gallery) });
S
Sandeep Somavarapu 已提交
1299
						return workbenchService.setEnablement(extensions[0], EnablementState.Enabled)
S
Sandeep Somavarapu 已提交
1300
							.then(() => testObject.update())
S
Sandeep Somavarapu 已提交
1301 1302
							.then(() => {
								assert.ok(testObject.enabled);
1303
								assert.equal('Please reload Visual Studio Code to complete the enabling of this extension.', testObject.tooltip);
S
Sandeep Somavarapu 已提交
1304 1305 1306 1307
							});

					});
			});
1308 1309
	});

S
Sandeep Somavarapu 已提交
1310
	test('Test ReloadAction when a localization extension is newly installed', async () => {
1311
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.b'), extensionLocation: URI.file('pub.b') }]);
S
Sandeep Somavarapu 已提交
1312
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1313
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
		const gallery = aGalleryExtension('a');
		instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));

		const paged = await instantiationService.get(IExtensionsWorkbenchService).queryGallery();
		testObject.extension = paged.firstPage[0];
		assert.ok(!testObject.enabled);

		installEvent.fire({ identifier: gallery.identifier, gallery });
		didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', { ...gallery, ...{ contributes: <IExtensionContributions>{ localizations: [{ languageId: 'de', translations: [] }] } } }, gallery) });
		assert.ok(!testObject.enabled);
	});

	test('Test ReloadAction when a localization extension is updated while running', async () => {
1327
		instantiationService.stubPromise(IExtensionService, 'getExtensions', [{ identifier: new ExtensionIdentifier('pub.a'), version: '1.0.1', extensionLocation: URI.file('pub.a') }]);
S
Sandeep Somavarapu 已提交
1328
		const testObject: ExtensionsActions.ReloadAction = instantiationService.createInstance(ExtensionsActions.ReloadAction);
S
Sandeep Somavarapu 已提交
1329
		instantiationService.get(IExtensionsWorkbenchService).onChange(() => testObject.update());
S
Sandeep Somavarapu 已提交
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
		const local = aLocalExtension('a', { version: '1.0.1', contributes: <IExtensionContributions>{ localizations: [{ languageId: 'de', translations: [] }] } });
		const workbenchService = instantiationService.get(IExtensionsWorkbenchService);
		instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
		const extensions = await workbenchService.queryLocal();
		testObject.extension = extensions[0];

		const gallery = aGalleryExtension('a', { uuid: local.identifier.id, version: '1.0.2' });
		installEvent.fire({ identifier: gallery.identifier, gallery });
		didInstallEvent.fire({ identifier: gallery.identifier, gallery, operation: InstallOperation.Install, local: aLocalExtension('a', { ...gallery, ...{ contributes: <IExtensionContributions>{ localizations: [{ languageId: 'de', translations: [] }] } } }, gallery) });
		assert.ok(!testObject.enabled);
	});


1343 1344 1345 1346
	test(`RecommendToFolderAction`, () => {
		// TODO: Implement test
	});

1347
	function aLocalExtension(name: string = 'someext', manifest: any = {}, properties: any = {}): ILocalExtension {
1348 1349 1350 1351
		manifest = assign({ name, publisher: 'pub', version: '1.0.0' }, manifest);
		properties = assign({
			type: ExtensionType.User,
			location: URI.file(`pub.${name}`),
1352
			identifier: { id: getGalleryExtensionId(manifest.publisher, manifest.name), uuid: undefined },
1353 1354 1355
			metadata: { id: getGalleryExtensionId(manifest.publisher, manifest.name), publisherId: manifest.publisher, publisherDisplayName: 'somename' }
		}, properties);
		return <ILocalExtension>Object.create({ manifest, ...properties });
1356 1357 1358 1359
	}

	function aGalleryExtension(name: string, properties: any = {}, galleryExtensionProperties: any = {}, assets: any = {}): IGalleryExtension {
		const galleryExtension = <IGalleryExtension>Object.create({});
S
Sandeep Somavarapu 已提交
1360
		assign(galleryExtension, { name, publisher: 'pub', version: '1.0.0', properties: {}, assets: {} }, properties);
1361 1362
		assign(galleryExtension.properties, { dependencies: [] }, galleryExtensionProperties);
		assign(galleryExtension.assets, assets);
S
Sandeep Somavarapu 已提交
1363
		galleryExtension.identifier = { id: getGalleryExtensionId(galleryExtension.publisher, galleryExtension.name), uuid: generateUuid() };
1364 1365 1366 1367
		return <IGalleryExtension>galleryExtension;
	}

	function aPage<T>(...objects: T[]): IPager<T> {
1368
		return { firstPage: objects, total: objects.length, pageSize: objects.length, getPage: () => null! };
1369 1370
	}

1371
});