access-control-and-redirects.any.js (2335B)
1 // META: title=Tests that redirects between origins are allowed when access control is involved. 2 // META: script=/common/get-host-info.sub.js 3 4 function runSync(test, url) 5 { 6 const xhr = new XMLHttpRequest(); 7 xhr.open("GET", url, false); 8 xhr.send(); 9 assert_equals(xhr.responseText, "PASS: Cross-domain access allowed."); 10 test.done(); 11 } 12 function runAsync(test, url) 13 { 14 const xhr = new XMLHttpRequest(); 15 xhr.open("GET", url, true); 16 xhr.onload = test.step_func_done(function() { 17 assert_equals(xhr.responseText, "PASS: Cross-domain access allowed."); 18 }); 19 xhr.onerror = test.unreached_func("Network error"); 20 xhr.send(); 21 test.done(); 22 } 23 test(t => { 24 runSync(t, "resources/redirect-cors.py?location=" + get_host_info().HTTP_REMOTE_ORIGIN + 25 "/xhr/resources/access-control-basic-allow.py") 26 }, "Local sync redirect to remote origin"); 27 async_test(t => { 28 runAsync(t, "resources/redirect-cors.py?location=" + get_host_info().HTTP_REMOTE_ORIGIN + 29 "/xhr/resources/access-control-basic-allow.py") 30 }, "Local async redirect to remote origin"); 31 test(t => { 32 runSync(t, get_host_info().HTTP_REMOTE_ORIGIN + 33 "/xhr/resources/redirect-cors.py?location=" + get_host_info().HTTP_ORIGIN + 34 "/xhr/resources/access-control-basic-allow.py&allow_origin=true") 35 }, "Remote sync redirect to local origin"); 36 async_test(t => { 37 runAsync(t, get_host_info().HTTP_REMOTE_ORIGIN + 38 "/xhr/resources/redirect-cors.py?location=" + get_host_info().HTTP_ORIGIN + 39 "/xhr/resources/access-control-basic-allow.py&allow_origin=true") 40 }, "Remote async redirect to local origin"); 41 test(t => { 42 runSync(t, get_host_info().HTTP_REMOTE_ORIGIN + 43 "/xhr/resources/redirect-cors.py?location=" + get_host_info().HTTP_REMOTE_ORIGIN + 44 "/xhr/resources/access-control-basic-allow.py&allow_origin=true") 45 }, "Remote sync redirect to same remote origin"); 46 async_test(t => { 47 runAsync(t, get_host_info().HTTP_REMOTE_ORIGIN + 48 "/xhr/resources/redirect-cors.py?location=" + get_host_info().HTTP_REMOTE_ORIGIN + 49 "/xhr/resources/access-control-basic-allow.py&allow_origin=true") 50 }, "Remote async redirect to same remote origin");