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",
258 { label: "onResponseStarted-1",
259 event: "onResponseStarted",
262 url: getURLHttpXHR(),
266 statusLine: "HTTP/1.1 200 OK",
269 { label: "onCompleted-1",
270 event: "onCompleted",
273 url: getURLHttpXHR(),
277 statusLine: "HTTP/1.1 200 OK",
280 { label: "a.js-onBeforeRequest",
281 event: "onBeforeRequest",
284 url: getURLHttpXHRJavaScript(),
285 frameUrl: getURLHttpXHR()
288 { label: "a.js-onBeforeSendHeaders",
289 event: "onBeforeSendHeaders",
292 url: getURLHttpXHRJavaScript(),
295 { label: "a.js-onSendHeaders",
296 event: "onSendHeaders",
299 url: getURLHttpXHRJavaScript(),
302 { label: "a.js-onHeadersReceived",
303 event: "onHeadersReceived",
306 url: getURLHttpXHRJavaScript(),
307 statusLine: "HTTP/1.1 200 OK",
310 { label: "a.js-onResponseStarted",
311 event: "onResponseStarted",
314 url: getURLHttpXHRJavaScript(),
318 statusLine: "HTTP/1.1 200 OK",
321 { label: "a.js-onCompleted",
322 event: "onCompleted",
325 url: getURLHttpXHRJavaScript(),
329 statusLine: "HTTP/1.1 200 OK",
332 { label: "onBeforeRequest-2",
333 event: "onBeforeRequest",
335 type: "xmlhttprequest",
336 url: getURLHttpXHRData(),
337 frameUrl: getURLHttpXHR()
340 { label: "onBeforeSendHeaders-2",
341 event: "onBeforeSendHeaders",
343 type: "xmlhttprequest",
344 url: getURLHttpXHRData(),
347 { label: "onSendHeaders-2",
348 event: "onSendHeaders",
350 type: "xmlhttprequest",
351 url: getURLHttpXHRData(),
354 { label: "onHeadersReceived-2",
355 event: "onHeadersReceived",
357 type: "xmlhttprequest",
358 url: getURLHttpXHRData(),
359 statusLine: "HTTP/1.1 200 OK",
362 { label: "onResponseStarted-2",
363 event: "onResponseStarted",
365 type: "xmlhttprequest",
366 url: getURLHttpXHRData(),
370 statusLine: "HTTP/1.1 200 OK",
373 { label: "onCompleted-2",
374 event: "onCompleted",
376 type: "xmlhttprequest",
377 url: getURLHttpXHRData(),
381 statusLine: "HTTP/1.1 200 OK",
386 ["onBeforeRequest-1", "onBeforeSendHeaders-1", "onSendHeaders-1",
387 "onHeadersReceived-1", "onResponseStarted-1", "onCompleted-1",
388 "onBeforeRequest-2", "onBeforeSendHeaders-2", "onSendHeaders-2",
389 "onHeadersReceived-2", "onResponseStarted-2", "onCompleted-2"] ]);
390 navigateAndWait(getURLHttpXHR());