Skip to content

Commit 3570053

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
Remove custom events from RecordingView
Fixed: 407941153 Change-Id: I83ab53130cd7f63ca7eb4e474c90d30b9bbe86e9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6696355 Reviewed-by: Nikolay Vitkov <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 73ae0fc commit 3570053

File tree

3 files changed

+122
-199
lines changed

3 files changed

+122
-199
lines changed

front_end/panels/recorder/RecorderController.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,11 @@ export class RecorderController extends LitElement {
477477
if (this.viewDescriptor) {
478478
this.viewDescriptor = undefined;
479479
}
480-
if (event.data.extension) {
481-
return await this.#onPlayViaExtension(event.data.extension);
480+
if (event.extension) {
481+
return await this.#onPlayViaExtension(event.extension);
482482
}
483483
Host.userMetrics.recordingReplayStarted(
484-
event.data.targetPanel !== Components.RecordingView.TargetPanel.DEFAULT ?
484+
event.targetPanel !== Components.RecordingView.TargetPanel.DEFAULT ?
485485
Host.UserMetrics.RecordingReplayStarted.REPLAY_WITH_PERFORMANCE_TRACING :
486486
Host.UserMetrics.RecordingReplayStarted.REPLAY_ONLY);
487487
this.#replayState.isPlaying = true;
@@ -494,9 +494,9 @@ export class RecorderController extends LitElement {
494494
await this.#disableDeviceModeIfEnabled();
495495

496496
this.recordingPlayer = new Models.RecordingPlayer.RecordingPlayer(
497-
this.currentRecording.flow, {speed: event.data.speed, breakpointIndexes: this.#stepBreakpointIndexes});
497+
this.currentRecording.flow, {speed: event.speed, breakpointIndexes: this.#stepBreakpointIndexes});
498498

499-
const withPerformanceTrace = event.data.targetPanel === Components.RecordingView.TargetPanel.PERFORMANCE_PANEL;
499+
const withPerformanceTrace = event.targetPanel === Components.RecordingView.TargetPanel.PERFORMANCE_PANEL;
500500
const sectionsWithScreenshot = new Set();
501501
this.recordingPlayer.addEventListener(Models.RecordingPlayer.Events.STEP, async ({data: {step, resolve}}) => {
502502
this.currentStep = step;
@@ -565,7 +565,7 @@ export class RecorderController extends LitElement {
565565
});
566566

567567
let performanceTracing = null;
568-
switch (event.data?.targetPanel) {
568+
switch (event.targetPanel) {
569569
case Components.RecordingView.TargetPanel.PERFORMANCE_PANEL:
570570
performanceTracing = new Tracing.PerformanceTracing.PerformanceTracing(this.#getMainTarget(), {
571571
tracingBufferUsage(): void{},
@@ -590,8 +590,8 @@ export class RecorderController extends LitElement {
590590
const events = await eventsPromise;
591591
this.#replayState.isPlaying = false;
592592
this.recordingPlayer = undefined;
593-
await UI.InspectorView.InspectorView.instance().showPanel(event.data?.targetPanel as string);
594-
if (event.data?.targetPanel === Components.RecordingView.TargetPanel.PERFORMANCE_PANEL) {
593+
await UI.InspectorView.InspectorView.instance().showPanel(event.targetPanel as string);
594+
if (event.targetPanel === Components.RecordingView.TargetPanel.PERFORMANCE_PANEL) {
595595
// Note: this is not passing any metadata to the Performance panel.
596596
const trace = new SDK.TraceObject.TraceObject(events as Trace.Types.Events.Event[]);
597597
void Common.Revealer.reveal(trace);
@@ -700,12 +700,12 @@ export class RecorderController extends LitElement {
700700
{keepBreakpoints: true, updateSession: true});
701701
}
702702

703-
async #handleRecordingTitleChanged(event: Components.RecordingView.RecordingTitleChangedEvent): Promise<void> {
703+
async #handleRecordingTitleChanged(title: string): Promise<void> {
704704
if (!this.currentRecording) {
705705
throw new Error('Current recording expected to be defined.');
706706
}
707707

708-
const flow = {...this.currentRecording.flow, title: event.title};
708+
const flow = {...this.currentRecording.flow, title};
709709
this.#setCurrentRecording(await this.#storage.updateRecording(this.currentRecording.storageName, flow));
710710
}
711711

@@ -737,7 +737,7 @@ export class RecorderController extends LitElement {
737737
{keepBreakpoints: true, updateSession: true});
738738
}
739739

740-
async #onNetworkConditionsChanged(event: Components.RecordingView.NetworkConditionsChanged): Promise<void> {
740+
async #onNetworkConditionsChanged(data?: SDK.NetworkManager.Conditions): Promise<void> {
741741
if (!this.currentRecording) {
742742
throw new Error('Current recording expected to be defined.');
743743
}
@@ -751,7 +751,7 @@ export class RecorderController extends LitElement {
751751
}
752752
return step.type === 'emulateNetworkConditions';
753753
});
754-
if (!event.data) {
754+
if (!data) {
755755
// Delete step if present.
756756
if (emulateNetworkConditionsIdx !== -1) {
757757
this.currentRecording.flow.steps.splice(emulateNetworkConditionsIdx, 1);
@@ -761,24 +761,24 @@ export class RecorderController extends LitElement {
761761
this.currentRecording.flow.steps.splice(
762762
0, 0,
763763
Models.SchemaUtils.createEmulateNetworkConditionsStep(
764-
{download: event.data.download, upload: event.data.upload, latency: event.data.latency}));
764+
{download: data.download, upload: data.upload, latency: data.latency}));
765765
} else {
766766
// Update existing step.
767767
const step =
768768
this.currentRecording.flow.steps[emulateNetworkConditionsIdx] as Models.Schema.EmulateNetworkConditionsStep;
769-
step.download = event.data.download;
770-
step.upload = event.data.upload;
771-
step.latency = event.data.latency;
769+
step.download = data.download;
770+
step.upload = data.upload;
771+
step.latency = data.latency;
772772
}
773773
this.#setCurrentRecording(
774774
await this.#storage.updateRecording(this.currentRecording.storageName, this.currentRecording.flow));
775775
}
776776

777-
async #onTimeoutChanged(event: Components.RecordingView.TimeoutChanged): Promise<void> {
777+
async #onTimeoutChanged(timeout?: number): Promise<void> {
778778
if (!this.currentRecording) {
779779
throw new Error('Current recording expected to be defined.');
780780
}
781-
this.currentRecording.flow.timeout = event.data;
781+
this.currentRecording.flow.timeout = timeout;
782782
this.#setCurrentRecording(
783783
await this.#storage.updateRecording(this.currentRecording.storageName, this.currentRecording.flow));
784784
}
@@ -1033,8 +1033,8 @@ export class RecorderController extends LitElement {
10331033

10341034
async #onPlayRecordingByName(event: Components.RecordingListView.PlayRecordingEvent): Promise<void> {
10351035
await this.#onRecordingSelected(event);
1036-
await this.#onPlayRecording(new Components.RecordingView.PlayRecordingEvent(
1037-
{targetPanel: Components.RecordingView.TargetPanel.DEFAULT, speed: this.#recorderSettings.speed}));
1036+
await this.#onPlayRecording(
1037+
{targetPanel: Components.RecordingView.TargetPanel.DEFAULT, speed: this.#recorderSettings.speed});
10381038
}
10391039

10401040
#onAddBreakpoint = (event: AddBreakpointEvent): void => {
@@ -1083,8 +1083,8 @@ export class RecorderController extends LitElement {
10831083
return;
10841084

10851085
case Actions.RecorderActions.REPLAY_RECORDING:
1086-
void this.#onPlayRecording(new Components.RecordingView.PlayRecordingEvent(
1087-
{targetPanel: Components.RecordingView.TargetPanel.DEFAULT, speed: this.#recorderSettings.speed}));
1086+
void this.#onPlayRecording(
1087+
{targetPanel: Components.RecordingView.TargetPanel.DEFAULT, speed: this.#recorderSettings.speed});
10881088
return;
10891089

10901090
case Actions.RecorderActions.TOGGLE_CODE_VIEW: {
@@ -1210,25 +1210,25 @@ export class RecorderController extends LitElement {
12101210
extensionConverters: this.extensionConverters,
12111211
replayExtensions: this.replayExtensions,
12121212
extensionDescriptor: this.viewDescriptor,
1213+
recordingFinished: this.#onRecordingFinished.bind(this),
1214+
addAssertion: this.#handleAddAssertionEvent.bind(this),
1215+
abortReplay: this.#onAbortReplay.bind(this),
1216+
playRecording: this.#onPlayRecording.bind(this),
1217+
networkConditionsChanged: this.#onNetworkConditionsChanged.bind(this),
1218+
timeoutChanged: this.#onTimeoutChanged.bind(this),
1219+
titleChanged: this.#handleRecordingTitleChanged.bind(this),
12131220
})}
1214-
@networkconditionschanged=${this.#onNetworkConditionsChanged}
1215-
@timeoutchanged=${this.#onTimeoutChanged}
12161221
@requestselectorattribute=${(
12171222
event: Controllers.SelectorPicker.RequestSelectorAttributeEvent,
12181223
) => {
12191224
event.send(this.currentRecording?.flow.selectorAttribute);
12201225
}}
1221-
@recordingfinished=${this.#onRecordingFinished}
12221226
@stepchanged=${this.#handleRecordingChanged.bind(this)}
1223-
@recordingtitlechanged=${this.#handleRecordingTitleChanged.bind(this)}
12241227
@addstep=${this.#handleStepAdded.bind(this)}
12251228
@removestep=${this.#handleStepRemoved.bind(this)}
12261229
@addbreakpoint=${this.#onAddBreakpoint.bind(this)}
12271230
@removebreakpoint=${this.#onRemoveBreakpoint.bind(this)}
1228-
@playrecording=${this.#onPlayRecording.bind(this)}
1229-
@abortreplay=${this.#onAbortReplay.bind(this)}
12301231
@recorderextensionviewclosed=${this.#onExtensionViewClosed.bind(this)}
1231-
@addassertion=${this.#handleAddAssertionEvent.bind(this)}
12321232
${UI.Widget.widgetRef(Components.RecordingView.RecordingView, widget => {this.#recordingView = widget;})}
12331233
></devtools-widget>
12341234
`;

front_end/panels/recorder/components/RecordingView.test.ts

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ describeWithEnvironment('RecordingView', () => {
7272
ranges: [{anchor: 0, head: 0}],
7373
main: 0,
7474
});
75-
76-
// FIXME(b/407941153): needs to be updated once we do not rely on events.
75+
// FIXME(b/407941153): TextEditor needs to be updated to render declaratively.
7776
// view.input.onStepHover();
7877
// assert.deepEqual(input.editorState?.selection.toJSON(), {
7978
// ranges: [{anchor: 34, head: 68}],
@@ -113,54 +112,53 @@ describeWithEnvironment('RecordingView', () => {
113112
assert.strictEqual(JSON.stringify(userFlow, null, 2) + '\n', text);
114113
});
115114

116-
it('should copy a step to clipboard via copy event',
117-
async () => {
118-
// FIXME(b/407941153): uncomment this test when migrating away from events.
119-
120-
// const [view] = await createView();
121-
// view.input.onStepClick();
122-
123-
// const clipboardData = new DataTransfer();
124-
// const isCalled = sinon.promise();
125-
// const copyText = sinon
126-
// .stub(
127-
// Host.InspectorFrontendHost.InspectorFrontendHostInstance,
128-
// 'copyText',
129-
// )
130-
// .callsFake(() => {
131-
// void isCalled.resolve(true);
132-
// });
133-
// const event = new ClipboardEvent('copy', {clipboardData, bubbles: true});
134-
135-
// document.body.dispatchEvent(event);
136-
137-
// await isCalled;
138-
139-
// sinon.assert.calledWith(copyText, JSON.stringify(step, null, 2) + '\n');
140-
});
141-
142-
it('should copy a step to clipboard via custom event',
143-
async () => {
144-
// FIXME(b/407941153): uncomment this test when migrating away from events.
145-
146-
// const [view] = await createView();
147-
// const isCalled = sinon.promise();
148-
// const copyText = sinon
149-
// .stub(
150-
// Host.InspectorFrontendHost.InspectorFrontendHostInstance,
151-
// 'copyText',
152-
// )
153-
// .callsFake(() => {
154-
// void isCalled.resolve(true);
155-
// });
156-
// const event = new Components.StepView.CopyStepEvent(step);
157-
158-
// dispatchOnStep(view, event);
159-
160-
// await isCalled;
161-
162-
// sinon.assert.calledWith(copyText, JSON.stringify(step, null, 2) + '\n');
163-
});
115+
it('should copy a step to clipboard via copy event', async () => {
116+
const [view] = await createView();
117+
view.input.onStepClick({
118+
target: {
119+
step,
120+
},
121+
stopPropagation: sinon.stub(),
122+
} as unknown as MouseEvent);
123+
124+
const clipboardData = new DataTransfer();
125+
const isCalled = sinon.promise();
126+
const copyText = sinon
127+
.stub(
128+
Host.InspectorFrontendHost.InspectorFrontendHostInstance,
129+
'copyText',
130+
)
131+
.callsFake(() => {
132+
void isCalled.resolve(true);
133+
});
134+
const event = new ClipboardEvent('copy', {clipboardData, bubbles: true});
135+
136+
document.body.dispatchEvent(event);
137+
138+
await isCalled;
139+
140+
sinon.assert.calledWith(copyText, JSON.stringify(step, null, 2) + '\n');
141+
});
142+
143+
it('should copy a step to clipboard via custom event', async () => {
144+
const [view] = await createView();
145+
const isCalled = sinon.promise();
146+
const copyText = sinon
147+
.stub(
148+
Host.InspectorFrontendHost.InspectorFrontendHostInstance,
149+
'copyText',
150+
)
151+
.callsFake(() => {
152+
void isCalled.resolve(true);
153+
});
154+
const event = new Components.StepView.CopyStepEvent(step);
155+
156+
view.input.onCopyStep(event);
157+
158+
await isCalled;
159+
160+
sinon.assert.calledWith(copyText, JSON.stringify(step, null, 2) + '\n');
161+
});
164162

165163
it('should show code and change preferred copy method', async () => {
166164
const [view] = await createView();

0 commit comments

Comments
 (0)