response-data-progress.htm (2096B)
1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <title>XMLHttpRequest: progress events grow response body size</title> 6 <meta name="timeout" content="long"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::a[contains(@href,'#make-progress-notifications')]/.. following::a[contains(@href,'#make-progress-notifications')]/../following:p[1]" /> 10 <link rel="help" href="https://xhr.spec.whatwg.org/#make-progress-notifications" data-tested-assertations=".." /> 11 <link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onprogress" data-tested-assertations="/../.." /> 12 <link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-progress" data-tested-assertations="/../.." /> 13 </head> 14 15 <div id="log"></div> 16 17 <script> 18 19 function doTest(test, expectedLengthComputable, expectedTotal, url) { 20 var client = new XMLHttpRequest(); 21 var lastSize = 0; 22 23 client.onprogress = test.step_func(function(e) { 24 assert_equals(e.total, expectedTotal); 25 assert_equals(e.lengthComputable, expectedLengthComputable); 26 27 var currentSize = client.responseText.length; 28 29 if (lastSize > 0 && currentSize > lastSize) { 30 // growth from a positive size to bigger! 31 test.done(); 32 } 33 34 lastSize = currentSize; 35 }); 36 37 client.onreadystatechange = test.step_func(function() { 38 if (client.readyState === 4) { 39 assert_unreached("onprogress not called multiple times, or response body did not grow."); 40 } 41 }); 42 43 client.open("GET", url); 44 client.send(null); 45 return client; 46 } 47 48 async_test(function () { doTest(this, false, 0, "resources/trickle.py?count=6&delay=150"); }, 49 document.title + ', unknown content-length'); 50 async_test(function () { doTest(this, true, 78, "resources/trickle.py?count=6&delay=150&specifylength=1"); }, 51 document.title + ', known content-length'); 52 </script>