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

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

Issue 1001233002: Streams Implementation Update: Reader name and Stream methods (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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 var testInLoadingState = async_test('Test aborting XMLHttpRequest with responseT ype set to "stream" in LOADING state.'); 7 var testInLoadingState = async_test('Test aborting XMLHttpRequest with responseT ype set to "stream" in LOADING state.');
8 8
9 testInLoadingState.step(function() 9 testInLoadingState.step(function()
10 { 10 {
(...skipping 13 matching lines...) Expand all
24 assert_unreached('Unexpected readyState: UNSENT'); 24 assert_unreached('Unexpected readyState: UNSENT');
25 return; 25 return;
26 26
27 case xhr.OPENED: 27 case xhr.OPENED:
28 case xhr.HEADERS_RECEIVED: 28 case xhr.HEADERS_RECEIVED:
29 return; 29 return;
30 30
31 case xhr.LOADING: 31 case xhr.LOADING:
32 var stream = xhr.response; 32 var stream = xhr.response;
33 assert_true(stream instanceof ReadableStream, 'xhr.response shoud be ReadableStream'); 33 assert_true(stream instanceof ReadableStream, 'xhr.response shoud be ReadableStream');
34 assert_true(stream.state == 'readable' || stream.state == 'waiting', 'stream state before abort() call');
35 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, x hr.LOADING]); 34 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, x hr.LOADING]);
36 35
37 xhr.abort(); 36 xhr.abort();
38 37
39 assert_equals(stream.state, 'errored', 'stream state after abort() c all');
40 assert_equals(xhr.readyState, xhr.UNSENT, 'xhr.readyState after abor t() call'); 38 assert_equals(xhr.readyState, xhr.UNSENT, 'xhr.readyState after abor t() call');
41 assert_equals(xhr.response, null, 'xhr.response after abort() call') ; 39 assert_equals(xhr.response, null, 'xhr.response after abort() call') ;
42 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, x hr.LOADING, xhr.DONE]); 40 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, x hr.LOADING, xhr.DONE]);
43 testInLoadingState.done(); 41 stream.closed.then(testInLoadingState.step_func(assert_unreached), t estInLoadingState.done.bind(testInLoadingState));
44 return; 42 return;
45 43
46 case xhr.DONE: 44 case xhr.DONE:
47 return; 45 return;
48 46
49 default: 47 default:
50 assert_unreached('Unexpected readyState: ' + xhr.readyState); 48 assert_unreached('Unexpected readyState: ' + xhr.readyState);
51 return; 49 return;
52 } 50 }
53 }); 51 });
54 52
55 xhr.open('GET', '/resources/test.ogv', true); 53 xhr.open('GET', '/resources/test.ogv', true);
56 xhr.send(); 54 xhr.send();
57 }); 55 });
58 56
59 var testInDoneState = async_test('Test aborting XMLHttpRequest with responseType set to "stream" in DONE state.'); 57 var testInDoneState = async_test('Test aborting XMLHttpRequest with responseType set to "stream" in DONE state.');
60 58
61 function readUntilDone(stream) { 59 function readUntilDone(reader) {
62 return stream.ready.then(function() { 60 return reader.ready.then(function() {
63 while (stream.state == 'readable') { 61 while (reader.state == 'readable') {
64 stream.read(); 62 reader.read();
65 } 63 }
66 if (stream.state == 'closed' || stream.state == 'errored') { 64 if (reader.state == 'closed' || reader.state == 'errored') {
67 return stream.closed; 65 return reader.closed;
68 } else { 66 } else {
69 return readUntilDone(stream); 67 return readUntilDone(reader);
70 } 68 }
71 }); 69 });
72 } 70 }
73 71
74 testInDoneState.step(function() 72 testInDoneState.step(function()
75 { 73 {
76 var xhr = new XMLHttpRequest; 74 var xhr = new XMLHttpRequest;
77 75
78 xhr.responseType = 'stream'; 76 xhr.responseType = 'stream';
79 77
80 var seenStates = []; 78 var seenStates = [];
81 var stream; 79 var stream;
82 80
83 xhr.onreadystatechange = testInDoneState.step_func(function() { 81 xhr.onreadystatechange = testInDoneState.step_func(function() {
84 // onreadystatechange can be invoked multiple times in LOADING state. 82 // onreadystatechange can be invoked multiple times in LOADING state.
85 if (seenStates.length == 0 || xhr.readyState != seenStates[seenStates.le ngth - 1]) 83 if (seenStates.length == 0 || xhr.readyState != seenStates[seenStates.le ngth - 1])
86 seenStates.push(xhr.readyState); 84 seenStates.push(xhr.readyState);
87 85
88 switch (xhr.readyState) { 86 switch (xhr.readyState) {
89 case xhr.UNSENT: 87 case xhr.UNSENT:
90 case xhr.OPENED: 88 case xhr.OPENED:
91 case xhr.HEADERS_RECEIVED: 89 case xhr.HEADERS_RECEIVED:
92 return; 90 return;
93 case xhr.LOADING: 91 case xhr.LOADING:
94 if (!stream) { 92 if (!stream) {
95 stream = xhr.response; 93 stream = xhr.response;
96 assert_true(stream instanceof ReadableStream, 'xhr.response shou d be ReadableStream'); 94 assert_true(stream instanceof ReadableStream, 'xhr.response shou d be ReadableStream');
97 readUntilDone(stream).then(function() { 95 readUntilDone(stream.getReader()).then(function() {
98 assert_true(stream instanceof ReadableStream, 'xhr.response should be ReadableStream'); 96 assert_true(stream instanceof ReadableStream, 'xhr.response should be ReadableStream');
99 assert_equals(stream.state, 'closed', 'stream state before a bort() call');
100 assert_equals(xhr.status, 200, 'xhr.status'); 97 assert_equals(xhr.status, 200, 'xhr.status');
101 assert_not_equals(xhr.response, null, 'xhr.response during D ONE'); 98 assert_not_equals(xhr.response, null, 'xhr.response during D ONE');
102 99
103 xhr.abort(); 100 xhr.abort();
104 101
105 assert_equals(stream.state, 'closed', 'stream state after ab ort() call');
106 assert_equals(xhr.readyState, xhr.UNSENT, 'xhr.readyState af ter abort() call'); 102 assert_equals(xhr.readyState, xhr.UNSENT, 'xhr.readyState af ter abort() call');
107 assert_equals(xhr.response, null, 'xhr.response after abort( ) call'); 103 assert_equals(xhr.response, null, 'xhr.response after abort( ) call');
108 104
109 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_REC EIVED, xhr.LOADING, xhr.DONE]); 105 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_REC EIVED, xhr.LOADING, xhr.DONE]);
106 return stream.closed;
107 }).then(function() {
110 testInDoneState.done(); 108 testInDoneState.done();
111 }).catch(testInDoneState.step_func(function(e) { 109 }).catch(testInDoneState.step_func(function(e) {
112 assert_unreached(e); 110 assert_unreached(e);
113 })); 111 }));
114 } 112 }
115 return; 113 return;
116 114
117 case xhr.DONE: 115 case xhr.DONE:
118 return; 116 return;
119 117
120 default: 118 default:
121 assert_unreached('Unexpected readyState: ' + xhr.readyState); 119 assert_unreached('Unexpected readyState: ' + xhr.readyState);
122 return; 120 return;
123 } 121 }
124 }); 122 });
125 123
126 xhr.open('GET', '/resources/test.ogv', true); 124 xhr.open('GET', '/resources/test.ogv', true);
127 xhr.send(); 125 xhr.send();
128 }); 126 });
129 127
130 if (global.importScripts) { 128 if (global.importScripts) {
131 // Worker case 129 // Worker case
132 done(); 130 done();
133 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698