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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/fetch-worker.js

Issue 555443002: [Fetch API] Put body members directly on Response/Request (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated yhirano's comment Created 6 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 importScripts('worker-test-harness.js'); 1 importScripts('worker-test-harness.js');
2 importScripts('test-helpers.js'); 2 importScripts('test-helpers.js');
3 3
4 async_test(function(t) { 4 async_test(function(t) {
5 fetch('http://') 5 fetch('http://')
6 .then( 6 .then(
7 unreached_rejection(t, 'fetch of invalid URL must fail'), 7 unreached_rejection(t, 'fetch of invalid URL must fail'),
8 function(e) { 8 function(e) {
9 assert_equals(e.message, 'Invalid URL'); 9 assert_equals(e.message, 'Invalid URL');
10 t.done(); 10 t.done();
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 async_test(function(t) { 43 async_test(function(t) {
44 var request = 44 var request =
45 new Request('fetch-access-control.php', 45 new Request('fetch-access-control.php',
46 { 46 {
47 method: 'POST', 47 method: 'POST',
48 body: new Blob(['Test Blob'], {type: 'test/type'}) 48 body: new Blob(['Test Blob'], {type: 'test/type'})
49 }); 49 });
50 fetch(request) 50 fetch(request)
51 .then(function(response) { return response.body.asText(); }) 51 .then(function(response) { return response.text(); })
52 .then(evalJsonp) 52 .then(evalJsonp)
53 .then(function(result) { 53 .then(function(result) {
54 assert_equals(result.method, 'POST'); 54 assert_equals(result.method, 'POST');
55 assert_equals(result.body, 'Test Blob'); 55 assert_equals(result.body, 'Test Blob');
56 t.done(); 56 t.done();
57 }) 57 })
58 .catch(unreached_rejection(t)); 58 .catch(unreached_rejection(t));
59 }, 'Fetch with Blob body test in ServiceWorkerGlobalScope'); 59 }, 'Fetch with Blob body test in ServiceWorkerGlobalScope');
60 60
61 async_test(function(t) { 61 async_test(function(t) {
62 var request = new Request('fetch-access-control.php', 62 var request = new Request('fetch-access-control.php',
63 {method: 'POST', body: 'Test String'}); 63 {method: 'POST', body: 'Test String'});
64 fetch(request) 64 fetch(request)
65 .then(function(response) { return response.body.asText(); }) 65 .then(function(response) { return response.text(); })
66 .then(evalJsonp) 66 .then(evalJsonp)
67 .then(function(result) { 67 .then(function(result) {
68 assert_equals(result.method, 'POST'); 68 assert_equals(result.method, 'POST');
69 assert_equals(result.body, 'Test String'); 69 assert_equals(result.body, 'Test String');
70 t.done(); 70 t.done();
71 }) 71 })
72 .catch(unreached_rejection(t)); 72 .catch(unreached_rejection(t));
73 }, 'Fetch with string body test in ServiceWorkerGlobalScope'); 73 }, 'Fetch with string body test in ServiceWorkerGlobalScope');
74 74
75 async_test(function(t) { 75 async_test(function(t) {
76 var text = "Test ArrayBuffer"; 76 var text = "Test ArrayBuffer";
77 var array = new Uint8Array(text.length); 77 var array = new Uint8Array(text.length);
78 for (var i = 0; i < text.length; ++i) 78 for (var i = 0; i < text.length; ++i)
79 array[i] = text.charCodeAt(i); 79 array[i] = text.charCodeAt(i);
80 var request = new Request('fetch-access-control.php', 80 var request = new Request('fetch-access-control.php',
81 {method: 'POST', body: array.buffer}); 81 {method: 'POST', body: array.buffer});
82 fetch(request) 82 fetch(request)
83 .then(function(response) { return response.body.asText(); }) 83 .then(function(response) { return response.text(); })
84 .then(evalJsonp) 84 .then(evalJsonp)
85 .then(function(result) { 85 .then(function(result) {
86 assert_equals(result.method, 'POST'); 86 assert_equals(result.method, 'POST');
87 assert_equals(result.body, 'Test ArrayBuffer'); 87 assert_equals(result.body, 'Test ArrayBuffer');
88 t.done(); 88 t.done();
89 }) 89 })
90 .catch(unreached_rejection(t)); 90 .catch(unreached_rejection(t));
91 }, 'Fetch with ArrayBuffer body test in ServiceWorkerGlobalScope'); 91 }, 'Fetch with ArrayBuffer body test in ServiceWorkerGlobalScope');
92 92
93 async_test(function(t) { 93 async_test(function(t) {
94 var text = "Test ArrayBufferView"; 94 var text = "Test ArrayBufferView";
95 var array = new Uint8Array(text.length); 95 var array = new Uint8Array(text.length);
96 for (var i = 0; i < text.length; ++i) 96 for (var i = 0; i < text.length; ++i)
97 array[i] = text.charCodeAt(i); 97 array[i] = text.charCodeAt(i);
98 var request = new Request('fetch-access-control.php', 98 var request = new Request('fetch-access-control.php',
99 {method: 'POST', body: array}); 99 {method: 'POST', body: array});
100 fetch(request) 100 fetch(request)
101 .then(function(response) { return response.body.asText(); }) 101 .then(function(response) { return response.text(); })
102 .then(evalJsonp) 102 .then(evalJsonp)
103 .then(function(result) { 103 .then(function(result) {
104 assert_equals(result.method, 'POST'); 104 assert_equals(result.method, 'POST');
105 assert_equals(result.body, 'Test ArrayBufferView'); 105 assert_equals(result.body, 'Test ArrayBufferView');
106 t.done(); 106 t.done();
107 }) 107 })
108 .catch(unreached_rejection(t)); 108 .catch(unreached_rejection(t));
109 }, 'Fetch with ArrayBufferView body test in ServiceWorkerGlobalScope'); 109 }, 'Fetch with ArrayBufferView body test in ServiceWorkerGlobalScope');
110 110
111 async_test(function(t) { 111 async_test(function(t) {
112 var formData = new FormData(); 112 var formData = new FormData();
113 formData.append('StringKey1', '1234567890'); 113 formData.append('StringKey1', '1234567890');
114 formData.append('StringKey2', 'ABCDEFGHIJ'); 114 formData.append('StringKey2', 'ABCDEFGHIJ');
115 formData.append('BlobKey', new Blob(['blob content'])); 115 formData.append('BlobKey', new Blob(['blob content']));
116 formData.append('FileKey', 116 formData.append('FileKey',
117 new File(['file content'], 'file.dat')); 117 new File(['file content'], 'file.dat'));
118 var request = new Request('fetch-access-control.php', 118 var request = new Request('fetch-access-control.php',
119 {method: 'POST', body: formData}); 119 {method: 'POST', body: formData});
120 fetch(request) 120 fetch(request)
121 .then(function(response) { return response.body.asText(); }) 121 .then(function(response) { return response.text(); })
122 .then(evalJsonp) 122 .then(evalJsonp)
123 .then(function(result) { 123 .then(function(result) {
124 assert_equals(result.method, 'POST'); 124 assert_equals(result.method, 'POST');
125 assert_equals(result.post['StringKey1'], '1234567890'); 125 assert_equals(result.post['StringKey1'], '1234567890');
126 assert_equals(result.post['StringKey2'], 'ABCDEFGHIJ'); 126 assert_equals(result.post['StringKey2'], 'ABCDEFGHIJ');
127 var files = []; 127 var files = [];
128 for (var i = 0; i < result.files.length; ++i) { 128 for (var i = 0; i < result.files.length; ++i) {
129 files[result.files[i].key] = result.files[i]; 129 files[result.files[i].key] = result.files[i];
130 } 130 }
131 assert_equals(files['BlobKey'].content, 'blob content'); 131 assert_equals(files['BlobKey'].content, 'blob content');
132 assert_equals(files['BlobKey'].name, 'blob'); 132 assert_equals(files['BlobKey'].name, 'blob');
133 assert_equals(files['BlobKey'].size, 12); 133 assert_equals(files['BlobKey'].size, 12);
134 assert_equals(files['FileKey'].content, 'file content'); 134 assert_equals(files['FileKey'].content, 'file content');
135 assert_equals(files['FileKey'].name, 'file.dat'); 135 assert_equals(files['FileKey'].name, 'file.dat');
136 assert_equals(files['FileKey'].size, 12); 136 assert_equals(files['FileKey'].size, 12);
137 t.done(); 137 t.done();
138 }) 138 })
139 .catch(unreached_rejection(t)); 139 .catch(unreached_rejection(t));
140 }, 'Fetch with FormData body test in ServiceWorkerGlobalScope'); 140 }, 'Fetch with FormData body test in ServiceWorkerGlobalScope');
141 141
142 test(function(t) { 142 test(function(t) {
143 function runInfiniteFetchLoop() { 143 function runInfiniteFetchLoop() {
144 fetch('dummy.html') 144 fetch('dummy.html')
145 .then(function() { runInfiniteFetchLoop(); }); 145 .then(function() { runInfiniteFetchLoop(); });
146 } 146 }
147 runInfiniteFetchLoop(); 147 runInfiniteFetchLoop();
148 }, 148 },
149 'Destroying the execution context while fetch is happening should not ' + 149 'Destroying the execution context while fetch is happening should not ' +
150 'cause a crash.'); 150 'cause a crash.');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698