OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 chrome.test.runTests([ | 5 chrome.test.runTests([ |
6 function addListeners() { | 6 function addListeners() { |
7 chrome.webRequest.onBeforeRequest.addListener( | 7 chrome.webRequest.onBeforeRequest.addListener( |
8 function(details) {}, {urls: ["<all_urls>"]}); | 8 function(details) {}, {urls: ["<all_urls>"]}); |
9 chrome.webRequest.onBeforeSendHeaders.addListener( | 9 chrome.webRequest.onBeforeSendHeaders.addListener( |
10 function(details) {}, {urls: ["<all_urls>"]}); | 10 function(details) {}, {urls: ["<all_urls>"]}); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 {types: ["xmlhttprequest"], urls: ["*://*/*"]}, | 134 {types: ["xmlhttprequest"], urls: ["*://*/*"]}, |
135 ["blocking", "responseHeaders"]); | 135 ["blocking", "responseHeaders"]); |
136 | 136 |
137 chrome.test.getConfig(function(config) { | 137 chrome.test.getConfig(function(config) { |
138 var url = 'http://127.0.0.1:' + config.testServer.port + '/simple.html'; | 138 var url = 'http://127.0.0.1:' + config.testServer.port + '/simple.html'; |
139 var xhr = new XMLHttpRequest(); | 139 var xhr = new XMLHttpRequest(); |
140 xhr.open('GET', url); | 140 xhr.open('GET', url); |
141 xhr.onload = function() { | 141 xhr.onload = function() { |
142 chrome.webRequest.onHeadersReceived.removeListener( | 142 chrome.webRequest.onHeadersReceived.removeListener( |
143 callbackWithBadHeadersResponse); | 143 callbackWithBadHeadersResponse); |
144 | 144 var responseHeaders = xhr.getAllResponseHeaders() || ''; |
145 chrome.test.fail(); | 145 chrome.test.assertTrue( |
146 }; | 146 responseHeaders.indexOf('X-Header-With-Invalid-Value') === -1); |
147 xhr.onerror = function() { | |
148 chrome.webRequest.onHeadersReceived.removeListener( | |
149 callbackWithBadHeadersResponse); | |
150 // When the returned header is invalid, the request should be canceled. | |
151 // TODO(robwu): If possible, check whether an error with the following | 147 // TODO(robwu): If possible, check whether an error with the following |
152 // message has been logged to the JavaScript console: | 148 // message has been logged to the JavaScript console: |
153 // "Header 'X-Header-With-Invalid-Value' has an invalid value" | 149 // "Header 'X-Header-With-Invalid-Value' has an invalid value" |
154 chrome.test.succeed(); | 150 chrome.test.succeed(); |
155 }; | 151 }; |
| 152 xhr.onerror = function() { |
| 153 chrome.webRequest.onHeadersReceived.removeListener( |
| 154 callbackWithBadHeadersResponse); |
| 155 chrome.test.fail(); |
| 156 }; |
156 xhr.send(); | 157 xhr.send(); |
157 }); | 158 }); |
158 } | 159 } |
159 ]); | 160 ]); |
OLD | NEW |