(done)
| 426 | // upload test, calls done function when it's over |
| 427 | let ulCalled = false; // used to prevent multiple accidental calls to ulTest |
| 428 | function ulTest(done) { |
| 429 | tverb("ulTest"); |
| 430 | if (ulCalled) return; |
| 431 | else ulCalled = true; // ulTest already called? |
| 432 | // garbage data for upload test |
| 433 | let r = new ArrayBuffer(1048576); |
| 434 | const maxInt = Math.pow(2, 32) - 1; |
| 435 | try { |
| 436 | r = new Uint32Array(r); |
| 437 | for (let i = 0; i < r.length; i++) r[i] = Math.random() * maxInt; |
| 438 | } catch (e) {} |
| 439 | let req = []; |
| 440 | let reqsmall = []; |
| 441 | for (let i = 0; i < settings.xhr_ul_blob_megabytes; i++) req.push(r); |
| 442 | req = new Blob(req); |
| 443 | r = new ArrayBuffer(262144); |
| 444 | try { |
| 445 | r = new Uint32Array(r); |
| 446 | for (let i = 0; i < r.length; i++) r[i] = Math.random() * maxInt; |
| 447 | } catch (e) {} |
| 448 | reqsmall.push(r); |
| 449 | reqsmall = new Blob(reqsmall); |
| 450 | const testFunction = function() { |
| 451 | let totLoaded = 0.0, // total number of transmitted bytes |
| 452 | startT = new Date().getTime(), // timestamp when test was started |
| 453 | bonusT = 0, //how many milliseconds the test has been shortened by (higher on faster connections) |
| 454 | graceTimeDone = false, //set to true after the grace time is past |
| 455 | failed = false; // set to true if a stream fails |
| 456 | xhr = []; |
| 457 | // function to create an upload stream. streams are slightly delayed so that they will not end at the same time |
| 458 | const testStream = function(i, delay) { |
| 459 | setTimeout( |
| 460 | function() { |
| 461 | if (testState !== 3) return; // delayed stream ended up starting after the end of the upload test |
| 462 | tverb("ul test stream started " + i + " " + delay); |
| 463 | let prevLoaded = 0; // number of bytes transmitted last time onprogress was called |
| 464 | let x = new XMLHttpRequest(); |
| 465 | xhr[i] = x; |
| 466 | let ie11workaround; |
| 467 | if (settings.forceIE11Workaround) ie11workaround = true; |
| 468 | else { |
| 469 | try { |
| 470 | xhr[i].upload.onprogress; |
| 471 | ie11workaround = false; |
| 472 | } catch (e) { |
| 473 | ie11workaround = true; |
| 474 | } |
| 475 | } |
| 476 | if (ie11workaround) { |
| 477 | // IE11 workaround: xhr.upload does not work properly, therefore we send a bunch of small 256k requests and use the onload event as progress. This is not precise, especially on fast connections |
| 478 | xhr[i].onload = xhr[i].onerror = function() { |
| 479 | tverb("ul stream progress event (ie11wa)"); |
| 480 | totLoaded += reqsmall.size; |
| 481 | testStream(i, 0); |
| 482 | }; |
| 483 | xhr[i].open("POST", settings.url_ul + url_sep(settings.url_ul) + (settings.mpot ? "cors=true&" : "") + "r=" + Math.random(), true); // random string to prevent caching |
| 484 | try { |
| 485 | xhr[i].setRequestHeader("Content-Encoding", "identity"); // disable compression (some browsers may refuse it, but data is incompressible anyway) |
no test coverage detected