test-helper.js (1928B)
1 // Tests scheduler context propagation when a blur is caused by a task in one 2 // context and observed in another, within the same task (depending on origin 3 // and site isolation). 4 function runFocusChangeTest(t, crossOrigin) { 5 window.onload = () => { 6 const iframe = document.createElement('iframe'); 7 let src = location.href.slice(0, location.href.lastIndexOf('/')) 8 + '/resources/focus-change-test-subframe.html'; 9 if (crossOrigin) { 10 src = src.replace('://', '://www1.') 11 } 12 iframe.src = src; 13 iframe.onload = () => { 14 // TAB to focus the first input. 15 test_driver.send_keys(document.body, "\ue004"); 16 // TAB again to focus the iframe's input. 17 test_driver.send_keys(document.body, "\ue004"); 18 } 19 document.body.appendChild(iframe); 20 } 21 22 let count = 0; 23 24 window.onmessage = t.step_func((e) => { 25 if (e.data.status === 'focus') { 26 ++count; 27 // The scheduling state is set when running the scheduler.postTask() and 28 // propagated to continuations descending from the callback. 29 if (count == 1) { 30 scheduler.postTask(() => { input.focus(); }, {priority: 'background'}); 31 } else { 32 assert_equals(count, 2); 33 scheduler.postTask(async () => { 34 await Promise.resolve(); 35 input.focus(); 36 }, {priority: 'background'}); 37 } 38 } else { 39 assert_equals(e.data.status, 'done'); 40 // If the default priority task runs before the background priority 41 // continuation, then the scheduling state was used for the continuation, 42 // which should not be the case for either cross- or same-origin frames. 43 assert_false( 44 e.data.didRun, 45 'Did not expect the continuation to use inherited signals'); 46 if (count == 1) { 47 test_driver.send_keys(document.body, "\ue004"); 48 } else { 49 assert_equals(count, 2); 50 t.done(); 51 } 52 } 53 }); 54 }