Files
tubestation/testing/web-platform/tests/screen-capture/capture-controller-event-target.https.window.js
Frédéric Wang ec454a1e68 Bug 1833590 [wpt PR 40052] - Make CaptureController inherit from EventTarget, a=testonly
Automatic update from web-platform-tests
Make CaptureController inherit from EventTarget

This CL makes CaptureController inherit from EventTarget as agreed in
[1] in order to be able to register listeners for
CapturedMouseEvents [2]. This change is web-exposed and cannot be
disabled by a runtime flag, so an intent-to-ship was sent [3]. It is
covered by the following web platform tests:

screen-capture/idlharness.https.window.js
screen-capture/capture-controller-event-target.https.window.js

Low-Coverage-Reason: Trace/InterfaceName not covered similarly to other EventTargets (InterfaceName called once for Window/WorkerGlobalScope, twice for debug logging and once with long callback [4]).

[1] https://github.com/w3c/mediacapture-screen-share/issues/268
[2] https://groups.google.com/a/chromium.org/g/blink-dev/c/DYb5fXICJvo
[3] https://groups.google.com/a/chromium.org/g/blink-dev/c/sDm7-oOmlPY
[4] scripts.name in https://github.com/w3c/longtasks/blob/main/loaf-explainer.md#how-a-loaf-entry-might-look-like

Bug: 1444712
Change-Id: I32caa53a0f70825b09ab5c9e3aeb4cab847640d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4542243
Reviewed-by: Elad Alon <eladalon@chromium.org>
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Frédéric Wang <fwang@igalia.com>
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1164348}

--

wpt-commits: e276b9ab6f1a33f88c2ee5619bb13e060246046c
wpt-pr: 40052
2023-07-12 07:53:46 +00:00

61 lines
1.8 KiB
JavaScript

'use strict';
const controller = new CaptureController();
const type = 'my-event-type';
const listeners = {};
const listener_count = 10;
for (let i = 0; i < listener_count; i++) {
listeners[i] = {
callback: (event) => {
assert_equals(event.type, type, `Event type sent to listener ${i}`);
listeners[i].execution_count++;
}
};
}
test(() => {
for (const i in listeners) {
listeners[i].execution_count = 0;
controller.addEventListener(type, listeners[i].callback);
}
controller.dispatchEvent(new Event(type));
for (const i in listeners) {
assert_equals(
listeners[i].execution_count, 1,
`Callback execution count for listener ${i}`);
}
}, 'Registering listeners on CaptureController and dispatching an event.');
test(() => {
for (const i in listeners) {
listeners[i].execution_count = 0;
}
controller.dispatchEvent(new Event(type));
controller.dispatchEvent(new Event(type));
controller.dispatchEvent(new Event(type));
for (const i in listeners) {
assert_equals(
listeners[i].execution_count, 3,
`Callback execution count for listener ${i}`);
}
}, 'Dispatching an multiple events to CaptureController.');
test(() => {
for (const i in listeners) {
listeners[i].execution_count = 0;
if (i % 3) {
listeners[i].removed = false;
} else {
listeners[i].removed = true;
controller.removeEventListener(type, listeners[i].callback);
};
}
controller.dispatchEvent(new Event(type));
controller.dispatchEvent(new Event(type));
for (const i in listeners) {
assert_equals(
listeners[i].execution_count, listeners[i].removed ? 0 : 2,
`Callback execution count for listener ${i}`);
}
}, 'Unregistering listeners from CaptureController and dispatching an event.');