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 var getURL = chrome.extension.getURL; | 5 var getURL = chrome.extension.getURL; |
6 var deepEq = chrome.test.checkDeepEq; | 6 var deepEq = chrome.test.checkDeepEq; |
7 var expectedEventData; | 7 var expectedEventData; |
8 var capturedEventData; | 8 var capturedEventData; |
9 var expectedEventOrder; | 9 var expectedEventOrder; |
10 var tabId; | 10 var tabId; |
| 11 var tabIdMap; |
11 var testServerPort; | 12 var testServerPort; |
12 var testServer = "www.a.com"; | 13 var testServer = "www.a.com"; |
13 var eventsCaptured; | 14 var eventsCaptured; |
14 | 15 |
15 function runTests(tests) { | 16 function runTests(tests) { |
16 chrome.tabs.create({url: "about:blank"}, function(tab) { | 17 chrome.tabs.create({url: "about:blank"}, function(tab) { |
17 tabId = tab.id; | 18 tabId = tab.id; |
| 19 tabIdMap = {}; |
| 20 tabIdMap[tabId] = 0; |
18 chrome.test.getConfig(function(config) { | 21 chrome.test.getConfig(function(config) { |
19 testServerPort = config.testServer.port; | 22 testServerPort = config.testServer.port; |
20 chrome.test.runTests(tests); | 23 chrome.test.runTests(tests); |
21 }); | 24 }); |
22 }); | 25 }); |
23 } | 26 } |
24 | 27 |
25 // Returns an URL from the test server, fixing up the port. Must be called | 28 // Returns an URL from the test server, fixing up the port. Must be called |
26 // from within a test case passed to runTests. | 29 // from within a test case passed to runTests. |
27 function getServerURL(path, opt_host) { | 30 function getServerURL(path, opt_host) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 eventsCaptured = chrome.test.callbackAdded(); | 67 eventsCaptured = chrome.test.callbackAdded(); |
65 tabAndFrameUrls = {}; // Maps "{tabId}-{frameId}" to the URL of the frame. | 68 tabAndFrameUrls = {}; // Maps "{tabId}-{frameId}" to the URL of the frame. |
66 removeListeners(); | 69 removeListeners(); |
67 initListeners(filter || {}, extraInfoSpec || []); | 70 initListeners(filter || {}, extraInfoSpec || []); |
68 // Fill in default values. | 71 // Fill in default values. |
69 for (var i = 0; i < expectedEventData.length; ++i) { | 72 for (var i = 0; i < expectedEventData.length; ++i) { |
70 if (!expectedEventData[i].details.method) { | 73 if (!expectedEventData[i].details.method) { |
71 expectedEventData[i].details.method = "GET"; | 74 expectedEventData[i].details.method = "GET"; |
72 } | 75 } |
73 if (!expectedEventData[i].details.tabId) { | 76 if (!expectedEventData[i].details.tabId) { |
74 expectedEventData[i].details.tabId = tabId; | 77 expectedEventData[i].details.tabId = tabIdMap[tabId]; |
75 } | 78 } |
76 if (!expectedEventData[i].details.type) { | 79 if (!expectedEventData[i].details.type) { |
77 expectedEventData[i].details.type = "main_frame"; | 80 expectedEventData[i].details.type = "main_frame"; |
78 } | 81 } |
79 } | 82 } |
80 } | 83 } |
81 | 84 |
82 function checkExpectations() { | 85 function checkExpectations() { |
83 if (capturedEventData.length < expectedEventData.length) { | 86 if (capturedEventData.length < expectedEventData.length) { |
84 return; | 87 return; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 chrome.test.assertTrue('tabId' in details && | 157 chrome.test.assertTrue('tabId' in details && |
155 typeof details.tabId === 'number'); | 158 typeof details.tabId === 'number'); |
156 var key = details.tabId + "-" + details.frameId; | 159 var key = details.tabId + "-" + details.frameId; |
157 if (details.type == "main_frame" || details.type == "sub_frame") { | 160 if (details.type == "main_frame" || details.type == "sub_frame") { |
158 tabAndFrameUrls[key] = details.url; | 161 tabAndFrameUrls[key] = details.url; |
159 } | 162 } |
160 details.frameUrl = tabAndFrameUrls[key] || "unknown frame URL"; | 163 details.frameUrl = tabAndFrameUrls[key] || "unknown frame URL"; |
161 } | 164 } |
162 delete details.frameId; | 165 delete details.frameId; |
163 | 166 |
| 167 // This assigns unique IDs to newly opened tabs. However, the new IDs are only |
| 168 // deterministic, if the order in which the tabs are opened is deterministic. |
| 169 if (!(details.tabId in tabIdMap)) { |
| 170 tabIdMap[details.tabId] = Object.keys(tabIdMap).length; |
| 171 } |
| 172 details.tabId = tabIdMap[details.tabId]; |
| 173 |
164 delete details.requestId; | 174 delete details.requestId; |
165 delete details.timeStamp; | 175 delete details.timeStamp; |
166 if (details.requestHeaders) { | 176 if (details.requestHeaders) { |
167 details.requestHeadersValid = checkUserAgent(details.requestHeaders); | 177 details.requestHeadersValid = checkUserAgent(details.requestHeaders); |
168 delete details.requestHeaders; | 178 delete details.requestHeaders; |
169 } | 179 } |
170 if (details.responseHeaders) { | 180 if (details.responseHeaders) { |
171 details.responseHeadersExist = true; | 181 details.responseHeadersExist = true; |
172 delete details.responseHeaders; | 182 delete details.responseHeaders; |
173 } | 183 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 helper(chrome.experimental.webRequest.onBeforeRequest); | 270 helper(chrome.experimental.webRequest.onBeforeRequest); |
261 helper(chrome.experimental.webRequest.onBeforeSendHeaders); | 271 helper(chrome.experimental.webRequest.onBeforeSendHeaders); |
262 helper(chrome.experimental.webRequest.onAuthRequired); | 272 helper(chrome.experimental.webRequest.onAuthRequired); |
263 helper(chrome.experimental.webRequest.onSendHeaders); | 273 helper(chrome.experimental.webRequest.onSendHeaders); |
264 helper(chrome.experimental.webRequest.onHeadersReceived); | 274 helper(chrome.experimental.webRequest.onHeadersReceived); |
265 helper(chrome.experimental.webRequest.onResponseStarted); | 275 helper(chrome.experimental.webRequest.onResponseStarted); |
266 helper(chrome.experimental.webRequest.onBeforeRedirect); | 276 helper(chrome.experimental.webRequest.onBeforeRedirect); |
267 helper(chrome.experimental.webRequest.onCompleted); | 277 helper(chrome.experimental.webRequest.onCompleted); |
268 helper(chrome.experimental.webRequest.onErrorOccurred); | 278 helper(chrome.experimental.webRequest.onErrorOccurred); |
269 } | 279 } |
OLD | NEW |