forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathAutomaticFileSystemManager.test.ts
More file actions
156 lines (131 loc) · 7.35 KB
/
Copy pathAutomaticFileSystemManager.test.ts
File metadata and controls
156 lines (131 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright 2025 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Host from '../../core/host/host.js';
import * as ProjectSettings from '../project_settings/project_settings.js';
import * as Persistence from './persistence.js';
describe('AutomaticFileSystemManager', () => {
const AUTOMATIC_FILE_SYSTEM_CHANGED = Persistence.AutomaticFileSystemManager.Events.AUTOMATIC_FILE_SYSTEM_CHANGED;
const {AutomaticFileSystemManager} = Persistence.AutomaticFileSystemManager;
const root = '/path/to/bar';
const uuid = '549bbf9b-48b2-4af7-aebd-d3ba68993094';
const hostConfig = {devToolsAutomaticFileSystems: {enabled: true}};
afterEach(() => {
AutomaticFileSystemManager.removeInstance();
});
it('initially doesn\'t report an automatic file system', () => {
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
sinon.stub(projectSettingsModel, 'projectSettings').value({});
const manager = AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
assert.isNull(manager.automaticFileSystem);
});
it('doesn\'t listen to project settings changes when `devToolsAutomaticFileSystems` is off', () => {
const hostConfig = {devToolsAutomaticFileSystems: {enabled: false}};
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
assert(projectSettingsModel.addEventListener.notCalled);
});
it('attempts to automatically connect the file system initially', () => {
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
sinon.stub(projectSettingsModel, 'projectSettings').value({workspace: {root, uuid}});
const manager = AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
assert.deepEqual(manager.automaticFileSystem, {root, uuid, state: 'connecting'});
assert(inspectorFrontendHost.connectAutomaticFileSystem.calledOnceWith(root, uuid, false));
});
it('reflects state correctly when automatic connection succeeds', async () => {
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
sinon.stub(projectSettingsModel, 'projectSettings').value({workspace: {root, uuid}});
const manager = AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
const [, , , setupCallback] = inspectorFrontendHost.connectAutomaticFileSystem.lastCall.args;
setupCallback({success: true});
const automaticFileSystem = await manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
assert.strictEqual(automaticFileSystem, manager.automaticFileSystem);
assert.deepEqual(automaticFileSystem, {root, uuid, state: 'connected'});
});
it('reflects state correctly when automatic connection fails', async () => {
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
sinon.stub(projectSettingsModel, 'projectSettings').value({workspace: {root, uuid}});
const manager = AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
const [, , , setupCallback] = inspectorFrontendHost.connectAutomaticFileSystem.lastCall.args;
setupCallback({success: false});
const automaticFileSystem = await manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
assert.strictEqual(automaticFileSystem, manager.automaticFileSystem);
assert.deepEqual(automaticFileSystem, {root, uuid, state: 'disconnected'});
});
it('performs first-time setup of automatic file system correctly', async () => {
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
sinon.stub(projectSettingsModel, 'projectSettings').value({workspace: {root, uuid}});
const manager = AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
const [, , , setupCallback] = inspectorFrontendHost.connectAutomaticFileSystem.lastCall.args;
setupCallback({success: false});
await manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
inspectorFrontendHost.connectAutomaticFileSystem.reset();
const connectingPromise = manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
const successPromise = manager.connectAutomaticFileSystem(/* addIfMissing= */ true);
assert.strictEqual(manager.automaticFileSystem, await connectingPromise);
assert.deepEqual(manager.automaticFileSystem, {root, uuid, state: 'connecting'});
const connectedPromise = manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
const [, , , connectCallback] = inspectorFrontendHost.connectAutomaticFileSystem.lastCall.args;
connectCallback({success: true});
const [success, automaticFileSystem] = await Promise.all([successPromise, connectedPromise]);
assert.isTrue(success);
assert.strictEqual(manager.automaticFileSystem, automaticFileSystem);
assert.deepEqual(manager.automaticFileSystem, {root, uuid, state: 'connected'});
});
it('correctly disconnects automatic file systems', async () => {
const inspectorFrontendHost = sinon.createStubInstance(Host.InspectorFrontendHost.InspectorFrontendHostStub);
const projectSettingsModel = sinon.createStubInstance(ProjectSettings.ProjectSettingsModel.ProjectSettingsModel);
sinon.stub(projectSettingsModel, 'projectSettings').value({workspace: {root, uuid}});
const manager = AutomaticFileSystemManager.instance({
forceNew: true,
hostConfig,
inspectorFrontendHost,
projectSettingsModel,
});
const [, , , setupCallback] = inspectorFrontendHost.connectAutomaticFileSystem.lastCall.args;
setupCallback({success: true});
await manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
const automaticFileSystemPromise = manager.once(AUTOMATIC_FILE_SYSTEM_CHANGED);
manager.disconnectedAutomaticFileSystem();
const automaticFileSystem = await automaticFileSystemPromise;
assert(inspectorFrontendHost.disconnectAutomaticFileSystem.calledOnceWith(root));
assert.strictEqual(manager.automaticFileSystem, automaticFileSystem);
assert.deepEqual(manager.automaticFileSystem, {root, uuid, state: 'disconnected'});
});
});