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