| OLD | NEW |
| 1 importScripts('worker-test-helpers.js'); | 1 importScripts('worker-test-helpers.js'); |
| 2 | 2 |
| 3 test(function() { | 3 test(function() { |
| 4 var response = new Response(new Blob()); | 4 var headers = new HeaderMap; |
| 5 assert_equals(response.type, 'default', 'Default Response.type should be \'d
efault\''); | |
| 6 assert_equals(response.url, '', 'Response.url should be the empty string'); | |
| 7 assert_equals(response.status, 200, 'Default Response.status should be 200')
; | |
| 8 assert_equals(response.statusText, 'OK', 'Default Response.statusText should
be \'OK\''); | |
| 9 assert_equals(response.headers.size, 1, 'Default Response should have one he
ader.'); | |
| 10 assert_equals(response.headers.get('content-type'), '', 'Default Response sh
ould have one header which name is \'content-type\' and value is an empty string
.'); | |
| 11 | |
| 12 response.status = 394; | |
| 13 response.statusText = 'Sesame Street'; | |
| 14 assert_equals(response.status, 200, 'Response.status should be readonly'); | |
| 15 assert_equals(response.statusText, 'OK', 'Response.statusText should be read
only'); | |
| 16 }, 'Response default value test in ServiceWorkerGlobalScope'); | |
| 17 | |
| 18 test(function() { | |
| 19 var headers = new Headers; | |
| 20 headers.set('Content-Language', 'ja'); | 5 headers.set('Content-Language', 'ja'); |
| 21 headers.set('Content-Type', 'text/html; charset=UTF-8'); | 6 headers.set('Content-Type', 'text/html; charset=UTF-8'); |
| 22 headers.set('X-ServiceWorker-Test', 'response test field'); | 7 headers.set('X-ServiceWorker-Test', 'response test field'); |
| 23 headers.set('Set-Cookie', 'response test set-cookie'); | |
| 24 headers.set('Set-Cookie2', 'response test set-cookie2'); | |
| 25 | 8 |
| 26 var responses = | 9 var response = new Response(new Blob(), { |
| 27 [new Response(new Blob(), | 10 status: 303, |
| 28 {status: 303, statusText: 'See Other', headers: headers}), | 11 statusText: 'See Other', |
| 29 new Response(new Blob(), | 12 headers: headers |
| 30 { | |
| 31 status: 303, | |
| 32 statusText: 'See Other', | |
| 33 headers: {'Content-Language': 'ja', | |
| 34 'Content-Type': 'text/html; charset=UTF-8', | |
| 35 'X-ServiceWorker-Test': 'response test field
', | |
| 36 'Set-Cookie': 'response test set-cookie', | |
| 37 'Set-Cookie2': 'response test set-cookie2'} | |
| 38 }), | |
| 39 new Response(new Blob(), | |
| 40 { | |
| 41 status: 303, | |
| 42 statusText: 'See Other', | |
| 43 headers: [['Content-Language', 'ja'], | |
| 44 ['Content-Type', 'text/html; charset=UTF-8']
, | |
| 45 ['X-ServiceWorker-Test', 'response test fiel
d'], | |
| 46 ['Set-Cookie', 'response test set-cookie'], | |
| 47 ['Set-Cookie2', 'response test set-cookie2']
] | |
| 48 })]; | |
| 49 responses.forEach(function(response) { | |
| 50 assert_equals(response.status, 303, 'Response.status should match'); | |
| 51 assert_equals(response.statusText, 'See Other', 'Response.statusText sho
uld match'); | |
| 52 assert_true(response.headers instanceof Headers, 'Response.headers shoul
d be Headers'); | |
| 53 assert_equals(response.headers.size, 3, 'Response.headers.size should ma
tch'); | |
| 54 assert_equals(response.headers.get('Content-Language'), 'ja', | |
| 55 'Content-Language of Response.headers should match'); | |
| 56 assert_equals(response.headers.get('Content-Type'), 'text/html; charset=
UTF-8', | |
| 57 'Content-Type of Response.headers should match'); | |
| 58 assert_equals(response.headers.get('X-ServiceWorker-Test'), 'response te
st field', | |
| 59 'X-ServiceWorker-Test of Response.headers should match'); | |
| 60 response.headers.set('X-ServiceWorker-Test2', 'response test field2'); | |
| 61 assert_equals(response.headers.size, 4, 'Response.headers.size should in
crease by 1.'); | |
| 62 assert_equals(response.headers.get('X-ServiceWorker-Test2'), 'response t
est field2', | |
| 63 'Response.headers should be added'); | |
| 64 response.headers.set('set-cookie', 'dummy'); | |
| 65 response.headers.set('sEt-cookie', 'dummy'); | |
| 66 response.headers.set('set-cookie2', 'dummy'); | |
| 67 response.headers.set('set-cOokie2', 'dummy'); | |
| 68 response.headers.append('set-cookie', 'dummy'); | |
| 69 response.headers.append('sEt-cookie', 'dummy'); | |
| 70 response.headers.append('set-cookie2', 'dummy'); | |
| 71 response.headers.append('set-cOokie2', 'dummy'); | |
| 72 assert_equals(response.headers.size, 4, | |
| 73 'Response.headers should not accept Set-Cookie nor Set-Coo
kie2'); | |
| 74 response.headers.delete('X-ServiceWorker-Test'); | |
| 75 assert_equals(response.headers.size, 3, 'Response.headers.size should de
crease by 1.'); | |
| 76 }); | |
| 77 // Note: detailed behavioral tests for Headers are in another test, | |
| 78 // http/tests/serviceworker/headers.html. | |
| 79 }, 'Response constructor test in ServiceWorkerGlobalScope'); | |
| 80 | |
| 81 test(function() { | |
| 82 var response = new Response(new Blob(['dummy'], {type :'audio/wav'})); | |
| 83 assert_equals(response.headers.size, 1, 'Response.headers should have Conten
t-Type'); | |
| 84 assert_equals(response.headers.get('Content-Type'), 'audio/wav', | |
| 85 'Content-Type of Response.headers should be set'); | |
| 86 | |
| 87 response = new Response(new Blob(['dummy'], {type :'audio/wav'}), | |
| 88 {headers:{'Content-Type': 'text/html; charset=UTF-8'
}}); | |
| 89 assert_equals(response.headers.size, 1, 'Response.headers should have Conten
t-Type'); | |
| 90 assert_equals(response.headers.get('Content-Type'), 'text/html; charset=UTF-
8', | |
| 91 'Content-Type of Response.headers should be overridden'); | |
| 92 }, 'Response content type test in ServiceWorkerGlobalScope'); | |
| 93 | |
| 94 test(function() { | |
| 95 [0, 1, 100, 199, 600, 700].forEach(function(status) { | |
| 96 assert_throws({name:'RangeError'}, | |
| 97 function() { new Response(new Blob(), {status: status}); }
, | |
| 98 'new Response with status = ' + status + ' should throw'); | |
| 99 }); | |
| 100 [200, 300, 400, 500, 599].forEach(function(status) { | |
| 101 var response = new Response(new Blob(), {status: status}); | |
| 102 assert_equals(response.status, status, 'Response.status should match'); | |
| 103 }); | 13 }); |
| 104 | 14 |
| 105 var invalidNames = ['', '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', | 15 assert_equals(response.status, 303, 'Response.status should match'); |
| 106 '/', '[', ']', '?', '=', '{', '}', '\u3042', 'a(b']; | 16 assert_equals(response.statusText, 'See Other', 'Response.statusText should
match'); |
| 107 invalidNames.forEach(function(name) { | 17 assert_true(response.headers instanceof HeaderMap, 'Response.headers should
be HeaderMap'); |
| 108 assert_throws({name:'TypeError'}, | 18 assert_equals(response.headers.size, 3, 'Response.headers.size should match'
); |
| 109 function() { | 19 // Note: detailed behavioral tests for HeaderMap are in another test, |
| 110 var obj = {}; | 20 // http/tests/serviceworker/headermap.html. |
| 111 obj[name] = 'a'; | 21 |
| 112 new Response(new Blob(), {headers: obj}); | 22 response.status = 123; |
| 113 }, | 23 response.statusText = 'Sesame Street'; |
| 114 'new Response with headers with an invalid name (' + name
+') should throw'); | 24 assert_equals(response.status, 123, 'Response.status should be writable'); |
| 115 assert_throws({name:'TypeError'}, | 25 assert_equals(response.statusText, 'Sesame Street', 'Response.statusText sho
uld be writable'); |
| 116 function() { | 26 |
| 117 new Response(new Blob(), {headers: [[name, 'a']]}); | 27 assert_throws({name:'TypeError'}, function() { response.statusText = 'invali
d \u0100'; }, |
| 118 }, | 28 'Response.statusText should throw on invalid ByteString'); |
| 119 'new Response with headers with an invalid name (' + name
+') should throw'); | 29 |
| 120 }); | 30 }, 'Response in ServiceWorkerGlobalScope'); |
| 121 var invalidValues = ['test \r data', 'test \n data']; | |
| 122 invalidValues.forEach(function(value) { | |
| 123 assert_throws({name:'TypeError'}, | |
| 124 function() { | |
| 125 new Response(new Blob(), | |
| 126 {headers: {'X-ServiceWorker-Test': value}
}); | |
| 127 }, | |
| 128 'new Response with headers with an invalid value should th
row'); | |
| 129 assert_throws({name:'TypeError'}, | |
| 130 function() { | |
| 131 new Response(new Blob(), | |
| 132 {headers: [['X-ServiceWorker-Test', value
]]}); | |
| 133 }, | |
| 134 'new Response with headers with an invalid value should th
row'); | |
| 135 }); | |
| 136 }, 'Response throw error test in ServiceWorkerGlobalScope'); | |
| OLD | NEW |