| OLD | NEW |
| (Empty) |
| 1 if (self.importScripts) { | |
| 2 importScripts('../resources/fetch-test-helpers.js'); | |
| 3 } | |
| 4 | |
| 5 promise_test(function() { | |
| 6 var lastModified = ''; | |
| 7 var eTag = ''; | |
| 8 var url = '../resources/doctype.html'; | |
| 9 var expectedText = '<!DOCTYPE html>\n'; | |
| 10 return fetch(url) | |
| 11 .then(function(res) { | |
| 12 lastModified = res.headers.get('last-modified'); | |
| 13 eTag = res.headers.get('etag'); | |
| 14 assert_not_equals(lastModified, '', 'last-modified must be set.'); | |
| 15 assert_not_equals(eTag, '', 'eTag must be set.'); | |
| 16 | |
| 17 return fetch(url); | |
| 18 }) | |
| 19 .then(function(res) { | |
| 20 assert_equals(res.status, 200, | |
| 21 'Automatically cached response status must be 200.'); | |
| 22 return res.text(); | |
| 23 }) | |
| 24 .then(function(text) { | |
| 25 assert_equals( | |
| 26 text, expectedText, | |
| 27 'Automatically cached response body must be correct.'); | |
| 28 | |
| 29 return fetch(url, | |
| 30 { headers: [['If-Modified-Since', lastModified]] }); | |
| 31 }) | |
| 32 .then(function(res) { | |
| 33 assert_equals( | |
| 34 res.status, 304, | |
| 35 'When If-Modified-Since is overridden, the response status must ' + | |
| 36 'be 304.'); | |
| 37 return res.text(); | |
| 38 }) | |
| 39 .then(function(text) { | |
| 40 assert_equals( | |
| 41 text, '', | |
| 42 'When If-Modified-Since is overridden, the response body must be' + | |
| 43 ' empty.'); | |
| 44 | |
| 45 return fetch(url, | |
| 46 { headers: [['If-Modified-Since', | |
| 47 'Tue, 01 Jan 1980 01:00:00 GMT']] }); | |
| 48 }) | |
| 49 .then(function(res) { | |
| 50 assert_equals( | |
| 51 res.status, 200, | |
| 52 'When If-Modified-Since is overridden, the modified response ' + | |
| 53 'status must be 200.'); | |
| 54 return res.text(); | |
| 55 }) | |
| 56 .then(function(text) { | |
| 57 assert_equals( | |
| 58 text, expectedText, | |
| 59 'When If-Modified-Since is overridden, the modified response body' + | |
| 60 ' must be correct.'); | |
| 61 | |
| 62 return fetch(url, | |
| 63 { headers: [['If-Unmodified-Since', lastModified]] }); | |
| 64 }) | |
| 65 .then(function(res) { | |
| 66 assert_equals( | |
| 67 res.status, 200, | |
| 68 'When If-Unmodified-Since is overridden, the modified response ' + | |
| 69 'status must be 200.'); | |
| 70 return res.text(); | |
| 71 }) | |
| 72 .then(function(text) { | |
| 73 assert_equals( | |
| 74 text, expectedText, | |
| 75 'When If-Unmodified-Since is overridden, the modified response ' + | |
| 76 'body must be correct.'); | |
| 77 | |
| 78 return fetch(url, | |
| 79 { headers: [['If-Unmodified-Since', | |
| 80 'Tue, 01 Jan 1980 01:00:00 GMT']] }); | |
| 81 }) | |
| 82 .then(function(res) { | |
| 83 assert_equals( | |
| 84 res.status, 412, | |
| 85 'When If-Unmodified is overridden, the modified response status ' + | |
| 86 'must be 412.'); | |
| 87 return res.text(); | |
| 88 }) | |
| 89 .then(function(text) { | |
| 90 assert_equals( | |
| 91 text, '', | |
| 92 'When If-Unmodified is overridden, the modified response body ' + | |
| 93 'must be empty.'); | |
| 94 | |
| 95 return fetch(url, | |
| 96 { headers: [['If-Match', eTag]] }); | |
| 97 }) | |
| 98 .then(function(res) { | |
| 99 assert_equals( | |
| 100 res.status, 200, | |
| 101 'When If-Match is overridden, the response status must be 200.'); | |
| 102 return res.text(); | |
| 103 }) | |
| 104 .then(function(text) { | |
| 105 assert_equals( | |
| 106 text, expectedText, | |
| 107 'When If-Match is overridden, the response body must be correct.'); | |
| 108 | |
| 109 // FIXME: We used to have a test of If-Match overridden with an | |
| 110 // invalid etag, but removed due to broken If-Match handling of | |
| 111 // Apache 2.4. See crbug.com/423070 | |
| 112 | |
| 113 return fetch(url, | |
| 114 { headers: [['If-None-Match', eTag]] }); | |
| 115 }) | |
| 116 .then(function(res) { | |
| 117 assert_equals( | |
| 118 res.status, 304, | |
| 119 'When If-None-Match is overridden, the response status must be ' + | |
| 120 '304.'); | |
| 121 return res.text(); | |
| 122 }) | |
| 123 .then(function(text) { | |
| 124 assert_equals( | |
| 125 text, '', | |
| 126 'When If-None-Match is overridden, the response body must be ' + | |
| 127 'empty.'); | |
| 128 | |
| 129 return fetch(url, | |
| 130 { headers: [['If-None-Match', 'xyzzy']] }); | |
| 131 }) | |
| 132 .then(function(res) { | |
| 133 assert_equals( | |
| 134 res.status, 200, | |
| 135 'When If-None-Match is overridden to the invalid tag, the ' + | |
| 136 'response status must be 200.'); | |
| 137 return res.text(); | |
| 138 }) | |
| 139 .then(function(text) { | |
| 140 assert_equals( | |
| 141 text, expectedText, | |
| 142 'When If-None-Match is overridden to the invalid tag, the ' + | |
| 143 'response body must be correct.'); | |
| 144 | |
| 145 return fetch(url, | |
| 146 { headers: [['If-Range', eTag], | |
| 147 ['Range', 'bytes=10-30']] }); | |
| 148 }) | |
| 149 .then(function(res) { | |
| 150 assert_equals( | |
| 151 res.status, 206, | |
| 152 'When If-Range is overridden, the response status must be 206.'); | |
| 153 return res.text(); | |
| 154 }) | |
| 155 .then(function(text) { | |
| 156 assert_equals( | |
| 157 text, expectedText.substring(10, 31), | |
| 158 'When If-Range is overridden, the response body must be correct.'); | |
| 159 | |
| 160 return fetch(url, | |
| 161 { headers: [['If-Range', 'xyzzy'], | |
| 162 ['Range', 'bytes=10-30']] }); | |
| 163 }) | |
| 164 .then(function(res) { | |
| 165 assert_equals( | |
| 166 res.status, 200, | |
| 167 'When If-Range is overridden to the invalid tag, the response ' + | |
| 168 'status must be 200.'); | |
| 169 return res.text(); | |
| 170 }) | |
| 171 .then(function(text) { | |
| 172 assert_equals( | |
| 173 text, expectedText, | |
| 174 'When If-Range is overridden to the invalid tag, the response ' + | |
| 175 'body must be correct.'); | |
| 176 | |
| 177 return fetch('../resources/fetch-status.php?status=304'); | |
| 178 }) | |
| 179 .then(function(res) { | |
| 180 assert_equals( | |
| 181 res.status, 304 , | |
| 182 'When the server returns 304 and there\'s a cache miss, the ' + | |
| 183 'response status must be 304.'); | |
| 184 }); | |
| 185 }, '304 handling for fetch().'); | |
| 186 | |
| 187 done(); | |
| OLD | NEW |