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