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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/fetch-body-mixin-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 self.onmessage = function(e) { 1 self.onmessage = function(e) {
2 var message = e.data; 2 var message = e.data;
3 if ('port' in message) { 3 if ('port' in message) {
4 port = message.port; 4 port = message.port;
5 doTextTest(port); 5 doTextTest(port);
6 } 6 }
7 }; 7 };
8 8
9 function quit(port) { 9 function quit(port) {
10 port.postMessage('quit'); 10 port.postMessage('quit');
11 } 11 }
12 12
13 function doFetchTwiceTest(port) { 13 function doFetchTwiceTest(port) {
14 var p1Out = p2Out = null; 14 var p1Out = p2Out = null;
15 15
16 fetch('doctype.html') 16 fetch('doctype.html')
17 .then(function(response) { 17 .then(function(response) {
18 var p1 = response.body.asText(); 18 var p1 = response.text();
19 var p2 = response.body.asText(); 19 var p2 = response.text();
20 20
21 p1.then(function(obj) { 21 p1.then(function(obj) {
22 p1Out = obj; 22 p1Out = obj;
23 if (p2Out) { 23 if (p2Out) {
24 complete(); 24 complete();
25 } 25 }
26 }); 26 });
27 p2.catch(function(e) { 27 p2.catch(function(e) {
28 p2Out = e; 28 p2Out = e;
29 if (p1Out) { 29 if (p1Out) {
30 complete(); 30 complete();
31 } 31 }
32 }); 32 });
33 }); 33 });
34 34
35 function complete() { 35 function complete() {
36 port.postMessage(p1Out + ' : ' + p2Out.name); 36 port.postMessage(p1Out + ' : ' + p2Out.name);
37 quit(port); 37 quit(port);
38 } 38 }
39 } 39 }
40 40
41 function doArrayBufferTest(port) { 41 function doArrayBufferTest(port) {
42 fetch('doctype.html') 42 fetch('doctype.html')
43 .then(function(response) { 43 .then(function(response) {
44 response.body.asArrayBuffer() 44 response.arrayBuffer()
45 .then(function(b) { 45 .then(function(b) {
46 port.postMessage('ArrayBuffer: ' + b.byteLength); 46 port.postMessage('ArrayBuffer: ' + b.byteLength);
47 doFetchTwiceTest(port); 47 doFetchTwiceTest(port);
48 }); 48 });
49 }); 49 });
50 } 50 }
51 51
52 function doBlobTest(port) { 52 function doBlobTest(port) {
53 fetch('doctype.html') 53 fetch('doctype.html')
54 .then(function(response) { 54 .then(function(response) {
55 response.body.asBlob() 55 response.blob()
56 .then(function(blob) { 56 .then(function(blob) {
57 port.postMessage('Blob: ' + blob.size + " : " + blob.type); 57 port.postMessage('Blob: ' + blob.size + " : " + blob.type);
58 doArrayBufferTest(port); 58 doArrayBufferTest(port);
59 }); 59 });
60 }); 60 });
61 } 61 }
62 62
63 function doJSONFailedTest(port) { 63 function doJSONFailedTest(port) {
64 fetch('doctype.html') 64 fetch('doctype.html')
65 .then(function(response) { 65 .then(function(response) {
66 response.body.asJSON() 66 response.json()
67 .catch(function(e) { 67 .catch(function(e) {
68 port.postMessage('JSON: ' + e.name); 68 port.postMessage('JSON: ' + e.name);
69 doBlobTest(port); 69 doBlobTest(port);
70 }); 70 });
71 }); 71 });
72 } 72 }
73 73
74 function doJSONTest(port) { 74 function doJSONTest(port) {
75 fetch('simple.json') 75 fetch('simple.json')
76 .then(function(response) { 76 .then(function(response) {
77 response.body.asJSON() 77 response.json()
78 .then(function(json) { 78 .then(function(json) {
79 port.postMessage('JSON: ' + json['a'] + ' ' + json['b']); 79 port.postMessage('JSON: ' + json['a'] + ' ' + json['b']);
80 doJSONFailedTest(port); 80 doJSONFailedTest(port);
81 }); 81 });
82 }); 82 });
83 } 83 }
84 84
85 function doTextTest(port) { 85 function doTextTest(port) {
86 fetch('doctype.html') 86 fetch('doctype.html')
87 .then(function(response) { 87 .then(function(response) {
88 response.body.asText() 88 response.text()
89 .then(function(txt) { 89 .then(function(txt) {
90 port.postMessage('Text: ' + txt); 90 port.postMessage('Text: ' + txt);
91 doJSONTest(port); 91 doJSONTest(port);
92 }); 92 });
93 }); 93 });
94 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698