Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / client / netmonitor / test / html_custom-get-page.html
blobdb4e45e81c9b527ffb88bc470ca21ae54eeb9d95
1 <!-- Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ -->
3 <!doctype html>
5 <html>
6 <head>
7 <meta charset="utf-8"/>
8 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
9 <meta http-equiv="Pragma" content="no-cache" />
10 <meta http-equiv="Expires" content="0" />
11 <title>Network Monitor test page</title>
12 </head>
14 <body>
15 <p>Performing a custom number of GETs</p>
17 <script type="text/javascript">
18 /* exported performRequests hasOfflineEventFired */
19 "use strict";
21 function get(address) {
22 return new Promise(resolve => {
23 const xhr = new XMLHttpRequest();
24 xhr.open("GET", address, true);
26 xhr.onreadystatechange = function() {
27 if (this.readyState == this.DONE) {
28 resolve();
31 xhr.send(null);
32 });
35 // Use a count parameter to defeat caching.
36 let count = 0;
38 async function performRequests(total, url, timeout = 0) {
39 if (!total) {
40 return;
42 await get(url || "request_" + (count++));
43 setTimeout(performRequests.bind(this, --total, url, timeout), timeout);
46 // For testing the offline mode in the netmonitor
47 let isOfflineEventFired = false;
48 window.addEventListener("offline", () => {
49 isOfflineEventFired = true
50 }, { once: true });
52 function hasOfflineEventFired() {
53 return isOfflineEventFired;
55 </script>
56 </body>
58 </html>