| Anne van Kesteren | 647eae0 | 2017-03-10 14:41:19 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <title>XMLHttpRequest: timeout, redirects, and CORS preflights</title> |
| 3 | <script src=/resources/testharness.js></script> |
| 4 | <script src=/resources/testharnessreport.js></script> |
| 5 | <script src=/common/get-host-info.sub.js></script> |
| Adam Rice | e6116f9 | 2018-08-28 08:00:06 | [diff] [blame] | 6 | <script src=/common/utils.js></script> |
| Anne van Kesteren | 647eae0 | 2017-03-10 14:41:19 | [diff] [blame] | 7 | <div id=log></div> |
| 8 | <script> |
| 9 | async_test(t => { |
| 10 | const client = new XMLHttpRequest |
| 11 | client.open("GET", "resources/redirect.py?delay=500&location=delay.py") // 500 + 500 = 1000 |
| Adam Rice | e6116f9 | 2018-08-28 08:00:06 | [diff] [blame] | 12 | client.timeout = 750 |
| Anne van Kesteren | 647eae0 | 2017-03-10 14:41:19 | [diff] [blame] | 13 | client.send() |
| 14 | client.ontimeout = t.step_func_done(() => { |
| 15 | assert_equals(client.readyState, 4) |
| 16 | }) |
| 17 | client.onload = t.unreached_func("load event fired") |
| 18 | }, "Redirects should not reset the timer") |
| 19 | |
| 20 | async_test(t => { |
| Adam Rice | e6116f9 | 2018-08-28 08:00:06 | [diff] [blame] | 21 | // Use a unique ID to prevent caching of the preflight making the test flaky. |
| 22 | const uuid = token(); |
| Anne van Kesteren | 647eae0 | 2017-03-10 14:41:19 | [diff] [blame] | 23 | const client = new XMLHttpRequest |
| Adam Rice | e6116f9 | 2018-08-28 08:00:06 | [diff] [blame] | 24 | client.open("YO", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/delay.py?uuid=" + uuid) |
| 25 | client.timeout = 750 |
| Anne van Kesteren | 647eae0 | 2017-03-10 14:41:19 | [diff] [blame] | 26 | client.send() |
| 27 | client.ontimeout = t.step_func_done(() => { |
| 28 | assert_equals(client.readyState, 4) |
| 29 | }) |
| 30 | client.onload = t.unreached_func("load event fired") |
| 31 | }, "CORS preflights should not reset the timer") |
| 32 | </script> |