| OLD | NEW |
| (Empty) |
| 1 function log(message) | |
| 2 { | |
| 3 if (self.importScripts) { | |
| 4 postMessage(message); | |
| 5 } else { | |
| 6 document.getElementById('console').appendChild(document.createTextNode(m
essage + "\n")); | |
| 7 } | |
| 8 } | |
| 9 | |
| 10 var uuidRegex = new RegExp('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9
a-f]{12}'); | |
| 11 | |
| 12 function replaceUUID(s) | |
| 13 { | |
| 14 return s.replace(uuidRegex, 'UUID'); | |
| 15 } | |
| 16 | |
| 17 function sendXMLHttpRequestSync(method, url) | |
| 18 { | |
| 19 var xhr = new XMLHttpRequest(); | |
| 20 xhr.open(method, url, false); | |
| 21 try { | |
| 22 xhr.send(); | |
| 23 log("Status: " + xhr.status); | |
| 24 log("Response: " + xhr.responseText); | |
| 25 } catch (error) { | |
| 26 log("Received exception, code: " + error.code + ", name: " + error.name
+ ", message: " + replaceUUID(error.message)); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 function sendXMLHttpRequestAsync(method, url) | |
| 31 { | |
| 32 return new Promise(function (resolve) { | |
| 33 var xhr = new XMLHttpRequest(); | |
| 34 | |
| 35 xhr.onload = function() | |
| 36 { | |
| 37 log("Status: " + xhr.status); | |
| 38 log("Response: " + xhr.responseText); | |
| 39 }; | |
| 40 xhr.onerror = function() | |
| 41 { | |
| 42 log("Error event is dispatched"); | |
| 43 }; | |
| 44 xhr.onloadend = function() | |
| 45 { | |
| 46 resolve(); | |
| 47 }; | |
| 48 | |
| 49 xhr.open(method, url, true); | |
| 50 try { | |
| 51 xhr.send(); | |
| 52 } catch (error) { | |
| 53 log("Received exception, code: " + error.code + ", name: " + error.n
ame + ", message: " + replaceUUID(error.message)); | |
| 54 } | |
| 55 }); | |
| 56 } | |
| 57 | |
| 58 function runXHRs(file) | |
| 59 { | |
| 60 var fileURL = URL.createObjectURL(file); | |
| 61 | |
| 62 log("Test that sync XMLHttpRequest GET succeeds."); | |
| 63 sendXMLHttpRequestSync("GET", fileURL); | |
| 64 | |
| 65 log("Test that sync XMLHttpRequest POST fails."); | |
| 66 sendXMLHttpRequestSync("POST", fileURL); | |
| 67 | |
| 68 log("Test that sync XMLHttpRequest GET fails after the blob URL is revoked."
); | |
| 69 URL.revokeObjectURL(fileURL); | |
| 70 sendXMLHttpRequestSync("GET", fileURL); | |
| 71 | |
| 72 fileURL = URL.createObjectURL(file); | |
| 73 | |
| 74 log("Test that async XMLHttpRequest GET succeeds."); | |
| 75 sendXMLHttpRequestAsync("GET", fileURL).then(function() | |
| 76 { | |
| 77 log("Test that async XMLHttpRequest POST fails."); | |
| 78 return sendXMLHttpRequestAsync("POST", fileURL); | |
| 79 }).then(function() | |
| 80 { | |
| 81 log("Test that async XMLHttpRequest GET fails after the blob URL is revo
ked."); | |
| 82 URL.revokeObjectURL(fileURL); | |
| 83 return sendXMLHttpRequestAsync("GET", fileURL); | |
| 84 }).then(function() | |
| 85 { | |
| 86 log("DONE"); | |
| 87 if (!self.importScripts && testRunner.notifyDone) | |
| 88 testRunner.notifyDone(); | |
| 89 }); | |
| 90 } | |
| 91 | |
| 92 if (self.importScripts) { | |
| 93 onmessage = function(event) | |
| 94 { | |
| 95 runXHRs(event.data); | |
| 96 }; | |
| 97 } | |
| OLD | NEW |