Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/resources/response-stream-orphaned-promise.js

Issue 1004623007: Streams Implementation Update: async read (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@stream-reader-read
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698