11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<title>Default passive event listeners on window, document, document element, body</title> 31cb0ef41Sopenharmony_ci<link rel="help" href="https://dom.spec.whatwg.org/#default-passive-value"> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci<body> 71cb0ef41Sopenharmony_ci <div id="div"></div> 81cb0ef41Sopenharmony_ci<script> 91cb0ef41Sopenharmony_ci function isListenerPassive(eventName, eventTarget, passive, expectPassive) { 101cb0ef41Sopenharmony_ci test(() => { 111cb0ef41Sopenharmony_ci let defaultPrevented = null; 121cb0ef41Sopenharmony_ci let handler = event => { 131cb0ef41Sopenharmony_ci event.preventDefault(); 141cb0ef41Sopenharmony_ci defaultPrevented = event.defaultPrevented; 151cb0ef41Sopenharmony_ci eventTarget.removeEventListener(eventName, handler); 161cb0ef41Sopenharmony_ci }; 171cb0ef41Sopenharmony_ci if (passive === 'omitted') { 181cb0ef41Sopenharmony_ci eventTarget.addEventListener(eventName, handler); 191cb0ef41Sopenharmony_ci } else { 201cb0ef41Sopenharmony_ci eventTarget.addEventListener(eventName, handler, {passive}); 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci let dispatchEventReturnValue = eventTarget.dispatchEvent(new Event(eventName, {cancelable: true})); 231cb0ef41Sopenharmony_ci assert_equals(defaultPrevented, !expectPassive, 'defaultPrevented'); 241cb0ef41Sopenharmony_ci assert_equals(dispatchEventReturnValue, expectPassive, 'dispatchEvent() return value'); 251cb0ef41Sopenharmony_ci }, `${eventName} listener is ${expectPassive ? '' : 'non-'}passive ${passive === 'omitted' ? 'by default' : `with {passive:${passive}}`} for ${eventTarget.constructor.name}`); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci const eventNames = { 291cb0ef41Sopenharmony_ci touchstart: true, 301cb0ef41Sopenharmony_ci touchmove: true, 311cb0ef41Sopenharmony_ci wheel: true, 321cb0ef41Sopenharmony_ci mousewheel: true, 331cb0ef41Sopenharmony_ci touchend: false 341cb0ef41Sopenharmony_ci }; 351cb0ef41Sopenharmony_ci const passiveEventTargets = [window, document, document.documentElement, document.body]; 361cb0ef41Sopenharmony_ci const div = document.getElementById('div'); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci for (const eventName in eventNames) { 391cb0ef41Sopenharmony_ci for (const eventTarget of passiveEventTargets) { 401cb0ef41Sopenharmony_ci isListenerPassive(eventName, eventTarget, 'omitted', eventNames[eventName]); 411cb0ef41Sopenharmony_ci isListenerPassive(eventName, eventTarget, undefined, eventNames[eventName]); 421cb0ef41Sopenharmony_ci isListenerPassive(eventName, eventTarget, false, false); 431cb0ef41Sopenharmony_ci isListenerPassive(eventName, eventTarget, true, true); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci isListenerPassive(eventName, div, 'omitted', false); 461cb0ef41Sopenharmony_ci isListenerPassive(eventName, div, undefined, false); 471cb0ef41Sopenharmony_ci isListenerPassive(eventName, div, false, false); 481cb0ef41Sopenharmony_ci isListenerPassive(eventName, div, true, true); 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci</script> 51