Path: blob/main/src/vs/workbench/contrib/debug/test/browser/baseDebugView.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import * as dom from '../../../../../base/browser/dom.js';7import { HighlightedLabel } from '../../../../../base/browser/ui/highlightedlabel/highlightedLabel.js';8import { DisposableStore } from '../../../../../base/common/lifecycle.js';9import { isWindows } from '../../../../../base/common/platform.js';10import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';11import { IHoverService } from '../../../../../platform/hover/browser/hover.js';12import { NullHoverService } from '../../../../../platform/hover/test/browser/nullHoverService.js';13import { TestInstantiationService } from '../../../../../platform/instantiation/test/common/instantiationServiceMock.js';14import { workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js';15import { renderViewTree } from '../../browser/baseDebugView.js';16import { DebugExpressionRenderer } from '../../browser/debugExpressionRenderer.js';17import { isStatusbarInDebugMode } from '../../browser/statusbarColorProvider.js';18import { State } from '../../common/debug.js';19import { Expression, Scope, StackFrame, Thread, Variable } from '../../common/debugModel.js';20import { MockSession } from '../common/mockDebug.js';21import { createTestSession } from './callStack.test.js';22import { createMockDebugModel } from './mockDebugModel.js';23import { TestConfigurationService } from '../../../../../platform/configuration/test/common/testConfigurationService.js';24import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';25const $ = dom.$;262728suite('Debug - Base Debug View', () => {29const disposables = ensureNoDisposablesAreLeakedInTestSuite();30let renderer: DebugExpressionRenderer;31let configurationService: TestConfigurationService;3233function assertVariable(session: MockSession, scope: Scope, disposables: Pick<DisposableStore, "add">, displayType: boolean) {34let variable = new Variable(session, 1, scope, 2, 'foo', 'bar.foo', undefined, 0, 0, undefined, {}, 'string');35let expression = $('.');36let name = $('.');37let type = $('.');38let value = $('.');39const label = new HighlightedLabel(name);40const lazyButton = $('.');41const store = disposables.add(new DisposableStore());42store.add(renderer.renderVariable({ expression, name, type, value, label, lazyButton }, variable, { showChanged: false }));4344assert.strictEqual(label.element.textContent, 'foo');45assert.strictEqual(value.textContent, '');4647variable.value = 'hey';48expression = $('.');49name = $('.');50type = $('.');51value = $('.');52store.add(renderer.renderVariable({ expression, name, type, value, label, lazyButton }, variable, { showChanged: false }));53assert.strictEqual(value.textContent, 'hey');54assert.strictEqual(label.element.textContent, displayType ? 'foo: ' : 'foo =');55assert.strictEqual(type.textContent, displayType ? 'string =' : '');5657variable.value = isWindows ? 'C:\\foo.js:5' : '/foo.js:5';58expression = $('.');59name = $('.');60type = $('.');61value = $('.');62store.add(renderer.renderVariable({ expression, name, type, value, label, lazyButton }, variable, { showChanged: false }));63assert.ok(value.querySelector('a'));64assert.strictEqual(value.querySelector('a')!.textContent, variable.value);6566variable = new Variable(session, 1, scope, 2, 'console', 'console', '5', 0, 0, undefined, { kind: 'virtual' });67expression = $('.');68name = $('.');69type = $('.');70value = $('.');71store.add(renderer.renderVariable({ expression, name, type, value, label, lazyButton }, variable, { showChanged: false }));72assert.strictEqual(name.className, 'virtual');73assert.strictEqual(label.element.textContent, 'console =');74assert.strictEqual(value.className, 'value number');7576variable = new Variable(session, 1, scope, 2, 'xpto', 'xpto.xpto', undefined, 0, 0, undefined, {}, 'custom-type');77store.add(renderer.renderVariable({ expression, name, type, value, label, lazyButton }, variable, { showChanged: false }));78assert.strictEqual(label.element.textContent, 'xpto');79assert.strictEqual(value.textContent, '');80variable.value = '2';81expression = $('.');82name = $('.');83type = $('.');84value = $('.');85store.add(renderer.renderVariable({ expression, name, type, value, label, lazyButton }, variable, { showChanged: false }));86assert.strictEqual(value.textContent, '2');87assert.strictEqual(label.element.textContent, displayType ? 'xpto: ' : 'xpto =');88assert.strictEqual(type.textContent, displayType ? 'custom-type =' : '');8990label.dispose();91}9293/**94* Instantiate services for use by the functions being tested.95*/96setup(() => {97const instantiationService: TestInstantiationService = workbenchInstantiationService(undefined, disposables);98configurationService = instantiationService.createInstance(TestConfigurationService);99instantiationService.stub(IConfigurationService, configurationService);100instantiationService.stub(IHoverService, NullHoverService);101renderer = instantiationService.createInstance(DebugExpressionRenderer);102});103104test('render view tree', () => {105const container = $('.container');106const treeContainer = renderViewTree(container);107108assert.strictEqual(treeContainer.className, 'debug-view-content file-icon-themable-tree');109assert.strictEqual(container.childElementCount, 1);110assert.strictEqual(container.firstChild, treeContainer);111assert.strictEqual(dom.isHTMLDivElement(treeContainer), true);112});113114test('render expression value', () => {115let container = $('.container');116const store = disposables.add(new DisposableStore());117store.add(renderer.renderValue(container, 'render \n me', {}));118assert.strictEqual(container.className, 'container value');119assert.strictEqual(container.textContent, 'render \n me');120121const expression = new Expression('console');122expression.value = 'Object';123container = $('.container');124store.add(renderer.renderValue(container, expression, { colorize: true }));125assert.strictEqual(container.className, 'container value unavailable error');126127expression.available = true;128expression.value = '"string value"';129container = $('.container');130store.add(renderer.renderValue(container, expression, { colorize: true }));131assert.strictEqual(container.className, 'container value string');132assert.strictEqual(container.textContent, '"string value"');133134expression.type = 'boolean';135container = $('.container');136store.add(renderer.renderValue(container, expression, { colorize: true }));137assert.strictEqual(container.className, 'container value boolean');138assert.strictEqual(container.textContent, expression.value);139140expression.value = 'this is a long string';141container = $('.container');142store.add(renderer.renderValue(container, expression, { colorize: true, maxValueLength: 4 }));143assert.strictEqual(container.textContent, 'this...');144145expression.value = isWindows ? 'C:\\foo.js:5' : '/foo.js:5';146container = $('.container');147store.add(renderer.renderValue(container, expression, { colorize: true }));148assert.ok(container.querySelector('a'));149assert.strictEqual(container.querySelector('a')!.textContent, expression.value);150});151152test('render variable', () => {153const session = new MockSession();154const thread = new Thread(session, 'mockthread', 1);155const range = {156startLineNumber: 1,157startColumn: 1,158endLineNumber: undefined!,159endColumn: undefined!160};161const stackFrame = new StackFrame(thread, 1, null!, 'app.js', 'normal', range, 0, true);162const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10);163164configurationService.setUserConfiguration('debug.showVariableTypes', false);165assertVariable(session, scope, disposables, false);166167});168169test('render variable with display type setting', () => {170const session = new MockSession();171const thread = new Thread(session, 'mockthread', 1);172const range = {173startLineNumber: 1,174startColumn: 1,175endLineNumber: undefined!,176endColumn: undefined!177};178const stackFrame = new StackFrame(thread, 1, null!, 'app.js', 'normal', range, 0, true);179const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10);180181configurationService.setUserConfiguration('debug.showVariableTypes', true);182assertVariable(session, scope, disposables, true);183});184185test('statusbar in debug mode', () => {186const model = createMockDebugModel(disposables);187const session = disposables.add(createTestSession(model));188const session2 = disposables.add(createTestSession(model, undefined, { suppressDebugStatusbar: true }));189assert.strictEqual(isStatusbarInDebugMode(State.Inactive, []), false);190assert.strictEqual(isStatusbarInDebugMode(State.Initializing, [session]), false);191assert.strictEqual(isStatusbarInDebugMode(State.Running, [session]), true);192assert.strictEqual(isStatusbarInDebugMode(State.Stopped, [session]), true);193194assert.strictEqual(isStatusbarInDebugMode(State.Running, [session2]), false);195assert.strictEqual(isStatusbarInDebugMode(State.Running, [session, session2]), true);196197session.configuration.noDebug = true;198assert.strictEqual(isStatusbarInDebugMode(State.Running, [session]), false);199assert.strictEqual(isStatusbarInDebugMode(State.Running, [session, session2]), false);200});201});202203204