|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import * as fs from 'fs'; |
| 8 | +import * as path from 'path'; |
| 9 | +import { Application, ApplicationOptions, Logger } from '../../../../automation'; |
| 10 | +import { installAllHandlers } from '../../utils'; |
| 11 | + |
| 12 | +const SETTING_KEY = 'extensions.autoUpdate'; |
| 13 | +const SETTING_SELECTOR = `.settings-editor .setting-item-contents[data-key="${SETTING_KEY}"]`; |
| 14 | + |
| 15 | +export function setup(logger: Logger) { |
| 16 | + for (const testCase of [ |
| 17 | + { name: 'without policy', policyValue: undefined, expectedValue: 'on' }, |
| 18 | + { name: 'with policy', policyValue: 'off', expectedValue: 'off' }, |
| 19 | + ]) { |
| 20 | + describe(`Policy Plumbing (${testCase.name})`, () => { |
| 21 | + installAllHandlers(logger, options => configurePolicyTest(options, testCase.policyValue)); |
| 22 | + |
| 23 | + it('applies the expected setting value', async function () { |
| 24 | + const app = this.app as Application; |
| 25 | + |
| 26 | + await app.workbench.settingsEditor.searchSettingsUI(`@id:${SETTING_KEY}`); |
| 27 | + await app.code.waitForTextContent( |
| 28 | + `${SETTING_SELECTOR} .setting-item-control select option:checked`, |
| 29 | + testCase.expectedValue |
| 30 | + ); |
| 31 | + await app.code.waitForElement( |
| 32 | + `${SETTING_SELECTOR} .setting-item-control select:${testCase.policyValue === undefined ? 'enabled' : 'disabled'}` |
| 33 | + ); |
| 34 | + |
| 35 | + const indicatorSelector = `${SETTING_SELECTOR} .setting-indicators-container .setting-indicator`; |
| 36 | + await app.code.waitForElements( |
| 37 | + indicatorSelector, |
| 38 | + false, |
| 39 | + elements => elements.some(element => element.textContent.includes('Managed by organization')) |
| 40 | + === (testCase.policyValue !== undefined) |
| 41 | + ); |
| 42 | + }); |
| 43 | + }); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +function configurePolicyTest(options: ApplicationOptions, policyValue: string | undefined): ApplicationOptions { |
| 48 | + assert.ok(options.userDataDir); |
| 49 | + |
| 50 | + const portablePath = `${options.userDataDir}-policy`; |
| 51 | + const userDataDir = path.join(portablePath, 'user-data'); |
| 52 | + const userSettingsPath = path.join(userDataDir, 'User', 'settings.json'); |
| 53 | + fs.mkdirSync(path.dirname(userSettingsPath), { recursive: true }); |
| 54 | + fs.writeFileSync(userSettingsPath, JSON.stringify({ [SETTING_KEY]: 'on' })); |
| 55 | + |
| 56 | + const extraArgs = [...(options.extraArgs ?? [])]; |
| 57 | + if (policyValue !== undefined) { |
| 58 | + fs.writeFileSync(path.join(portablePath, 'policy.json'), JSON.stringify({ ExtensionsAutoUpdate: policyValue })); |
| 59 | + extraArgs.push('--__enable-file-policy'); |
| 60 | + } |
| 61 | + |
| 62 | + return { |
| 63 | + ...options, |
| 64 | + userDataDir, |
| 65 | + extraArgs, |
| 66 | + extraEnv: { |
| 67 | + ...options.extraEnv, |
| 68 | + VSCODE_PORTABLE: portablePath, |
| 69 | + }, |
| 70 | + }; |
| 71 | +} |
0 commit comments