fetch-header-visibility-iframe.html (2137B)
1 <script src="/common/get-host-info.sub.js"></script> 2 <script src="test-helpers.sub.js?pipe=sub"></script> 3 <script> 4 var host_info = get_host_info(); 5 var uri = document.location + '?check-ua-header'; 6 7 var headers = new Headers(); 8 headers.set('User-Agent', 'custom_ua'); 9 10 // Check the custom UA case 11 fetch(uri, { headers: headers }).then(function(response) { 12 return response.text(); 13 }).then(function(text) { 14 if (text == 'custom_ua') { 15 parent.postMessage('PASS', '*'); 16 } else { 17 parent.postMessage('withUA FAIL - expected "custom_ua", got "' + text + '"', '*'); 18 } 19 }).catch(function(err) { 20 parent.postMessage('withUA FAIL - unexpected error: ' + err, '*'); 21 }); 22 23 // Check the default UA case 24 fetch(uri, {}).then(function(response) { 25 return response.text(); 26 }).then(function(text) { 27 if (text == 'NO_UA') { 28 parent.postMessage('PASS', '*'); 29 } else { 30 parent.postMessage('noUA FAIL - expected "NO_UA", got "' + text + '"', '*'); 31 } 32 }).catch(function(err) { 33 parent.postMessage('noUA FAIL - unexpected error: ' + err, '*'); 34 }); 35 36 var uri = document.location + '?check-accept-header'; 37 var headers = new Headers(); 38 headers.set('Accept', 'hmm'); 39 40 // Check for custom accept header 41 fetch(uri, { headers: headers }).then(function(response) { 42 return response.text(); 43 }).then(function(text) { 44 if (text === headers.get('Accept')) { 45 parent.postMessage('PASS', '*'); 46 } else { 47 parent.postMessage('custom accept FAIL - expected ' + headers.get('Accept') + 48 ' got "' + text + '"', '*'); 49 } 50 }).catch(function(err) { 51 parent.postMessage('custom accept FAIL - unexpected error: ' + err, '*'); 52 }); 53 54 // Check for default accept header 55 fetch(uri).then(function(response) { 56 return response.text(); 57 }).then(function(text) { 58 if (text === '*/*') { 59 parent.postMessage('PASS', '*'); 60 } else { 61 parent.postMessage('accept FAIL - expected */* got "' + text + '"', '*'); 62 } 63 }).catch(function(err) { 64 parent.postMessage('accept FAIL - unexpected error: ' + err, '*'); 65 }); 66 </script>