access-control-basic-allow-preflight-cache-timeout.any.js (1475B)
1 // META: title=Preflight cache should be invalidated on timeout 2 // META: timeout=long 3 // META: script=/common/get-host-info.sub.js 4 // META: script=/common/utils.js 5 6 const uuid = token(); 7 let xhr = new XMLHttpRequest; 8 9 async_test(function(test) { 10 xhr.onerror = test.unreached_func("FAIL: Network error."); 11 xhr.onload = test.step_func(function() { 12 // Token reset. We can start the test now. 13 assert_equals(xhr.responseText, "PASS"); 14 firstRequest(); 15 }); 16 17 xhr.open("GET", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/reset-token.py?token=" + uuid, true); 18 xhr.send(); 19 20 function firstRequest() { 21 xhr.onload = test.step_func(function() { 22 assert_equals(xhr.responseText, "PASS: First PUT request."); 23 step_timeout(secondRequest, 3000); // 3 seconds 24 }); 25 xhr.open("PUT", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/access-control-basic-preflight-cache-timeout.py?token=" + uuid, true); 26 xhr.send(); 27 } 28 29 function secondRequest() { 30 xhr.onload = test.step_func(function() { 31 assert_equals(xhr.responseText, "PASS: Second OPTIONS request was sent."); 32 test.done(); 33 }); 34 xhr.open("PUT", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/access-control-basic-preflight-cache-timeout.py?token=" + uuid, true); 35 xhr.send(); 36 } 37 }, "Preflight cache should be invalidated on timeout");