Skip to content

Bring event host tests to WheelEvent-level coverage#1118

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/add-test-methods-for-event-classes
Draft

Bring event host tests to WheelEvent-level coverage#1118
Copilot wants to merge 3 commits into
masterfrom
copilot/add-test-methods-for-event-classes

Conversation

Copy link
Copy Markdown

Copilot AI commented May 12, 2026

This PR raises event host coverage in org.htmlunit.javascript.host.event to the same constructor/createEvent/in-window detail level used by WheelEventTest. It fills the missing standard test matrix across existing event tests and adds coverage for event classes that previously had no dedicated test file.

  • Expand existing event tests

    • Added missing standard methods to the targeted existing suites, including:
      • constructor variants: no-arg, numeric, null, unknown symbol, arbitrary type
      • full init-dict and empty init-dict cases
      • document.createEvent(...)
      • 'EventName' in window
    • Preserved all existing specialized tests and behavior-specific coverage.
    • Updated per-browser alerts for restricted classes (Chrome/Edge-only and Firefox-only hosts).
  • Normalize event dumps

    • Aligned dump helpers with the WheelEventTest pattern:
      • base fields: type, bubbles, cancelable, composed
      • event-specific getters where exposed by the host class
    • Extended dumps for classes such as:
      • PopStateEventstate
      • CloseEventcode, reason, wasClean
      • HashChangeEventoldURL, newURL
      • PointerEvent → pointer-specific fields including persistentDeviceId
      • UIEventdetail, view, which
  • Add missing test classes

    • Added new test coverage for previously untested event hosts, including:
      • ClipboardEventTest
      • IDBVersionChangeEventTest
      • MIDIConnectionEventTest
      • MIDIMessageEventTest
      • MediaEncryptedEventTest
      • MediaKeyMessageEventTest
      • MediaQueryListEventTest
      • MediaStreamEventTest
      • MediaStreamTrackEventTest
      • MouseScrollEventTest
      • PromiseRejectionEventTest
      • RTCDataChannelEventTest
      • RTCPeerConnectionIceEventTest
      • SecurityPolicyViolationEventTest
      • SpeechSynthesisEventTest
  • Keep browser support explicit

    • Encoded support boundaries directly in alerts using the existing convention:
      • unrestricted hosts → all browsers
      • @JsxClass({CHROME, EDGE}) → default ReferenceError for Firefox
      • @JsxClass({FF, FF_ESR}) → default ReferenceError for Chromium

Example of the standardized shape now used across event tests:

@Test
@Alerts({"[object PopStateEvent]", "popstate", "false", "false", "false", "null"})
public void create_ctor() throws Exception {
    final String html = DOCTYPE_HTML
        + "<html><head><script>\n"
        + LOG_TITLE_FUNCTION
        + "  function test() {\n"
        + "    try {\n"
        + "      var event = new PopStateEvent('popstate');\n"
        + "      dump(event);\n"
        + "    } catch(e) { logEx(e) }\n"
        + "  }\n"
        + DUMP_EVENT_FUNCTION
        + "</script></head><body onload='test()'>\n"
        + "</body></html>";

    loadPageVerifyTitle2(html);
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • central.sonatype.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/htmlunit/htmlunit org.codehaus.plexus.classworlds.launcher.Launcher -Dtest=WheelEventTest,PopStateEventTest,WebGLContextEventTest test (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/htmlunit/htmlunit org.codehaus.plexus.classworlds.launcher.Launcher -Dtest=PopStateEventTest,UIEventTest,PointerEventTest,ClipboardEventTest,MouseScrollEventTest test grep crip�� g/htmlunit/javascript/host/event/UIEvent.java git /PointerEvent.java d &#34; &#34;$f&#34; | sed &#34;getopt --global java grep (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Goal

Every test class in src/test/java/org/htmlunit/javascript/host/event/ must reach the same detail level as WheelEventTest — the reference implementation.


The Standard Test Pattern

Study WheelEventTest carefully — it is the reference. Every event test class must contain (at minimum) these 10 test methods, adapted for the specific event class:

private static final String DUMP_EVENT_FUNCTION = "  function dump(event) {\n"
    + "    if (event) {\n"
    + "      log(event);\n"
    + "      log(event.type);\n"
    + "      log(event.bubbles);\n"
    + "      log(event.cancelable);\n"
    + "      log(event.composed);\n"
    // add event-class-specific properties here if any exist (like deltaX, deltaY for WheelEvent)
    + "    } else {\n"
    + "      log('no event');\n"
    + "    }\n"
    + "  }\n";

Required test methods (adapt alerts per browser support):

  1. create_ctornew EventName('type'), dump event
  2. create_ctorWithoutTypenew EventName() with no args → TypeError (use @HtmlUnitNYI if HtmlUnit doesn't throw)
  3. create_ctorNumericTypenew EventName(42) → works, logs 42 as type
  4. create_ctorNullTypenew EventName(null) → works, logs null as type
  5. create_ctorUnknownTypenew EventName(unknown)ReferenceError
  6. create_ctorArbitraryTypenew EventName('HtmlUnitEvent') → works
  7. create_ctorAllDetails — full init dict with event-specific fields (bubbles, cancelable, composed, plus any event-class fields)
  8. create_ctorAllDetailsMissingData — empty init dict {}
  9. create_createEventdocument.createEvent('EventName')NotSupportedError/DOMException
  10. inWindow'EventName' in windowtrue or false depending on browser support

Browser-restriction rules:

  • If @JsxClass has no browser restriction → all browsers supported → @Alerts("true") for inWindow, no per-browser @Alerts splits needed for constructors
  • If @JsxClass({CHROME, EDGE})DEFAULT = "ReferenceError" (FF/FF_ESR), specific Chrome/Edge alerts
  • If @JsxClass({FF, FF_ESR})DEFAULT = "ReferenceError" (Chrome/Edge), specific FF alerts

Work Items

A. Fix PopStateEventTest (existing file needs enhancement)

The existing file has create_ctor, create_ctorWithDetails, create_createEvent, setState, dispatchEvent, dispatchEventWithoutInit, initPopStateEvent. Keep all existing tests. Add the missing standard tests:

  • create_ctorWithoutTypeTypeError (all browsers, @HtmlUnitNYI if needed)
  • create_ctorNumericType
  • create_ctorNullType
  • create_ctorUnknownType
  • create_ctorArbitraryType
  • create_ctorAllDetailsMissingDatanew PopStateEvent('popstate', {})
  • inWindow@Alerts("true")

The DUMP_EVENT_FUNCTION for PopStateEvent logs: event, event.type, event.bubbles, event.cancelable, event.composed, event.state.

B. Enhance existing test files that lack standard tests

For each file below, read the current content and the corresponding main source class, then add all missing standard test methods. Keep all existing tests. Also add/update the DUMP_EVENT_FUNCTION if it doesn't log the standard 5 base properties yet, and add event-class-specific properties to the dump if the main source exposes them via @JsxGetter.

Files to enhance (read each to see what's currently missing):

  • AudioProcessingEventTest — main: AudioProcessingEvent.java (check browser restrictions and any getters)
  • BeforeInstallPromptEventTest — main: BeforeInstallPromptEvent.java
  • BeforeUnloadEventTest — main: BeforeUnloadEvent.java
  • BlobEventTest — main: BlobEvent.java
  • CloseEventTest — main: CloseEvent.java (has code, reason, wasClean getters — include in dump and create_ctorAllDetails)
  • CompositionEventTest — main: CompositionEvent.java
  • CustomEventTest — main: CustomEvent.java (has detail getter)
  • DeviceMotionEventTest — main: DeviceMotionEvent.java
  • DeviceOrientationEventTest — main: DeviceOrientationEvent.java
  • DragEventTest — main: DragEvent.java
  • ErrorEventTest — main: ErrorEvent.java (has message, filename, lineno, colno, error getters)
  • FocusEventTest — main: FocusEvent.java
  • GamepadEventTest — main: GamepadEvent.java
  • HashChangeEventTest — main: HashChangeEvent.java (has oldURL, newURL getters)
  • InputEventTest — main: InputEvent.java
  • OfflineAudioCompletionEventTest — main: OfflineAudioCompletionEvent.java
  • PageTransitionEventTest — main: PageTransitionEvent.java (has persisted getter)
  • PointerEventTest — main: PointerEvent.java
  • StorageEventTest — main: StorageEvent.java
  • SubmitEventTest — main: SubmitEvent.java
  • TextEventTest — main: TextEvent.java
  • TimeEventTest — main: TimeEvent.java
  • TouchEventTest — main: TouchEvent.java
  • TrackEventTest — main: TrackEvent.java
  • TransitionEventTest — main: TransitionEvent.java
  • `UIEvent...

This pull request was created from Copilot chat.

Copilot AI and others added 2 commits May 12, 2026 16:12
Copilot AI changed the title [WIP] Add test methods for event classes based on WheelEventTest Bring event host tests to WheelEvent-level coverage May 12, 2026
Copilot AI requested a review from rbri May 12, 2026 16:16
Copilot finished work on behalf of rbri May 12, 2026 16:16
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants