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
3 // found in the LICENSE file.
5 function getURLHttpXHR() {
6 return getServerURL('extensions/api_test/webrequest/xhr/a.html');
8 function getURLHttpXHRJavaScript() {
9 return getServerURL('extensions/api_test/webrequest/xhr/a.js');
11 function getURLHttpXHRData() {
12 return getServerURL('extensions/api_test/webrequest/xhr/data.json');
16 // Navigates to a page with subresources.
17 function complexLoad() {
20 { label: "a.html-onBeforeRequest",
21 event: "onBeforeRequest",
24 url: getURL("complexLoad/a.html"),
25 frameUrl: getURL("complexLoad/a.html")
28 { label: "b.html-onBeforeRequest",
29 event: "onBeforeRequest",
32 url: getURL("complexLoad/b.html"),
33 frameUrl: getURL("complexLoad/b.html"),
38 { label: "b.jpg-onBeforeRequest",
39 event: "onBeforeRequest",
42 url: getURL("complexLoad/b.jpg"),
43 frameUrl: getURL("complexLoad/b.html"),
48 { label: "a.html-onResponseStarted",
49 event: "onResponseStarted",
52 url: getURL("complexLoad/a.html"),
55 statusLine: "HTTP/1.1 200 OK",
56 // Request to chrome-extension:// url has no IP.
59 { label: "b.html-onResponseStarted",
60 event: "onResponseStarted",
63 url: getURL("complexLoad/b.html"),
66 statusLine: "HTTP/1.1 200 OK",
69 // Request to chrome-extension:// url has no IP.
72 { label: "b.jpg-onResponseStarted",
73 event: "onResponseStarted",
76 url: getURL("complexLoad/b.jpg"),
79 statusLine: "HTTP/1.1 200 OK",
82 // Request to chrome-extension:// url has no IP.
85 { label: "a.html-onCompleted",
89 url: getURL("complexLoad/a.html"),
92 statusLine: "HTTP/1.1 200 OK",
93 // Request to chrome-extension:// url has no IP.
96 { label: "b.html-onCompleted",
100 url: getURL("complexLoad/b.html"),
103 statusLine: "HTTP/1.1 200 OK",
106 // Request to chrome-extension:// url has no IP.
109 { label: "b.jpg-onCompleted",
110 event: "onCompleted",
113 url: getURL("complexLoad/b.jpg"),
116 statusLine: "HTTP/1.1 200 OK",
119 // Request to chrome-extension:// url has no IP.
124 ["a.html-onBeforeRequest", "a.html-onResponseStarted",
125 "b.html-onBeforeRequest", "b.html-onResponseStarted",
126 "b.jpg-onBeforeRequest", "b.jpg-onResponseStarted" ],
127 ["a.html-onResponseStarted", "a.html-onCompleted"],
128 ["b.html-onResponseStarted", "b.html-onCompleted"],
129 ["b.jpg-onResponseStarted", "b.jpg-onCompleted"] ]
131 navigateAndWait(getURL("complexLoad/a.html"));
134 // Loads several resources, but should only see the complexLoad main_frame
135 // and image due to the filter.
136 function complexLoadFiltered() {
139 { label: "a-onBeforeRequest",
140 event: "onBeforeRequest",
143 url: getURL("complexLoad/a.html"),
144 frameUrl: getURL("complexLoad/a.html")
147 { label: "b-onBeforeRequest",
148 event: "onBeforeRequest",
151 url: getURL("complexLoad/b.jpg"),
152 // As we do not listed to sub-frames we do not know the frameUrl.
153 frameUrl: "unknown frame URL",
158 { label: "a-onResponseStarted",
159 event: "onResponseStarted",
162 url: getURL("complexLoad/a.html"),
165 statusLine: "HTTP/1.1 200 OK",
166 // Request to chrome-extension:// url has no IP.
169 { label: "b-onResponseStarted",
170 event: "onResponseStarted",
173 url: getURL("complexLoad/b.jpg"),
176 statusLine: "HTTP/1.1 200 OK",
179 // Request to chrome-extension:// url has no IP.
182 { label: "a-onCompleted",
183 event: "onCompleted",
186 url: getURL("complexLoad/a.html"),
189 statusLine: "HTTP/1.1 200 OK",
190 // Request to chrome-extension:// url has no IP.
193 { label: "b-onCompleted",
194 event: "onCompleted",
197 url: getURL("complexLoad/b.jpg"),
200 statusLine: "HTTP/1.1 200 OK",
203 // Request to chrome-extension:// url has no IP.
208 ["a-onBeforeRequest", "a-onResponseStarted",
209 "b-onBeforeRequest", "b-onResponseStarted"],
210 ["a-onResponseStarted", "a-onCompleted"],
211 ["b-onResponseStarted", "b-onCompleted"] ],
213 urls: [getURL("complexLoad/*")],
214 types: ["main_frame", "image"],
217 chrome.tabs.create({ url: getURL("simpleLoad/a.html") },
219 chrome.tabs.remove(newTab.id);
220 navigateAndWait(getURL("complexLoad/a.html"));
224 // Navigates to a page to generates an XHR.
228 { label: "onBeforeRequest-1",
229 event: "onBeforeRequest",
232 url: getURLHttpXHR(),
233 frameUrl: getURLHttpXHR()
236 { label: "onBeforeSendHeaders-1",
237 event: "onBeforeSendHeaders",
240 url: getURLHttpXHR(),
243 { label: "onSendHeaders-1",
244 event: "onSendHeaders",
247 url: getURLHttpXHR(),
250 { label: "onHeadersReceived-1",
251 event: "onHeadersReceived",
254 url: getURLHttpXHR(),
255 statusLine: "HTTP/1.1 200 OK",
259 { label: "onResponseStarted-1",
260 event: "onResponseStarted",
263 url: getURLHttpXHR(),
267 statusLine: "HTTP/1.1 200 OK",
270 { label: "onCompleted-1",
271 event: "onCompleted",
274 url: getURLHttpXHR(),
278 statusLine: "HTTP/1.1 200 OK",
281 { label: "a.js-onBeforeRequest",
282 event: "onBeforeRequest",
285 url: getURLHttpXHRJavaScript(),
286 frameUrl: getURLHttpXHR()
289 { label: "a.js-onBeforeSendHeaders",
290 event: "onBeforeSendHeaders",
293 url: getURLHttpXHRJavaScript(),
296 { label: "a.js-onSendHeaders",
297 event: "onSendHeaders",
300 url: getURLHttpXHRJavaScript(),
303 { label: "a.js-onHeadersReceived",
304 event: "onHeadersReceived",
307 url: getURLHttpXHRJavaScript(),
308 statusLine: "HTTP/1.1 200 OK",
312 { label: "a.js-onResponseStarted",
313 event: "onResponseStarted",
316 url: getURLHttpXHRJavaScript(),
320 statusLine: "HTTP/1.1 200 OK",
323 { label: "a.js-onCompleted",
324 event: "onCompleted",
327 url: getURLHttpXHRJavaScript(),
331 statusLine: "HTTP/1.1 200 OK",
334 { label: "onBeforeRequest-2",
335 event: "onBeforeRequest",
337 type: "xmlhttprequest",
338 url: getURLHttpXHRData(),
339 frameUrl: getURLHttpXHR()
342 { label: "onBeforeSendHeaders-2",
343 event: "onBeforeSendHeaders",
345 type: "xmlhttprequest",
346 url: getURLHttpXHRData(),
349 { label: "onSendHeaders-2",
350 event: "onSendHeaders",
352 type: "xmlhttprequest",
353 url: getURLHttpXHRData(),
356 { label: "onHeadersReceived-2",
357 event: "onHeadersReceived",
359 type: "xmlhttprequest",
360 url: getURLHttpXHRData(),
361 statusLine: "HTTP/1.1 200 OK",
365 { label: "onResponseStarted-2",
366 event: "onResponseStarted",
368 type: "xmlhttprequest",
369 url: getURLHttpXHRData(),
373 statusLine: "HTTP/1.1 200 OK",
376 { label: "onCompleted-2",
377 event: "onCompleted",
379 type: "xmlhttprequest",
380 url: getURLHttpXHRData(),
384 statusLine: "HTTP/1.1 200 OK",
389 ["onBeforeRequest-1", "onBeforeSendHeaders-1", "onSendHeaders-1",
390 "onHeadersReceived-1", "onResponseStarted-1", "onCompleted-1",
391 "onBeforeRequest-2", "onBeforeSendHeaders-2", "onSendHeaders-2",
392 "onHeadersReceived-2", "onResponseStarted-2", "onCompleted-2"] ]);
393 navigateAndWait(getURLHttpXHR());