Skip to content

Commit 3b641ed

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
Handle StreamingContentData updates in BinaryResourceViewFactory
This is the last piece of the puzzle: Update the ResourceSourceFrame views that the BinaryResourceViewFactory produces when the content updates. The "cleaner" approach would be to pass a custom "ContentProvider" to "ResourceSourceFrame" that spits out a wrapped "StreamingContentData" that applies the utf8/base64 transformation to the original "StreamingContentData". That is because the "ResourceSourceFrame" actually knows how to subscribe to "StreamingContentData" updates. This is a lot of boilerplate code though and not very readable, so the next best thing is this CL. [email protected] Fixed: 375546679 Change-Id: I982859fd255354ea8a73cc928bc34640ec78a87b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5993272 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Philip Pfaffe <[email protected]>
1 parent ee21558 commit 3b641ed

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as Common from '../../../../core/common/common.js';
66
import type * as Platform from '../../../../core/platform/platform.js';
77
import * as TextUtils from '../../../../models/text_utils/text_utils.js';
8+
import {raf} from '../../../../testing/DOMHelpers.js';
89
import {describeWithEnvironment} from '../../../../testing/EnvironmentHelpers.js';
910

1011
import * as SourceFrame from './source_frame.js';
@@ -44,4 +45,38 @@ describeWithEnvironment('BinaryResourceViewFactory', () => {
4445
'73656e64696e672074686973207574662d3820737472696e6720617320612062696e617279206d6573736167652e2e2e');
4546
assert.strictEqual(factory.utf8(), 'sending this utf-8 string as a binary message...');
4647
});
48+
49+
it('produces views for utf8/base64 that update when the StreamingContentData changes', async () => {
50+
const base64content = new TextUtils.ContentData.ContentData(
51+
'c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4u', true, '');
52+
const streamingContent = TextUtils.StreamingContentData.StreamingContentData.from(base64content);
53+
const factory = new SourceFrame.BinaryResourceViewFactory.BinaryResourceViewFactory(
54+
streamingContent, 'http://example.com' as Platform.DevToolsPath.UrlString,
55+
Common.ResourceType.resourceTypes.WebSocket);
56+
57+
const utf8View = factory.createUtf8View();
58+
utf8View.markAsRoot();
59+
utf8View.show(document.body);
60+
const base64View = factory.createBase64View();
61+
base64View.markAsRoot();
62+
base64View.show(document.body);
63+
64+
await raf();
65+
assert.strictEqual(utf8View.textEditor.state.doc.toString(), 'sending this utf-8 string as a binary message...');
66+
assert.strictEqual(
67+
base64View.textEditor.state.doc.toString(), 'c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4u');
68+
69+
streamingContent.addChunk(window.btoa('\nadded another line'));
70+
71+
await raf();
72+
assert.strictEqual(
73+
utf8View.textEditor.state.doc.toString(),
74+
'sending this utf-8 string as a binary message...\nadded another line');
75+
assert.strictEqual(
76+
base64View.textEditor.state.doc.toString(),
77+
'c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4uCmFkZGVkIGFub3RoZXIgbGluZQ==');
78+
79+
utf8View.detach();
80+
base64View.detach();
81+
});
4782
});

front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,29 @@ export class BinaryResourceViewFactory {
3737
}
3838

3939
createBase64View(): ResourceSourceFrame {
40-
return new ResourceSourceFrame(
40+
const resourceFrame = new ResourceSourceFrame(
4141
TextUtils.StaticContentProvider.StaticContentProvider.fromString(
4242
this.contentUrl, this.resourceType, this.streamingContent.content().base64),
4343
this.resourceType.canonicalMimeType(), {lineNumbers: false, lineWrapping: true});
44+
this.streamingContent.addEventListener(TextUtils.StreamingContentData.Events.CHUNK_ADDED, () => {
45+
void resourceFrame.setContent(this.base64());
46+
});
47+
return resourceFrame;
4448
}
4549

4650
createHexView(): StreamingContentHexView {
4751
return new StreamingContentHexView(this.streamingContent);
4852
}
4953

5054
createUtf8View(): ResourceSourceFrame {
51-
return new ResourceSourceFrame(
55+
const resourceFrame = new ResourceSourceFrame(
5256
TextUtils.StaticContentProvider.StaticContentProvider.fromString(
5357
this.contentUrl, this.resourceType, this.utf8()),
5458
this.resourceType.canonicalMimeType(), {lineNumbers: true, lineWrapping: true});
59+
this.streamingContent.addEventListener(TextUtils.StreamingContentData.Events.CHUNK_ADDED, () => {
60+
void resourceFrame.setContent(this.utf8());
61+
});
62+
return resourceFrame;
5563
}
5664

5765
static #uint8ArrayToHexString(uint8Array: Uint8Array): string {

0 commit comments

Comments
 (0)