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

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

Issue 1181973005: [XHR] Fix a XHR-stream test script. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/resources/slow-failure.cgi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
17 // we don't have to read the data.
18 xhr.response.getReader().closed.then(resolve, reject); 16 xhr.response.getReader().closed.then(resolve, reject);
19 }; 17 };
20 xhr.open('GET', url); 18 xhr.open('GET', url);
21 xhr.send(); 19 xhr.send();
22 }); 20 });
23 } 21 }
24 22
25 promise_test(function() { 23 promise_test(function() {
24 // slow-empty-response.cgi has an empty body, so we can assume that the
25 // closed promise will be resolved without reading data.
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 // alow-failure.cgi will output an error after outputting a few valid
32 // chunks, so we will see a rejection.
31 var url = '/xmlhttprequest/resources/slow-failure.cgi'; 33 var url = '/xmlhttprequest/resources/slow-failure.cgi';
32 return fetchBody(url).then(function() { 34 return fetchBody(url).then(function() {
33 assert_unreached('resolved unexpectedly'); 35 assert_unreached('resolved unexpectedly');
34 }, function() { 36 }, function() {
35 // rejected as expected 37 // rejected as expected
36 }); 38 });
37 }, 'check if |closed| gets rejected without explicit stream reference'); 39 }, 'check if |closed| gets rejected without explicit stream reference');
38 40
39 if (global.importScripts) { 41 if (global.importScripts) {
40 // Worker case 42 // Worker case
41 done(); 43 done();
42 } 44 }
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/resources/slow-failure.cgi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698