| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 chrome.tabs.executeScript(tab.id, {'code': xhr}); | 112 chrome.tabs.executeScript(tab.id, {'code': xhr}); |
| 113 chrome.tabs.onUpdated.removeListener(doCSXHR); | 113 chrome.tabs.onUpdated.removeListener(doCSXHR); |
| 114 chrome.tabs.remove(tabId); | 114 chrome.tabs.remove(tabId); |
| 115 setCompleted('doContentScriptXHR'); | 115 setCompleted('doContentScriptXHR'); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 ); | 118 ); |
| 119 window.open('http://www.google.cn'); | 119 window.open('http://www.google.cn'); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Modifies the headers sent and received in an HTTP request using the |
| 123 // webRequest API. |
| 124 function doWebRequestModifications() { |
| 125 // Install a webRequest handler that will add an HTTP header to the outgoing |
| 126 // request for the main page. |
| 127 function doModifyHeaders(details) { |
| 128 var headers = details.requestHeaders; |
| 129 if (headers === undefined) { |
| 130 headers = []; |
| 131 } |
| 132 headers.push({'name': 'X-Test-Activity-Log-Send', |
| 133 'value': 'Present'}); |
| 134 return {'requestHeaders': headers}; |
| 135 } |
| 136 chrome.webRequest.onBeforeSendHeaders.addListener( |
| 137 doModifyHeaders, |
| 138 {'urls': ['http://*/*'], 'types': ['main_frame']}, |
| 139 ['blocking', 'requestHeaders']); |
| 140 |
| 141 // Open a tab, then close it when it has finished loading--this should give |
| 142 // the webRequest handler a chance to run. |
| 143 chrome.tabs.onUpdated.addListener( |
| 144 function closeTab(tabId, changeInfo, tab) { |
| 145 if (changeInfo['status'] === "complete" && |
| 146 tab.url.match(/google\.co\.uk/g)) { |
| 147 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders); |
| 148 chrome.tabs.onUpdated.removeListener(closeTab); |
| 149 chrome.tabs.remove(tabId); |
| 150 setCompleted('doWebRequestModifications'); |
| 151 } |
| 152 } |
| 153 ); |
| 154 window.open('http://www.google.co.uk'); |
| 155 } |
| 156 |
| 122 // REGISTER YOUR TESTS HERE | 157 // REGISTER YOUR TESTS HERE |
| 123 // Attach the tests to buttons. | 158 // Attach the tests to buttons. |
| 124 function setupEvents() { | 159 function setupEvents() { |
| 125 $('api_call').addEventListener('click', makeApiCall); | 160 $('api_call').addEventListener('click', makeApiCall); |
| 126 $('blocked_call').addEventListener('click', makeBlockedApiCall); | 161 $('blocked_call').addEventListener('click', makeBlockedApiCall); |
| 127 $('inject_cs').addEventListener('click', injectContentScript); | 162 $('inject_cs').addEventListener('click', injectContentScript); |
| 128 $('inject_blob').addEventListener('click', injectScriptBlob); | 163 $('inject_blob').addEventListener('click', injectScriptBlob); |
| 129 $('background_xhr').addEventListener('click', doBackgroundXHR); | 164 $('background_xhr').addEventListener('click', doBackgroundXHR); |
| 130 $('cs_xhr').addEventListener('click', doContentScriptXHR); | 165 $('cs_xhr').addEventListener('click', doContentScriptXHR); |
| 166 $('webrequest').addEventListener('click', doWebRequestModifications); |
| 131 | 167 |
| 132 completed = 0; | 168 completed = 0; |
| 133 total = document.getElementsByTagName('button').length; | 169 total = document.getElementsByTagName('button').length; |
| 134 } | 170 } |
| 135 | 171 |
| 136 document.addEventListener('DOMContentLoaded', setupEvents); | 172 document.addEventListener('DOMContentLoaded', setupEvents); |
| 137 | 173 |
| OLD | NEW |