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

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

Issue 1283163003: [Fetch][WIP] Support blob:, about:, and data: URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Cleanup. Created 5 years, 3 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 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 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 // Tests for non-HTTP(S) schemes.
24 promise_test(function(t) {
25 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'}));
26 return fetch(url)
27 .then(function(response) {
28 assert_equals(response.status, 200);
29 assert_equals(response.statusText, 'OK');
30 assert_equals(response.headers.get('Content-Type'), 'text/fox');
31 assert_equals(response.headers.get('Content-Length'), '3');
32 assert_equals(size(response.headers), 2);
33 return response.text();
34 })
35 .then(function(text) {
36 assert_equals(text, 'fox');
37 });
38 }, 'fetch blob: URL');
39
40 promise_test(function(t) {
41 var url = URL.createObjectURL(new Blob(['fox'], {type: 'text/fox'}));
42 return fetch(url + 'invalid')
43 .then(
44 t.unreached_func('fetching non-existent blob: URL must fail'),
45 function() {});
46 }, 'fetch non-existent blob: URL');
47
48 promise_test(function(t) {
49 return fetch('data:,Foobar')
50 .then(function(response) {
51 assert_equals(response.status, 200);
52 assert_equals(response.statusText, 'OK');
53 assert_equals(response.headers.get('Content-Type'),
54 'text/plain;charset=US-ASCII');
55 assert_equals(size(response.headers), 1);
56 return response.text();
57 })
58 .then(function(text) {
59 assert_equals(text, 'Foobar');
60 });
61 }, 'fetch data: URL');
62
63 promise_test(function(t) {
64 return fetch('data:text/html;charset=utf-8;base64,5paH5a2X')
65 .then(function(response) {
66 assert_equals(response.status, 200);
67 assert_equals(response.statusText, 'OK');
68 assert_equals(response.headers.get('Content-Type'),
69 'text/html;charset=utf-8');
70 assert_equals(size(response.headers), 1);
71 return response.text();
72 })
73 .then(function(text) {
74 assert_equals(text, '\u6587\u5b57');
75 });
76 }, 'fetch data: URL with non-ASCII characters');
77
78 promise_test(function(t) {
79 return fetch('data:text/html;base64,***')
80 .then(
81 t.unreached_func('fetching invalid data: URL must fail'),
82 function() {});
83 }, 'fetch invalid data: URL');
84
85 // +disable all cors route
86 // +allow first data: and all about:
87 // data: all OK
88 // Redirect -> data: same-origin: NG / no-cors: OK / cors: NG
89 // about: all OK
90 // Redirect -> about: all OK
91 // blob: same-origin: check / no-cors: check-OK / cors: check-NG
92 // Redirect -> blob: same-origin: NG / no-cors: OK / cors: NG
93
23 // https://fetch.spec.whatwg.org/#concept-basic-fetch 94 // https://fetch.spec.whatwg.org/#concept-basic-fetch
24 // The last statement: 95 // The last statement:
25 // Otherwise 96 // Otherwise
26 // Return a network error. 97 // Return a network error.
27 promise_test(function(t) { 98 promise_test(function(t) {
28 return fetch('foobar://localhost/', {mode: 'no-cors'}) 99 return fetch('foobar://localhost/', {mode: 'no-cors'})
29 .then( 100 .then(
30 t.unreached_func('scheme not listed in basic fetch spec must fail'), 101 t.unreached_func('scheme not listed in basic fetch spec must fail'),
31 function() {}); 102 function() {});
32 }, 'fetch of scheme not listed in basic fetch spec'); 103 }, 'fetch of scheme not listed in basic fetch spec');
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 function runInfiniteFetchLoop() { 358 function runInfiniteFetchLoop() {
288 fetch('dummy.html') 359 fetch('dummy.html')
289 .then(function() { runInfiniteFetchLoop(); }); 360 .then(function() { runInfiniteFetchLoop(); });
290 } 361 }
291 runInfiniteFetchLoop(); 362 runInfiniteFetchLoop();
292 }, 363 },
293 'Destroying the execution context while fetch is happening should not ' + 364 'Destroying the execution context while fetch is happening should not ' +
294 'cause a crash.'); 365 'cause a crash.');
295 366
296 done(); 367 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698