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

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: Simplify code 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
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ); 138 );
139 window.open('http://www.google.cn'); 139 window.open('http://www.google.cn');
140 } 140 }
141 141
142 // Modifies the headers sent and received in an HTTP request using the 142 // Modifies the headers sent and received in an HTTP request using the
143 // webRequest API. 143 // webRequest API.
144 function doWebRequestModifications() { 144 function doWebRequestModifications() {
145 // Install a webRequest handler that will add an HTTP header to the outgoing 145 // Install a webRequest handler that will add an HTTP header to the outgoing
146 // request for the main page. 146 // request for the main page.
147 function doModifyHeaders(details) { 147 function doModifyHeaders(details) {
148 var response = {};
149
148 var headers = details.requestHeaders; 150 var headers = details.requestHeaders;
149 if (headers === undefined) { 151 if (headers === undefined) {
150 headers = []; 152 headers = [];
151 } 153 }
152 headers.push({'name': 'X-Test-Activity-Log-Send', 154 headers.push({'name': 'X-Test-Activity-Log-Send',
153 'value': 'Present'}); 155 'value': 'Present'});
154 return {'requestHeaders': headers}; 156 response['requestHeaders'] = headers;
157
158 headers = details.responseHeaders;
159 if (headers === undefined) {
160 headers = [];
161 }
162 headers = headers.filter(
163 function(x) {return x["name"] != "Cache-Control"});
164 headers.push({'name': 'X-Test-Response-Header',
165 'value': 'Inserted'});
166 headers.push({'name': 'Set-Cookie',
167 'value': 'ActivityLog=InsertedCookie'});
168 response['responseHeaders'] = headers;
169
170 return response;
155 } 171 }
156 chrome.webRequest.onBeforeSendHeaders.addListener( 172 chrome.webRequest.onBeforeSendHeaders.addListener(
157 doModifyHeaders, 173 doModifyHeaders,
158 {'urls': ['http://*/*'], 'types': ['main_frame']}, 174 {'urls': ['http://*/*'], 'types': ['main_frame']},
159 ['blocking', 'requestHeaders']); 175 ['blocking', 'requestHeaders']);
176 chrome.webRequest.onHeadersReceived.addListener(
177 doModifyHeaders,
178 {'urls': ['http://*/*'], 'types': ['main_frame']},
179 ['blocking', 'responseHeaders']);
160 180
161 // Open a tab, then close it when it has finished loading--this should give 181 // Open a tab, then close it when it has finished loading--this should give
162 // the webRequest handler a chance to run. 182 // the webRequest handler a chance to run.
163 chrome.tabs.onUpdated.addListener( 183 chrome.tabs.onUpdated.addListener(
164 function closeTab(tabId, changeInfo, tab) { 184 function closeTab(tabId, changeInfo, tab) {
165 if (changeInfo['status'] === "complete" && 185 if (changeInfo['status'] === "complete" &&
166 tab.url.match(/google\.co\.uk/g)) { 186 tab.url.match(/google\.co\.uk/g)) {
167 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders); 187 chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders);
168 chrome.tabs.onUpdated.removeListener(closeTab); 188 chrome.tabs.onUpdated.removeListener(closeTab);
169 chrome.tabs.remove(tabId); 189 chrome.tabs.remove(tabId);
(...skipping 16 matching lines...) Expand all
186 $('cs_xhr').addEventListener('click', doContentScriptXHR); 206 $('cs_xhr').addEventListener('click', doContentScriptXHR);
187 $('webrequest').addEventListener('click', doWebRequestModifications); 207 $('webrequest').addEventListener('click', doWebRequestModifications);
188 $('double').addEventListener('click', checkNoDoubleLogging); 208 $('double').addEventListener('click', checkNoDoubleLogging);
189 209
190 completed = 0; 210 completed = 0;
191 total = document.getElementsByTagName('button').length; 211 total = document.getElementsByTagName('button').length;
192 } 212 }
193 213
194 document.addEventListener('DOMContentLoaded', setupEvents); 214 document.addEventListener('DOMContentLoaded', setupEvents);
195 215
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698