11cb0ef41Sopenharmony_ci<!doctype html> 21cb0ef41Sopenharmony_ci<html> 31cb0ef41Sopenharmony_ci<head> 41cb0ef41Sopenharmony_ci<meta chareset="utf-8"> 51cb0ef41Sopenharmony_ci<title>Clicking editable content in link shouldn't cause redundant focus related events</title> 61cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 71cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 81cb0ef41Sopenharmony_ci<script src="/resources/testdriver.js"></script> 91cb0ef41Sopenharmony_ci<script src="/resources/testdriver-actions.js"></script> 101cb0ef41Sopenharmony_ci<script src="/resources/testdriver-vendor.js"></script> 111cb0ef41Sopenharmony_ci</head> 121cb0ef41Sopenharmony_ci<body> 131cb0ef41Sopenharmony_ci<a href="#"><span contenteditable>Hello</span></a> 141cb0ef41Sopenharmony_ci<a href="#" contenteditable><span>Hello</span></a> 151cb0ef41Sopenharmony_ci<script> 161cb0ef41Sopenharmony_cifunction promiseTicks() { 171cb0ef41Sopenharmony_ci return new Promise(resolve => { 181cb0ef41Sopenharmony_ci requestAnimationFrame(() => { 191cb0ef41Sopenharmony_ci requestAnimationFrame(resolve); 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci }); 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciasync function clickElementAndCollectFocusEvents(x, y, options) { 251cb0ef41Sopenharmony_ci await promiseTicks(); 261cb0ef41Sopenharmony_ci let events = []; 271cb0ef41Sopenharmony_ci for (const eventType of ["focus", "blur", "focusin", "focusout"]) { 281cb0ef41Sopenharmony_ci document.addEventListener(eventType, event => { 291cb0ef41Sopenharmony_ci events.push(`type: ${event.type}, target: ${event.target.nodeName}`); 301cb0ef41Sopenharmony_ci }, {capture: true}); 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci const waitForClickEvent = new Promise(resolve => { 341cb0ef41Sopenharmony_ci addEventListener("click", resolve, {capture: true, once: true}); 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci await new test_driver 381cb0ef41Sopenharmony_ci .Actions() 391cb0ef41Sopenharmony_ci .pointerMove(x, y, options) 401cb0ef41Sopenharmony_ci .pointerDown() 411cb0ef41Sopenharmony_ci .pointerUp() 421cb0ef41Sopenharmony_ci .send(); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci await waitForClickEvent; 451cb0ef41Sopenharmony_ci await promiseTicks(); 461cb0ef41Sopenharmony_ci return events; 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_cipromise_test(async t => { 501cb0ef41Sopenharmony_ci document.activeElement?.blur(); 511cb0ef41Sopenharmony_ci const editingHost = document.querySelector("span[contenteditable]"); 521cb0ef41Sopenharmony_ci editingHost.blur(); 531cb0ef41Sopenharmony_ci const focusEvents = 541cb0ef41Sopenharmony_ci await clickElementAndCollectFocusEvents(5, 5, {origin: editingHost}); 551cb0ef41Sopenharmony_ci assert_array_equals( 561cb0ef41Sopenharmony_ci focusEvents, 571cb0ef41Sopenharmony_ci [ 581cb0ef41Sopenharmony_ci "type: focus, target: SPAN", 591cb0ef41Sopenharmony_ci "type: focusin, target: SPAN", 601cb0ef41Sopenharmony_ci ], 611cb0ef41Sopenharmony_ci "Click event shouldn't cause redundant focus events"); 621cb0ef41Sopenharmony_ci}, "Click editable element in link"); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_cipromise_test(async t => { 651cb0ef41Sopenharmony_ci document.activeElement?.blur(); 661cb0ef41Sopenharmony_ci const editingHost = document.querySelector("a[contenteditable]"); 671cb0ef41Sopenharmony_ci editingHost.blur(); 681cb0ef41Sopenharmony_ci const focusEvents = 691cb0ef41Sopenharmony_ci await clickElementAndCollectFocusEvents(5, 5, {origin: editingHost}); 701cb0ef41Sopenharmony_ci assert_array_equals( 711cb0ef41Sopenharmony_ci focusEvents, 721cb0ef41Sopenharmony_ci [ 731cb0ef41Sopenharmony_ci "type: focus, target: A", 741cb0ef41Sopenharmony_ci "type: focusin, target: A", 751cb0ef41Sopenharmony_ci ], 761cb0ef41Sopenharmony_ci "Click event shouldn't cause redundant focus events"); 771cb0ef41Sopenharmony_ci}, "Click editable link"); 781cb0ef41Sopenharmony_ci</script> 791cb0ef41Sopenharmony_ci</body> 801cb0ef41Sopenharmony_ci</html> 81