Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: chrome/test/data/extensions/activity_log/options.js

Issue 12491012: Improved extension activity logging for the chrome.webRequest API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/chrome_browser_extensions.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
159 var headers = details.requestHeaders; 161 var headers = details.requestHeaders;
160 if (headers === undefined) { 162 if (headers === undefined) {
161 headers = []; 163 headers = [];
162 } 164 }
163 headers.push({'name': 'X-Test-Activity-Log-Send', 165 headers.push({'name': 'X-Test-Activity-Log-Send',
164 'value': 'Present'}); 166 'value': 'Present'});
165 return {'requestHeaders': headers}; 167 response['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;
166 } 182 }
167 chrome.webRequest.onBeforeSendHeaders.addListener( 183 chrome.webRequest.onBeforeSendHeaders.addListener(
168 doModifyHeaders, 184 doModifyHeaders,
169 {'urls': ['http://*/*'], 'types': ['main_frame']}, 185 {'urls': ['http://*/*'], 'types': ['main_frame']},
170 ['blocking', 'requestHeaders']); 186 ['blocking', 'requestHeaders']);
187 chrome.webRequest.onHeadersReceived.addListener(
188 doModifyHeaders,
189 {'urls': ['http://*/*'], 'types': ['main_frame']},
190 ['blocking', 'responseHeaders']);
171 191
172 // Open a tab, then close it when it has finished loading--this should give 192 // Open a tab, then close it when it has finished loading--this should give
173 // the webRequest handler a chance to run. 193 // the webRequest handler a chance to run.
174 chrome.tabs.onUpdated.addListener( 194 chrome.tabs.onUpdated.addListener(
175 function closeTab(tabId, changeInfo, tab) { 195 function closeTab(tabId, changeInfo, tab) {
176 if (changeInfo['status'] === "complete" && 196 if (changeInfo['status'] === "complete" &&
177 tab.url.match(/google\.co\.uk/g)) { 197 tab.url.match(/google\.co\.uk/g)) {
178 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders); 198 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders);
179 chrome.tabs.onUpdated.removeListener(closeTab); 199 chrome.tabs.onUpdated.removeListener(closeTab);
180 chrome.tabs.remove(tabId); 200 chrome.tabs.remove(tabId);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 $('message_self').addEventListener('click', sendMessageToSelf); 280 $('message_self').addEventListener('click', sendMessageToSelf);
261 $('message_other').addEventListener('click', sendMessageToOther); 281 $('message_other').addEventListener('click', sendMessageToOther);
262 $('connect_other').addEventListener('click', connectToOther); 282 $('connect_other').addEventListener('click', connectToOther);
263 283
264 completed = 0; 284 completed = 0;
265 total = document.getElementsByTagName('button').length; 285 total = document.getElementsByTagName('button').length;
266 } 286 }
267 287
268 document.addEventListener('DOMContentLoaded', setupEvents); 288 document.addEventListener('DOMContentLoaded', setupEvents);
269 289
OLDNEW
« no previous file with comments | « chrome/chrome_browser_extensions.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698