| OLD | NEW |
| 1 var global = this; | 1 var global = this; |
| 2 if (global.importScripts) { | 2 if (global.importScripts) { |
| 3 // Worker case | 3 // Worker case |
| 4 importScripts('/resources/testharness.js'); | 4 importScripts('/resources/testharness.js'); |
| 5 } | 5 } |
| 6 | 6 |
| 7 function fetchBody(url) { | 7 function fetchBody(url) { |
| 8 return new Promise(function(resolve, reject) { | 8 return new Promise(function(resolve, reject) { |
| 9 var xhr = new XMLHttpRequest; | 9 var xhr = new XMLHttpRequest; |
| 10 xhr.responseType = 'stream'; | 10 xhr.responseType = 'stream'; |
| 11 var visited = false; | 11 var visited = false; |
| 12 xhr.onreadystatechange = function() { | 12 xhr.onreadystatechange = function() { |
| 13 if (xhr.readyState !== xhr.LOADING || visited) | 13 if (xhr.readyState !== xhr.LOADING || visited) |
| 14 return; | 14 return; |
| 15 visited = true; | 15 visited = true; |
| 16 // Note that all provided urls have empty bodies, so | 16 // Note that all provided urls have empty bodies, so |
| 17 // we don't have to read the data. | 17 // we don't have to read the data. |
| 18 xhr.response.closed.then(resolve, reject); | 18 xhr.response.getReader().closed.then(resolve, reject); |
| 19 }; | 19 }; |
| 20 xhr.open('GET', url); | 20 xhr.open('GET', url); |
| 21 xhr.send(); | 21 xhr.send(); |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 promise_test(function() { | 25 promise_test(function() { |
| 26 var url = '/xmlhttprequest/resources/slow-empty-response.cgi'; | 26 var url = '/xmlhttprequest/resources/slow-empty-response.cgi'; |
| 27 return fetchBody(url); | 27 return fetchBody(url); |
| 28 }, 'check if |closed| gets resolved without stream reference'); | 28 }, 'check if |closed| gets resolved without stream reference'); |
| 29 | 29 |
| 30 promise_test(function() { | 30 promise_test(function() { |
| 31 var url = '/xmlhttprequest/resources/slow-failure.cgi'; | 31 var url = '/xmlhttprequest/resources/slow-failure.cgi'; |
| 32 return fetchBody(url).then(function() { | 32 return fetchBody(url).then(function() { |
| 33 assert_unreached('resolved unexpectedly'); | 33 assert_unreached('resolved unexpectedly'); |
| 34 }, function() { | 34 }, function() { |
| 35 // rejected as expected | 35 // rejected as expected |
| 36 }); | 36 }); |
| 37 }, 'check if |closed| gets rejected without explicit stream reference'); | 37 }, 'check if |closed| gets rejected without explicit stream reference'); |
| 38 | 38 |
| 39 if (global.importScripts) { | 39 if (global.importScripts) { |
| 40 // Worker case | 40 // Worker case |
| 41 done(); | 41 done(); |
| 42 } | 42 } |
| OLD | NEW |