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 : 4 [ + ]: 1 : export default (activeURL) => { 5 : 1 : 6 : 1 : let xhr = new XMLHttpRequest(); 7 : 1 : let countedLoading = 0; 8 : 1 : 9 [ + ]: 1 : xhr.onreadystatechange = () => { 10 [ + ]: 13 : if(xhr.readyState === 3){ 11 : 10 : countedLoading += 1; 12 : 10 : } 13 : 13 : 14 [ + ]: 13 : if(xhr.readyState === 4) { 15 : 1 : assert(countedLoading > 1, 'LOADING state change may be emitted multiple times'); 16 : 1 : 17 : 1 : xhr.onreadystatechange = null; 18 : 1 : } 19 : 1 : }; 20 : 1 : 21 : 1 : xhr.open('GET', `${activeURL}/trickle.py?count=10`); 22 : 1 : xhr.send(); 23 : 1 : } 24 : 1 : 25 : 1 : /* 26 : 1 : * event-readystatechange-loaded.any.js 27 : 1 : * 28 : 1 : 29 : 1 : // META: title=XMLHttpRequest: the LOADING state change may be emitted multiple times 30 : 1 : 31 : 1 : var test = async_test(); 32 : 1 : 33 : 1 : test.step(function () { 34 : 1 : var client = new XMLHttpRequest(); 35 : 1 : var countedLoading = 0; 36 : 1 : 37 : 1 : client.onreadystatechange = test.step_func(function () { 38 : 1 : if (client.readyState === 3) { 39 : 1 : countedLoading += 1; 40 : 1 : } 41 : 1 : 42 : 1 : if (client.readyState === 4) { 43 : 1 : assert_greater_than(countedLoading, 1, "LOADING state change may be emitted multiple times"); 44 : 1 : 45 : 1 : test.done(); 46 : 1 : } 47 : 1 : }); 48 : 1 : 49 : 1 : client.open("GET", "resources/trickle.py?count=10"); // default timeout in trickle.py is 1/2 sec, so this request will take 5 seconds to complete 50 : 1 : client.send(null); 51 : 1 : }); 52 : 1 : 53 : 1 : * 54 : 1 : * event-readystatechange-loaded.any.js 55 : 1 : */