|
| 1 | +// Copyright 2025 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import * as Common from '../../core/common/common.js'; |
| 6 | +import type * as Platform from '../../core/platform/platform.js'; |
| 7 | +import * as SDK from '../../core/sdk/sdk.js'; |
| 8 | +import * as Bindings from '../../models/bindings/bindings.js'; |
| 9 | +import * as Breakpoints from '../../models/breakpoints/breakpoints.js'; |
| 10 | +import * as Persistence from '../../models/persistence/persistence.js'; |
| 11 | +import * as Workspace from '../../models/workspace/workspace.js'; |
| 12 | +import {describeWithEnvironment, registerNoopActions, updateHostConfig} from '../../testing/EnvironmentHelpers.js'; |
| 13 | +import * as UI from '../../ui/legacy/legacy.js'; |
| 14 | + |
| 15 | +import * as Sources from './sources.js'; |
| 16 | + |
| 17 | +describeWithEnvironment('SourcesPanel', () => { |
| 18 | + function setUpEnvironment() { |
| 19 | + const workspace = Workspace.Workspace.WorkspaceImpl.instance({forceNew: true}); |
| 20 | + const debuggerWorkspaceBinding = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance({ |
| 21 | + forceNew: true, |
| 22 | + targetManager: SDK.TargetManager.TargetManager.instance(), |
| 23 | + resourceMapping: |
| 24 | + new Bindings.ResourceMapping.ResourceMapping(SDK.TargetManager.TargetManager.instance(), workspace), |
| 25 | + ignoreListManager: Workspace.IgnoreListManager.IgnoreListManager.instance({forceNew: true}), |
| 26 | + }); |
| 27 | + const breakpointManager = Breakpoints.BreakpointManager.BreakpointManager.instance({ |
| 28 | + forceNew: true, |
| 29 | + targetManager: SDK.TargetManager.TargetManager.instance(), |
| 30 | + workspace, |
| 31 | + debuggerWorkspaceBinding, |
| 32 | + }); |
| 33 | + Persistence.Persistence.PersistenceImpl.instance({forceNew: true, workspace, breakpointManager}); |
| 34 | + const networkPersistenceManager = |
| 35 | + sinon.createStubInstance(Persistence.NetworkPersistenceManager.NetworkPersistenceManager); |
| 36 | + sinon.stub(Persistence.NetworkPersistenceManager.NetworkPersistenceManager, 'instance') |
| 37 | + .returns(networkPersistenceManager); |
| 38 | + sinon.stub(UI.ViewManager.ViewManager.instance(), 'view') |
| 39 | + .callsFake(() => sinon.createStubInstance(UI.View.SimpleView)); |
| 40 | + } |
| 41 | + |
| 42 | + function createStubUISourceCode() { |
| 43 | + const uiSourceCode = sinon.createStubInstance(Workspace.UISourceCode.UISourceCode); |
| 44 | + uiSourceCode.contentType.returns(Common.ResourceType.resourceTypes.Script); |
| 45 | + const stubProject = sinon.createStubInstance(Bindings.ContentProviderBasedProject.ContentProviderBasedProject); |
| 46 | + uiSourceCode.project.returns(stubProject); |
| 47 | + stubProject.isServiceProject.returns(true); |
| 48 | + return uiSourceCode; |
| 49 | + } |
| 50 | + |
| 51 | + it('Shows Debug with Ai menu and submenu items', () => { |
| 52 | + updateHostConfig({ |
| 53 | + devToolsAiSubmenuPrompts: { |
| 54 | + enabled: true, |
| 55 | + }, |
| 56 | + }); |
| 57 | + |
| 58 | + registerNoopActions([ |
| 59 | + 'debugger.toggle-pause', 'debugger.step-over', 'debugger.step-into', 'debugger.step-out', 'debugger.step', |
| 60 | + 'debugger.toggle-breakpoints-active' |
| 61 | + ]); |
| 62 | + UI.ActionRegistration.registerActionExtension({ |
| 63 | + actionId: 'drjones.sources-panel-context', |
| 64 | + title: () => 'Debug with AI' as Platform.UIString.LocalizedString, |
| 65 | + category: UI.ActionRegistration.ActionCategory.GLOBAL, |
| 66 | + }); |
| 67 | + const actionRegistryInstance = UI.ActionRegistry.ActionRegistry.instance({forceNew: true}); |
| 68 | + UI.ShortcutRegistry.ShortcutRegistry.instance({forceNew: true, actionRegistry: actionRegistryInstance}); |
| 69 | + |
| 70 | + setUpEnvironment(); |
| 71 | + |
| 72 | + const sources = new Sources.SourcesPanel.SourcesPanel(); |
| 73 | + |
| 74 | + const event = new Event('contextmenu'); |
| 75 | + sinon.stub(event, 'target').value(document); |
| 76 | + const contextMenu = new UI.ContextMenu.ContextMenu(event); |
| 77 | + |
| 78 | + const uiSourceCode = createStubUISourceCode(); |
| 79 | + sources.appendApplicableItems(event, contextMenu, uiSourceCode); |
| 80 | + |
| 81 | + const debugWithAiItem = contextMenu.buildDescriptor().subItems?.find(item => item.label === 'Debug with AI'); |
| 82 | + assert.exists(debugWithAiItem); |
| 83 | + assert.deepEqual( |
| 84 | + debugWithAiItem.subItems?.map(item => item.label), |
| 85 | + ['Start a chat', 'Assess performance', 'Explain this script', 'Explain input handling']); |
| 86 | + |
| 87 | + UI.ActionRegistry.ActionRegistry.reset(); |
| 88 | + UI.ShortcutRegistry.ShortcutRegistry.removeInstance(); |
| 89 | + }); |
| 90 | +}); |
0 commit comments