| OLD | NEW |
| 1 if (self.importScripts) { | 1 if (self.importScripts) { |
| 2 importScripts('../resources/fetch-test-helpers.js'); | 2 importScripts('../resources/fetch-test-helpers.js'); |
| 3 } | 3 } |
| 4 | 4 |
| 5 function arrayBufferToString(buffer) { | 5 function arrayBufferToString(buffer) { |
| 6 return new Promise(function(resolve) { | 6 return new Promise(function(resolve) { |
| 7 var reader = new FileReader(); | 7 var reader = new FileReader(); |
| 8 reader.onload = function() { | 8 reader.onload = function() { |
| 9 resolve(reader.result); | 9 resolve(reader.result); |
| 10 }; | 10 }; |
| 11 reader.readAsText(new Blob([buffer])); | 11 reader.readAsText(new Blob([buffer])); |
| 12 }); | 12 }); |
| 13 } | 13 } |
| 14 | 14 |
| 15 function readStream(stream, values) { | 15 function readStream(stream, values) { |
| 16 while (stream.state === 'readable') { | 16 while (stream.state === 'readable') { |
| 17 values.push(stream.read()); | 17 values.push(stream.read()); |
| 18 } | 18 } |
| 19 if (stream.state === 'waiting') { | 19 if (stream.state === 'waiting') { |
| 20 return stream.wait().then(function() { | 20 return stream.ready.then(function() { |
| 21 readStream(stream, values); | 21 readStream(stream, values); |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 return stream.closed; | 24 return stream.closed; |
| 25 } | 25 } |
| 26 | 26 |
| 27 promise_test(function(test) { | 27 promise_test(function(test) { |
| 28 var response; | 28 var response; |
| 29 return fetch('/fetch/resources/doctype.html') | 29 return fetch('/fetch/resources/doctype.html') |
| 30 .then(function(resp) { | 30 .then(function(resp) { |
| 31 response = resp; | 31 response = resp; |
| 32 return response.body.wait(); | 32 return response.body.ready; |
| 33 }) | 33 }) |
| 34 .then(function() { | 34 .then(function() { |
| 35 if (response.body.state !== 'readable') { | 35 if (response.body.state !== 'readable') { |
| 36 return Promise.reject(TypeError('stream state get wrong')); | 36 return Promise.reject(TypeError('stream state get wrong')); |
| 37 } else { | 37 } else { |
| 38 return response.text(); | 38 return response.text(); |
| 39 } | 39 } |
| 40 }) | 40 }) |
| 41 .then(function(text) { | 41 .then(function(text) { |
| 42 assert_equals(text, '<!DOCTYPE html>\n', 'response.body'); | 42 assert_equals(text, '<!DOCTYPE html>\n', 'response.body'); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return fetch('/fetch/resources/doctype.html') | 136 return fetch('/fetch/resources/doctype.html') |
| 137 .then(function(response) { | 137 .then(function(response) { |
| 138 return response.text(); | 138 return response.text(); |
| 139 }) | 139 }) |
| 140 .then(function(text) { | 140 .then(function(text) { |
| 141 assert_equals(text, '<!DOCTYPE html>\n'); | 141 assert_equals(text, '<!DOCTYPE html>\n'); |
| 142 }) | 142 }) |
| 143 }, 'TextTest'); | 143 }, 'TextTest'); |
| 144 | 144 |
| 145 done(); | 145 done(); |
| OLD | NEW |