(details, { abortAfterMs } = {})
| 1138 | name: "GM_xhr abort timeout onloadend events", |
| 1139 | async run(fetch) { |
| 1140 | const runCase = (details, { abortAfterMs } = {}) => { |
| 1141 | return new Promise((resolve, reject) => { |
| 1142 | const events = []; |
| 1143 | const timeoutMs = Math.max((details.timeout || 0) + (abortAfterMs || 0) + 8000, 12000); |
| 1144 | const timer = setTimeout(() => { |
| 1145 | reject(new Error(`Expected onloadend; events=${events.join(",")}`)); |
| 1146 | }, timeoutMs); |
| 1147 | const req = GM_xmlhttpRequest({ |
| 1148 | method: details.method || "GET", |
| 1149 | url: details.url, |
| 1150 | timeout: details.timeout, |
| 1151 | fetch, |
| 1152 | onload() { |
| 1153 | events.push("onload"); |
| 1154 | }, |
| 1155 | onerror() { |
| 1156 | events.push("onerror"); |
| 1157 | }, |
| 1158 | onabort() { |
| 1159 | events.push("onabort"); |
| 1160 | }, |
| 1161 | ontimeout() { |
| 1162 | events.push("ontimeout"); |
| 1163 | }, |
| 1164 | onloadend(response) { |
| 1165 | events.push("onloadend"); |
| 1166 | clearTimeout(timer); |
| 1167 | resolve({ events, response }); |
| 1168 | }, |
| 1169 | }); |
| 1170 | if (abortAfterMs != null) { |
| 1171 | setTimeout(() => req.abort(), abortAfterMs); |
| 1172 | } |
| 1173 | }); |
| 1174 | }; |
| 1175 | |
| 1176 | const normal = await runCase({ |
| 1177 | url: `${HB}/get`, |
no test coverage detected