first-input-interactionid-key.html (2388B)
1 <!DOCTYPE html> 2 <html> 3 <meta charset=utf-8 /> 4 <title>First Input: interactionId-key.</title> 5 <input id='input'></input> 6 <textarea id='textarea'></textarea> 7 <script src=/resources/testharness.js></script> 8 <script src=/resources/testharnessreport.js></script> 9 <script src=/resources/testdriver.js></script> 10 <script src=/resources/testdriver-vendor.js></script> 11 <script src=/resources/testdriver-actions.js></script> 12 <script src=resources/event-timing-test-utils.js></script> 13 14 <script> 15 const key = 'a'; // Arbitrary key picked for testing. 16 let firstInputInteractionId = 0; 17 let eventTimingKeyDownInteractionId = 0; 18 let hasFirstInputEntry = false; 19 let hasEventTimingKeyDownEntry = false; 20 21 promise_test(async t => { 22 assert_implements(window.PerformanceEventTiming, 'Event Timing is not supported.'); 23 24 const callback = (entryList) => { 25 entryList.getEntries().forEach(entry => { 26 switch (entry.entryType) { 27 case 'first-input': { 28 firstInputInteractionId = entry.interactionId; 29 hasFirstInputEntry = true; 30 break; 31 } 32 case 'event': { 33 if ('keydown' == entry.name) { 34 eventTimingKeyDownInteractionId = entry.interactionId; 35 hasEventTimingKeyDownEntry = true; 36 } 37 break; 38 } 39 } 40 }); 41 }; 42 const readyToResolve = () => { 43 return hasFirstInputEntry && hasEventTimingKeyDownEntry; 44 } 45 const observerPromise = createPerformanceObserverPromise(['event', 'first-input'], callback, readyToResolve); 46 await interactAndObserve('key', document.getElementById('input'), observerPromise, key); 47 48 assert_greater_than(firstInputInteractionId, 0, 'The first input entry should have a non-trivial interactionId'); 49 assert_equals(firstInputInteractionId, eventTimingKeyDownInteractionId, 'The first input entry should have the same interactionId as the event timing keydown entry'); 50 assert_equals(firstInputInteractionId.target, eventTimingKeyDownInteractionId.target, 'The first input entry should have the same target as the event timing keydown entry'); 51 assert_not_equals(firstInputInteractionId.target, null, 'The first input entry should have a non-null target'); 52 53 }, "The interactionId of the first input entry should match the same keydown entry of event timing when press a key."); 54 </script> 55 56 </html>