mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 01:07:01 +08:00
Fix keyboard throttler injection and unrestricted logging.
Bug: 1467464 Change-Id: I4927663fb4c9077957f7deb8686ee3c8b20b3bcc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4931036 Commit-Queue: Danil Somsikov <dsv@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org> Auto-Submit: Danil Somsikov <dsv@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org>
This commit is contained in:
committed by
Devtools-frontend LUCI CQ
parent
96ec5154fc
commit
98afcc975b
@@ -23,7 +23,7 @@ export async function startLogging(
|
||||
options?: {domProcessingThrottler?: Common.Throttler.Throttler, keyboardLogThrottler?: Common.Throttler.Throttler}):
|
||||
Promise<void> {
|
||||
domProcessingThrottler = options?.domProcessingThrottler || new Common.Throttler.Throttler(PROCESS_DOM_INTERVAL);
|
||||
keyboardLogThrottler = options?.domProcessingThrottler || new Common.Throttler.Throttler(KEYBOARD_LOG_INTERVAL);
|
||||
keyboardLogThrottler = options?.keyboardLogThrottler || new Common.Throttler.Throttler(KEYBOARD_LOG_INTERVAL);
|
||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||
await processDom();
|
||||
}
|
||||
@@ -71,9 +71,10 @@ async function processDom(): Promise<void> {
|
||||
if (loggingState.config.track?.has('change')) {
|
||||
element.addEventListener('change', logChange, {capture: true});
|
||||
}
|
||||
const trackKeyDown = loggingState.config.track?.get('keydown');
|
||||
const trackKeyDown = loggingState.config.track?.has('keydown');
|
||||
const codes = loggingState.config.track?.get('keydown')?.split(',') || [];
|
||||
if (trackKeyDown) {
|
||||
element.addEventListener('keydown', logKeyDown(trackKeyDown.split(','), keyboardLogThrottler), {capture: true});
|
||||
element.addEventListener('keydown', logKeyDown(codes, keyboardLogThrottler), {capture: true});
|
||||
}
|
||||
loggingState.processed = true;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('LoggingDriver', () => {
|
||||
parent.style.height = '300px';
|
||||
const element = document.createElement('div') as HTMLElement;
|
||||
element.id = 'element';
|
||||
element.setAttribute('jslog', 'TreeItem; context:42; track: click');
|
||||
element.setAttribute('jslog', 'TreeItem; context:42; track: click, keydown');
|
||||
element.style.width = '300px';
|
||||
element.style.height = '300px';
|
||||
parent.appendChild(element);
|
||||
@@ -140,4 +140,25 @@ describe('LoggingDriver', () => {
|
||||
|
||||
assert.isFalse(recordClick.called);
|
||||
});
|
||||
|
||||
it('logs keydown', async () => {
|
||||
const domProcessingThrottler = new Common.Throttler.Throttler(100000);
|
||||
const keyboardLogThrottler = new Common.Throttler.Throttler(100000);
|
||||
addLoggableElements();
|
||||
await VisualLogging.startLogging({domProcessingThrottler, keyboardLogThrottler});
|
||||
const recordKeyDown = sinon.stub(
|
||||
Host.InspectorFrontendHost.InspectorFrontendHostInstance,
|
||||
'recordKeyDown',
|
||||
);
|
||||
|
||||
const element = document.getElementById('element') as HTMLElement;
|
||||
element.dispatchEvent(new KeyboardEvent('keydown', {'key': 'a'}));
|
||||
element.dispatchEvent(new KeyboardEvent('keydown', {'key': 'b'}));
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
assert.exists(keyboardLogThrottler.process);
|
||||
assert.isFalse(recordKeyDown.called);
|
||||
|
||||
await keyboardLogThrottler.process?.();
|
||||
assert.isTrue(recordKeyDown.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user