| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 5 /** |
| 6 * Every test needs: | 6 * Every test needs: |
| 7 * - a button in options.html | 7 * - a button in options.html |
| 8 * - a function that runs the test & calls setCompleted when done | 8 * - a function that runs the test & calls setCompleted when done |
| 9 * - a listener registered in setupEvents | 9 * - a listener registered in setupEvents |
| 10 **/ | 10 **/ |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ); | 149 ); |
| 150 window.open('http://www.google.cn'); | 150 window.open('http://www.google.cn'); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Modifies the headers sent and received in an HTTP request using the | 153 // Modifies the headers sent and received in an HTTP request using the |
| 154 // webRequest API. | 154 // webRequest API. |
| 155 function doWebRequestModifications() { | 155 function doWebRequestModifications() { |
| 156 // Install a webRequest handler that will add an HTTP header to the outgoing | 156 // Install a webRequest handler that will add an HTTP header to the outgoing |
| 157 // request for the main page. | 157 // request for the main page. |
| 158 function doModifyHeaders(details) { | 158 function doModifyHeaders(details) { |
| 159 var response = {}; | |
| 160 | |
| 161 var headers = details.requestHeaders; | 159 var headers = details.requestHeaders; |
| 162 if (headers === undefined) { | 160 if (headers === undefined) { |
| 163 headers = []; | 161 headers = []; |
| 164 } | 162 } |
| 165 headers.push({'name': 'X-Test-Activity-Log-Send', | 163 headers.push({'name': 'X-Test-Activity-Log-Send', |
| 166 'value': 'Present'}); | 164 'value': 'Present'}); |
| 167 response['requestHeaders'] = headers; | 165 return {'requestHeaders': headers}; |
| 168 | |
| 169 headers = details.responseHeaders; | |
| 170 if (headers === undefined) { | |
| 171 headers = []; | |
| 172 } | |
| 173 headers = headers.filter( | |
| 174 function(x) {return x["name"] != "Cache-Control"}); | |
| 175 headers.push({'name': 'X-Test-Response-Header', | |
| 176 'value': 'Inserted'}); | |
| 177 headers.push({'name': 'Set-Cookie', | |
| 178 'value': 'ActivityLog=InsertedCookie'}); | |
| 179 response['responseHeaders'] = headers; | |
| 180 | |
| 181 return response; | |
| 182 } | 166 } |
| 183 chrome.webRequest.onBeforeSendHeaders.addListener( | 167 chrome.webRequest.onBeforeSendHeaders.addListener( |
| 184 doModifyHeaders, | 168 doModifyHeaders, |
| 185 {'urls': ['http://*/*'], 'types': ['main_frame']}, | 169 {'urls': ['http://*/*'], 'types': ['main_frame']}, |
| 186 ['blocking', 'requestHeaders']); | 170 ['blocking', 'requestHeaders']); |
| 187 chrome.webRequest.onHeadersReceived.addListener( | |
| 188 doModifyHeaders, | |
| 189 {'urls': ['http://*/*'], 'types': ['main_frame']}, | |
| 190 ['blocking', 'responseHeaders']); | |
| 191 | 171 |
| 192 // Open a tab, then close it when it has finished loading--this should give | 172 // Open a tab, then close it when it has finished loading--this should give |
| 193 // the webRequest handler a chance to run. | 173 // the webRequest handler a chance to run. |
| 194 chrome.tabs.onUpdated.addListener( | 174 chrome.tabs.onUpdated.addListener( |
| 195 function closeTab(tabId, changeInfo, tab) { | 175 function closeTab(tabId, changeInfo, tab) { |
| 196 if (changeInfo['status'] === "complete" && | 176 if (changeInfo['status'] === "complete" && |
| 197 tab.url.match(/google\.co\.uk/g)) { | 177 tab.url.match(/google\.co\.uk/g)) { |
| 198 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders); | 178 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders); |
| 199 chrome.tabs.onUpdated.removeListener(closeTab); | 179 chrome.tabs.onUpdated.removeListener(closeTab); |
| 200 chrome.tabs.remove(tabId); | 180 chrome.tabs.remove(tabId); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 $('message_self').addEventListener('click', sendMessageToSelf); | 260 $('message_self').addEventListener('click', sendMessageToSelf); |
| 281 $('message_other').addEventListener('click', sendMessageToOther); | 261 $('message_other').addEventListener('click', sendMessageToOther); |
| 282 $('connect_other').addEventListener('click', connectToOther); | 262 $('connect_other').addEventListener('click', connectToOther); |
| 283 | 263 |
| 284 completed = 0; | 264 completed = 0; |
| 285 total = document.getElementsByTagName('button').length; | 265 total = document.getElementsByTagName('button').length; |
| 286 } | 266 } |
| 287 | 267 |
| 288 document.addEventListener('DOMContentLoaded', setupEvents); | 268 document.addEventListener('DOMContentLoaded', setupEvents); |
| 289 | 269 |
| OLD | NEW |