workerxhr-origin-referrer.js (1984B)
1 importScripts("/resources/testharness.js") 2 3 async_test(function() { 4 var expected = 'Referer: ' + 5 location.href.replace(/[^/]*$/, '') + 6 "workerxhr-origin-referrer.js\n" 7 8 var xhr = new XMLHttpRequest() 9 xhr.onreadystatechange = this.step_func(function() { 10 if (xhr.readyState == 4) { 11 assert_equals(xhr.responseText, expected) 12 this.done() 13 } 14 }) 15 xhr.open('GET', 'inspect-headers.py?filter_name=referer', true) 16 xhr.send() 17 }, 'Referer header') 18 19 async_test(function() { 20 var expected = 'Origin: ' + 21 location.protocol + 22 '//' + 23 location.hostname + 24 (location.port === "" ? "" : ":" + location.port) + 25 '\n' 26 27 var xhr = new XMLHttpRequest() 28 xhr.onreadystatechange = this.step_func(function() { 29 if (xhr.readyState == 4) { 30 assert_equals(xhr.responseText, expected) 31 this.done() 32 } 33 }) 34 var url = location.protocol + 35 '//www2.' + 36 location.hostname + 37 (location.port === "" ? "" : ":" + location.port) + 38 location.pathname.replace(/[^/]*$/, '') + 39 'inspect-headers.py?filter_name=origin&cors' 40 xhr.open('GET', url, true) 41 xhr.send() 42 }, 'Origin header') 43 44 async_test(function() { 45 // If "origin" / base URL is the origin of this JS file, we can load files 46 // from the server it originates from.. and requri.py will be able to tell us 47 // what the requested URL was 48 49 var expected = location.href.replace(/[^/]*$/, '') + 50 'requri.py?full' 51 52 var xhr = new XMLHttpRequest() 53 xhr.onreadystatechange = this.step_func(function() { 54 if (xhr.readyState == 4) { 55 assert_equals(xhr.responseText, expected) 56 this.done() 57 } 58 }) 59 xhr.open('GET', 'requri.py?full', true) 60 xhr.send() 61 }, 'Request URL test') 62 63 done()