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

Side by Side Diff: LayoutTests/http/tests/fetch/script-tests/fetch.js

Issue 1216203003: Replace all sequential_promise_tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@update-testharnessjs
Patch Set: Created 5 years, 5 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 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 sequential_promise_test(function(t) { 5 promise_test(function(t) {
6 return fetch('http://') 6 return fetch('http://')
7 .then( 7 .then(
8 t.unreached_func('fetch of invalid URL must fail'), 8 t.unreached_func('fetch of invalid URL must fail'),
9 function() {}); 9 function() {});
10 }, 'Fetch invalid URL'); 10 }, 'Fetch invalid URL');
11 11
12 // https://fetch.spec.whatwg.org/#fetching 12 // https://fetch.spec.whatwg.org/#fetching
13 // Step 4: 13 // Step 4:
14 // request's url's scheme is not one of "http" and "https" 14 // request's url's scheme is not one of "http" and "https"
15 // A network error. 15 // A network error.
16 sequential_promise_test(function(t) { 16 promise_test(function(t) {
17 return fetch('ftp://localhost/') 17 return fetch('ftp://localhost/')
18 .then( 18 .then(
19 t.unreached_func('fetch of non-HTTP(S) CORS must fail'), 19 t.unreached_func('fetch of non-HTTP(S) CORS must fail'),
20 function() {}); 20 function() {});
21 }, 'fetch non-HTTP(S) CORS'); 21 }, 'fetch non-HTTP(S) CORS');
22 22
23 // https://fetch.spec.whatwg.org/#concept-basic-fetch 23 // https://fetch.spec.whatwg.org/#concept-basic-fetch
24 // The last statement: 24 // The last statement:
25 // Otherwise 25 // Otherwise
26 // Return a network error. 26 // Return a network error.
27 sequential_promise_test(function(t) { 27 promise_test(function(t) {
28 return fetch('foobar://localhost/', {mode: 'no-cors'}) 28 return fetch('foobar://localhost/', {mode: 'no-cors'})
29 .then( 29 .then(
30 t.unreached_func('scheme not listed in basic fetch spec must fail'), 30 t.unreached_func('scheme not listed in basic fetch spec must fail'),
31 function() {}); 31 function() {});
32 }, 'fetch of scheme not listed in basic fetch spec'); 32 }, 'fetch of scheme not listed in basic fetch spec');
33 33
34 sequential_promise_test(function(t) { 34 promise_test(function(t) {
35 return fetch('/fetch/resources/fetch-status.php?status=200') 35 return fetch('/fetch/resources/fetch-status.php?status=200')
36 .then(function(response) { 36 .then(function(response) {
37 assert_equals(response.status, 200); 37 assert_equals(response.status, 200);
38 assert_equals(response.statusText, 'OK'); 38 assert_equals(response.statusText, 'OK');
39 }); 39 });
40 }, 'Fetch result of 200 response'); 40 }, 'Fetch result of 200 response');
41 41
42 sequential_promise_test(function(t) { 42 promise_test(function(t) {
43 return fetch('/fetch/resources/fetch-status.php?status=404') 43 return fetch('/fetch/resources/fetch-status.php?status=404')
44 .then(function(response) { 44 .then(function(response) {
45 assert_equals(response.status, 404); 45 assert_equals(response.status, 404);
46 assert_equals(response.statusText, 'Not Found'); 46 assert_equals(response.statusText, 'Not Found');
47 }); 47 });
48 }, 'Fetch result of 404 response'); 48 }, 'Fetch result of 404 response');
49 49
50 sequential_promise_test(function(t) { 50 promise_test(function(t) {
51 var request = new Request( 51 var request = new Request(
52 '/fetch/resources/fetch-status.php?status=200#fragment'); 52 '/fetch/resources/fetch-status.php?status=200#fragment');
53 53
54 // The url attribute's getter must return request's url, 54 // The url attribute's getter must return request's url,
55 // serialized with the exclude fragment flag set. 55 // serialized with the exclude fragment flag set.
56 assert_equals(request.url, 56 assert_equals(request.url,
57 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'); 57 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200');
58 assert_equals(request.context, ''); 58 assert_equals(request.context, '');
59 59
60 return fetch(request) 60 return fetch(request)
61 .then(function(response) { 61 .then(function(response) {
62 assert_equals(response.status, 200); 62 assert_equals(response.status, 200);
63 assert_equals(response.statusText, 'OK'); 63 assert_equals(response.statusText, 'OK');
64 // The url attribute's getter must return the empty string 64 // The url attribute's getter must return the empty string
65 // if response's url is null and response's url, 65 // if response's url is null and response's url,
66 // serialized with the exclude fragment flag set, otherwise. 66 // serialized with the exclude fragment flag set, otherwise.
67 assert_equals(response.url, 67 assert_equals(response.url,
68 BASE_ORIGIN + 68 BASE_ORIGIN +
69 '/fetch/resources/fetch-status.php?status=200'); 69 '/fetch/resources/fetch-status.php?status=200');
70 assert_equals(request.context, ''); 70 assert_equals(request.context, '');
71 }); 71 });
72 }, 'Request/response url attribute getter with fragment'); 72 }, 'Request/response url attribute getter with fragment');
73 73
74 sequential_promise_test(function(t) { 74 promise_test(function(t) {
75 var redirect_target_url = 75 var redirect_target_url =
76 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200'; 76 BASE_ORIGIN + '/fetch/resources/fetch-status.php?status=200';
77 var redirect_original_url = 77 var redirect_original_url =
78 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' + 78 BASE_ORIGIN + '/serviceworker/resources/redirect.php?Redirect=' +
79 redirect_target_url; 79 redirect_target_url;
80 80
81 var request = new Request(redirect_original_url); 81 var request = new Request(redirect_original_url);
82 assert_equals(request.url, redirect_original_url, 82 assert_equals(request.url, redirect_original_url,
83 'Request\'s url is the original URL'); 83 'Request\'s url is the original URL');
84 assert_equals(request.context, ''); 84 assert_equals(request.context, '');
(...skipping 11 matching lines...) Expand all
96 }, 'Request/response url attribute getter with redirect'); 96 }, 'Request/response url attribute getter with redirect');
97 97
98 function evalJsonp(text) { 98 function evalJsonp(text) {
99 return new Promise(function(resolve) { 99 return new Promise(function(resolve) {
100 var report = resolve; 100 var report = resolve;
101 // text must contain report() call. 101 // text must contain report() call.
102 eval(text); 102 eval(text);
103 }); 103 });
104 } 104 }
105 105
106 sequential_promise_test(function(t) { 106 promise_test(function(t) {
107 var request = 107 var request =
108 new Request('/serviceworker/resources/fetch-access-control.php', 108 new Request('/serviceworker/resources/fetch-access-control.php',
109 { 109 {
110 method: 'POST', 110 method: 'POST',
111 body: new Blob(['Test Blob'], {type: 'test/type'}) 111 body: new Blob(['Test Blob'], {type: 'test/type'})
112 }); 112 });
113 assert_equals(request.context, ''); 113 assert_equals(request.context, '');
114 return fetch(request) 114 return fetch(request)
115 .then(function(response) { return response.text(); }) 115 .then(function(response) { return response.text(); })
116 .then(evalJsonp) 116 .then(evalJsonp)
117 .then(function(result) { 117 .then(function(result) {
118 assert_equals(result.method, 'POST'); 118 assert_equals(result.method, 'POST');
119 assert_equals(result.body, 'Test Blob'); 119 assert_equals(result.body, 'Test Blob');
120 assert_equals(request.context, ''); 120 assert_equals(request.context, '');
121 }); 121 });
122 }, 'Fetch with Blob body test'); 122 }, 'Fetch with Blob body test');
123 123
124 sequential_promise_test(function(t) { 124 promise_test(function(t) {
125 var request = new Request( 125 var request = new Request(
126 '/serviceworker/resources/fetch-access-control.php', 126 '/serviceworker/resources/fetch-access-control.php',
127 {method: 'POST', body: 'Test String'}); 127 {method: 'POST', body: 'Test String'});
128 return fetch(request) 128 return fetch(request)
129 .then(function(response) { return response.text(); }) 129 .then(function(response) { return response.text(); })
130 .then(evalJsonp) 130 .then(evalJsonp)
131 .then(function(result) { 131 .then(function(result) {
132 assert_equals(result.method, 'POST'); 132 assert_equals(result.method, 'POST');
133 assert_equals(result.body, 'Test String'); 133 assert_equals(result.body, 'Test String');
134 }); 134 });
135 }, 'Fetch with string body test'); 135 }, 'Fetch with string body test');
136 136
137 sequential_promise_test(function(t) { 137 promise_test(function(t) {
138 var text = 'Test ArrayBuffer'; 138 var text = 'Test ArrayBuffer';
139 var array = new Uint8Array(text.length); 139 var array = new Uint8Array(text.length);
140 for (var i = 0; i < text.length; ++i) 140 for (var i = 0; i < text.length; ++i)
141 array[i] = text.charCodeAt(i); 141 array[i] = text.charCodeAt(i);
142 var request = new Request( 142 var request = new Request(
143 '/serviceworker/resources/fetch-access-control.php', 143 '/serviceworker/resources/fetch-access-control.php',
144 {method: 'POST', body: array.buffer}); 144 {method: 'POST', body: array.buffer});
145 return fetch(request) 145 return fetch(request)
146 .then(function(response) { return response.text(); }) 146 .then(function(response) { return response.text(); })
147 .then(evalJsonp) 147 .then(evalJsonp)
148 .then(function(result) { 148 .then(function(result) {
149 assert_equals(result.method, 'POST'); 149 assert_equals(result.method, 'POST');
150 assert_equals(result.body, 'Test ArrayBuffer'); 150 assert_equals(result.body, 'Test ArrayBuffer');
151 }); 151 });
152 }, 'Fetch with ArrayBuffer body test'); 152 }, 'Fetch with ArrayBuffer body test');
153 153
154 sequential_promise_test(function(t) { 154 promise_test(function(t) {
155 var text = 'Test ArrayBufferView'; 155 var text = 'Test ArrayBufferView';
156 var array = new Uint8Array(text.length); 156 var array = new Uint8Array(text.length);
157 for (var i = 0; i < text.length; ++i) 157 for (var i = 0; i < text.length; ++i)
158 array[i] = text.charCodeAt(i); 158 array[i] = text.charCodeAt(i);
159 var request = new Request( 159 var request = new Request(
160 '/serviceworker/resources/fetch-access-control.php', 160 '/serviceworker/resources/fetch-access-control.php',
161 {method: 'POST', body: array}); 161 {method: 'POST', body: array});
162 return fetch(request) 162 return fetch(request)
163 .then(function(response) { return response.text(); }) 163 .then(function(response) { return response.text(); })
164 .then(evalJsonp) 164 .then(evalJsonp)
165 .then(function(result) { 165 .then(function(result) {
166 assert_equals(result.method, 'POST'); 166 assert_equals(result.method, 'POST');
167 assert_equals(result.body, 'Test ArrayBufferView'); 167 assert_equals(result.body, 'Test ArrayBufferView');
168 }); 168 });
169 }, 'Fetch with ArrayBufferView body test'); 169 }, 'Fetch with ArrayBufferView body test');
170 170
171 sequential_promise_test(function(t) { 171 promise_test(function(t) {
172 var formData = new FormData(); 172 var formData = new FormData();
173 formData.append('StringKey1', '1234567890'); 173 formData.append('StringKey1', '1234567890');
174 formData.append('StringKey2', 'ABCDEFGHIJ'); 174 formData.append('StringKey2', 'ABCDEFGHIJ');
175 formData.append('BlobKey', new Blob(['blob content'])); 175 formData.append('BlobKey', new Blob(['blob content']));
176 formData.append('FileKey', 176 formData.append('FileKey',
177 new File(['file content'], 'file.dat')); 177 new File(['file content'], 'file.dat'));
178 var request = new Request( 178 var request = new Request(
179 '/serviceworker/resources/fetch-access-control.php', 179 '/serviceworker/resources/fetch-access-control.php',
180 {method: 'POST', body: formData}); 180 {method: 'POST', body: formData});
181 return fetch(request) 181 return fetch(request)
(...skipping 20 matching lines...) Expand all
202 function runInfiniteFetchLoop() { 202 function runInfiniteFetchLoop() {
203 fetch('dummy.html') 203 fetch('dummy.html')
204 .then(function() { runInfiniteFetchLoop(); }); 204 .then(function() { runInfiniteFetchLoop(); });
205 } 205 }
206 runInfiniteFetchLoop(); 206 runInfiniteFetchLoop();
207 }, 207 },
208 'Destroying the execution context while fetch is happening should not ' + 208 'Destroying the execution context while fetch is happening should not ' +
209 'cause a crash.'); 209 'cause a crash.');
210 210
211 done(); 211 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698