| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../resources/testharness.js"></script> | 4 <script src="../resources/testharness.js"></script> |
| 5 <script src="../resources/testharnessreport.js"></script> | 5 <script src="../resources/testharnessreport.js"></script> |
| 6 </head> | 6 </head> |
| 7 <body> | 7 <body> |
| 8 <p> Verify that a timeout ProgressEvent is dispatched and have the expected valu
es.</p> | 8 <p> Verify that a timeout ProgressEvent is dispatched and have the expected valu
es.</p> |
| 9 <div id="log"></div> | 9 <div id="logEvent"></div> |
| 10 <script type="text/javascript"> | 10 <script type="text/javascript"> |
| 11 var didTimeout = false; |
| 11 | 12 |
| 12 function verifyProgressEvent(context, e) | 13 function timeoutEvent(e) { |
| 13 { | 14 didTimeout = true; |
| 14 assert_true(e.loaded >= 0, "Non-zero 'loaded' value for '" + context + "' ev
ent."); | |
| 15 assert_true(!e.lengthComputable || e.total > 0, "Non-zero 'total' value for
'" + context + "' event."); | |
| 16 } | |
| 17 | |
| 18 function logProgressEvent(e) { | |
| 19 results += " " + e.type; | |
| 20 } | 15 } |
| 21 | 16 |
| 22 function unexpectedProgressEvent(e) { | 17 function unexpectedProgressEvent(e) { |
| 23 assert_unreached("Unexpected request error"); | 18 assert_unreached("'" + e.type + "' event should not be dispatched, expected
'timeout'"); |
| 24 } | |
| 25 | |
| 26 function timeoutHandler(e) | |
| 27 { | |
| 28 assert_true(e instanceof ProgressEvent); | |
| 29 verifyProgressEvent("ontimeout", e); | |
| 30 testOnTimeoutEvent.done(); | |
| 31 } | 19 } |
| 32 | 20 |
| 33 var testOnTimeoutEvent = async_test("Check that 'timeout' events are delivered a
nd have expected values."); | 21 var testOnTimeoutEvent = async_test("Check that 'timeout' events are delivered a
nd have expected values."); |
| 34 testOnTimeoutEvent.step(function () { | 22 testOnTimeoutEvent.step(function () { |
| 35 var xhr = new XMLHttpRequest(); | 23 var xhr = new XMLHttpRequest(); |
| 36 xhr.ontimeout = testOnTimeoutEvent.step_func(timeoutHandler); | 24 xhr.ontimeout = testOnTimeoutEvent.step_func(timeoutEvent); |
| 37 xhr.onabort = testOnTimeoutEvent.step_func(unexpectedProgressEvent); | 25 xhr.onabort = testOnTimeoutEvent.step_func(unexpectedProgressEvent); |
| 38 xhr.onerror = testOnTimeoutEvent.step_func(unexpectedProgressEvent); | 26 xhr.onerror = testOnTimeoutEvent.step_func(unexpectedProgressEvent); |
| 39 xhr.onload = testOnTimeoutEvent.step_func(unexpectedProgressEvent); | 27 xhr.onload = testOnTimeoutEvent.step_func(unexpectedProgressEvent); |
| 40 xhr.timeout = 30; | 28 xhr.onloadend = testOnTimeoutEvent.step_func(function(e) { |
| 41 xhr.open("GET", "/resources/load-and-stall.php?name=../resources/test.mp4&st
allAt=100&stallFor=10000&mimeType=video/mp4", true); | 29 assert_true(didTimeout, "'timeout' event should be dispatched after 400m
s"); |
| 30 testOnTimeoutEvent.done(); |
| 31 }); |
| 32 xhr.timeout = 100000; |
| 33 xhr.open("GET", "../resources/load-and-stall.php?name=test.mp4&stallAt=0&sta
llFor=1000&mimeType=video/mp4", true); |
| 42 xhr.send(); | 34 xhr.send(); |
| 35 // Defer overriding timeout |
| 36 setTimeout(function() { |
| 37 xhr.timeout = 400; |
| 38 }, 200); |
| 43 }); | 39 }); |
| 44 </script> | 40 </script> |
| 45 </body> | 41 </body> |
| 46 </html> | 42 </html> |
| OLD | NEW |