mdn-bcd-collector icon indicating copy to clipboard operation
mdn-bcd-collector copied to clipboard

Cover global/window events

Open Elchi3 opened this issue 1 year ago • 1 comments

In https://github.com/openwebdocs/mdn-bcd-collector/pull/879 I re-enabled collecting compat data for events, but skipped those for global/window event handlers:

const skipIncludes = [
  "WindowOrWorkerGlobalScope", // handled separately as globals
  "GlobalEventHandlers", // XXX needs special handling
  "WindowEventHandlers", // XXX needs special handling
];

https://github.com/openwebdocs/mdn-bcd-collector/blob/9e556b0fdea227e5c9aa549e8bf4138dfe188fbd/test-builder/api.ts#L92C1-L96C9

To meet our coverage goal of 90% (see https://github.com/openwebdocs/project/issues/161), we want to sort our coverage of events (the work on events will add coverage of ~175 more data entries)

The GlobalEventHandlers and WindowEventHandlers mixins are mixed into a lot of interfaces and we don't want the collector to add these to all of them. So likely a mapping will be needed. BCD already does that, but the mapping isn't scripted anywhere so there might be bugs with it, too. Mapping it here in the collector will likely help to ensure consistency. Then there is also bubbling and that might not be handled consistently yet either, so maybe we need even more mappings.

I volunteered to implement this. Wish me luck :)

Elchi3 avatar Jan 26 '24 09:01 Elchi3

The way I would approach this is to start with a list of interfaces that don't get their own onfoo event handler properties because they are instead added to GlobalEventHandlers or WindowEventHandlers. That's Window, Document, HTML*Element, and perhaps some others.

If BCD has a foo_event key for one of those interfaces and there's an onfoo attribute in Web IDL for the same interface, then we should generate a test that simply checks for onfoo on the prototype or an instance.

Using api.HTMLMediaElement.volumechange_event as an example, we should note that HTMLMediaElement is a special interface, confirm that onvolumechange is in the GlobalEventHandlers mixins, and proceed to generate this test:

(function () {
  var instance = document.createElement("video");
  return !!instance && "onvolumechange" in instance;
})();

foolip avatar Feb 13 '24 10:02 foolip