Branch data Line data Source code
1 [ + ]: 1 : import assert from 'node:assert/strict'; 2 : 1 : import { XMLHttpRequest } from '../../../lib/whatwg-xhr.js'; 3 : 1 : import { ProgressEvent } from '../../../lib/whatwg-xhr.js'; 4 : 1 : 5 [ + ]: 1 : export default (activeURL) => { 6 : 1 : 7 : 1 : let xhr = new XMLHttpRequest(); 8 : 1 : let timeout; 9 : 1 : 10 [ + ]: 1 : xhr.onload = (e) => { 11 : 1 : 12 : 1 : assert(e instanceof ProgressEvent); 13 : 1 : assert.strictEqual(e.type, 'load'); 14 : 1 : assert.strictEqual(xhr.readyState, 4); 15 : 1 : 16 : 1 : xhr.onload = null; 17 : 1 : xhr.onreadystatechange = null; 18 : 1 : 19 : 1 : clearTimeout(timeout); 20 : 1 : }; 21 : 1 : 22 [ + ]: 1 : xhr.onreadystatechange = () => { 23 [ + ]: 4 : if(xhr.readyState !== 4){ 24 : 3 : return; 25 [ + ]: 3 : } 26 : 1 : 27 : 1 : timeout = setTimeout(() => { 28 : 0 : assert(false, "Didn't get load event within 4ms of readystatechange==4"); 29 : 1 : }, 4); 30 : 1 : }; 31 : 1 : 32 : 1 : xhr.open('GET', `${activeURL}/well-formed.xml`); 33 : 1 : xhr.send(); 34 : 1 : } 35 : 1 : 36 : 1 : /* 37 : 1 : * event-load.any.js 38 : 1 : * 39 : 1 : 40 : 1 : // META: title=XMLHttpRequest: The send() method: Fire an event named load (synchronous flag is unset) 41 : 1 : 42 : 1 : var test = async_test(); 43 : 1 : test.step(function () { 44 : 1 : var client = new XMLHttpRequest(); 45 : 1 : client.onload = test.step_func(function (e) { 46 : 1 : assert_true(e instanceof ProgressEvent); 47 : 1 : assert_equals(e.type, "load"); 48 : 1 : assert_equals(client.readyState, 4); 49 : 1 : test.done(); 50 : 1 : }); 51 : 1 : client.onreadystatechange = test.step_func(function () { 52 : 1 : if (client.readyState !== 4) return; 53 : 1 : 54 : 1 : test.step_timeout(() => { 55 : 1 : assert_unreached("Didn't get load event within 4ms of readystatechange==4"); 56 : 1 : }, 4); 57 : 1 : }); 58 : 1 : client.open("GET", "resources/well-formed.xml"); 59 : 1 : client.send(null); 60 : 1 : }); 61 : 1 : 62 : 1 : * 63 : 1 : * event-load.any.js 64 : 1 : */