OLD | NEW |
1 if ('ServiceWorkerGlobalScope' in self && | 1 if ('ServiceWorkerGlobalScope' in self && |
2 self instanceof ServiceWorkerGlobalScope) { | 2 self instanceof ServiceWorkerGlobalScope) { |
3 // ServiceWorker case | 3 // ServiceWorker case |
4 importScripts('/serviceworker/resources/worker-testharness.js'); | 4 importScripts('/serviceworker/resources/worker-testharness.js'); |
5 importScripts('/serviceworker/resources/test-helpers.js'); | 5 importScripts('/serviceworker/resources/test-helpers.js'); |
6 importScripts('/serviceworker/resources/fetch-test-options.js'); | 6 importScripts('/serviceworker/resources/fetch-test-options.js'); |
7 } else if (self.importScripts) { | 7 } else if (self.importScripts) { |
8 // Other workers cases | 8 // Other workers cases |
9 importScripts('/resources/testharness.js'); | 9 importScripts('/resources/testharness.js'); |
10 importScripts('/serviceworker/resources/test-helpers.js'); | 10 importScripts('/serviceworker/resources/test-helpers.js'); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 var VALID_REASON_PHRASE = [ | 120 var VALID_REASON_PHRASE = [ |
121 '\t', ' ', '"', '(', ')', ',', '/', ':', ';', '<', '=', '>', '?', '@', '[', | 121 '\t', ' ', '"', '(', ')', ',', '/', ':', ';', '<', '=', '>', '?', '@', '[', |
122 '\\', ']', '{', '}', | 122 '\\', ']', '{', '}', |
123 '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~', | 123 '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~', |
124 // non-CHAR | 124 // non-CHAR |
125 '\x80', '\xff', | 125 '\x80', '\xff', |
126 // Valid strings. | 126 // Valid strings. |
127 '', '0123456789', '404 Not Found', 'HTTP/1.1 404 Not Found', 'AZ\u00ffaz', | 127 '', '0123456789', '404 Not Found', 'HTTP/1.1 404 Not Found', 'AZ\u00ffaz', |
128 'x'.repeat(100000)]; | 128 'x'.repeat(100000)]; |
| 129 |
| 130 function testBlockMixedContent(mode) { |
| 131 promise_test(function(t) { |
| 132 return Promise.resolve() |
| 133 .then(function() { |
| 134 // Test 1: Must fail: blocked as mixed content. |
| 135 return fetch(BASE_URL + 'test1-' + mode, {mode: mode}) |
| 136 .then(t.unreached_func('Test 1: Must be blocked (' + |
| 137 mode + ', HTTPS->HTTP)'), |
| 138 function() {}); |
| 139 }) |
| 140 .then(function() { |
| 141 // Block mixed content in redirects. |
| 142 // Test 2: Must fail: original fetch is not blocked but |
| 143 // redirect is blocked. |
| 144 return fetch(HTTPS_REDIRECT_URL + |
| 145 encodeURIComponent(BASE_URL + 'test2-' + mode), |
| 146 {mode: mode}) |
| 147 .then(t.unreached_func('Test 2: Must be blocked (' + |
| 148 mode + ', HTTPS->HTTPS->HTTP)'), |
| 149 function() {}); |
| 150 }) |
| 151 .then(function() { |
| 152 // Test 3: Must fail: original fetch is blocked. |
| 153 return fetch(REDIRECT_URL + |
| 154 encodeURIComponent(HTTPS_BASE_URL + 'test3-' + mode), |
| 155 {mode: mode}) |
| 156 .then(t.unreached_func('Test 3: Must be blocked (' + |
| 157 mode + ', HTTPS->HTTP->HTTPS)'), |
| 158 function() {}); |
| 159 }) |
| 160 .then(function() { |
| 161 // Test 4: Must success. |
| 162 // Test that the mixed contents above are not rejected due to |
| 163 return fetch(HTTPS_REDIRECT_URL + |
| 164 encodeURIComponent(HTTPS_BASE_URL + 'test4-' + mode), |
| 165 {mode: mode}) |
| 166 .then(function(res) {assert_equals(res.status, 200); }, |
| 167 t.unreached_func('Test 4: Must success (' + |
| 168 mode + ', HTTPS->HTTPS->HTTPS)')); |
| 169 }) |
| 170 .then(function() { |
| 171 // Test 5: Must success if mode is not 'same-origin'. |
| 172 // Test that the mixed contents above are not rejected due to |
| 173 // CORS check. |
| 174 return fetch(HTTPS_OTHER_REDIRECT_URL + |
| 175 encodeURIComponent(HTTPS_BASE_URL + 'test5-' + mode), |
| 176 {mode: mode}) |
| 177 .then(function(res) { |
| 178 if (mode === 'same-origin') { |
| 179 assert_unreached( |
| 180 'Test 5: Cross-origin HTTPS request must fail: ' + |
| 181 'mode = ' + mode); |
| 182 } |
| 183 }, |
| 184 function() { |
| 185 if (mode !== 'same-origin') { |
| 186 assert_unreached( |
| 187 'Test 5: Cross-origin HTTPS request must success: ' + |
| 188 'mode = ' + mode); |
| 189 } |
| 190 }); |
| 191 }); |
| 192 }, 'Block fetch() as mixed content (' + mode + ')'); |
| 193 } |
OLD | NEW |