Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / webrequest / test_complex.js
bloba66ac3b2c16a5f188543fa8d94e7b4401d933199
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');
15 runTests([
16   // Navigates to a page with subresources.
17   function complexLoad() {
18     expect(
19       [  // events
20         { label: "a.html-onBeforeRequest",
21           event: "onBeforeRequest",
22           details: {
23             type: "main_frame",
24             url: getURL("complexLoad/a.html"),
25             frameUrl: getURL("complexLoad/a.html")
26           }
27         },
28         { label: "b.html-onBeforeRequest",
29           event: "onBeforeRequest",
30           details: {
31             type: "sub_frame",
32             url: getURL("complexLoad/b.html"),
33             frameUrl: getURL("complexLoad/b.html"),
34             frameId: 1,
35             parentFrameId: 0,
36           }
37         },
38         { label: "b.jpg-onBeforeRequest",
39           event: "onBeforeRequest",
40           details: {
41             type: "image",
42             url: getURL("complexLoad/b.jpg"),
43             frameUrl: getURL("complexLoad/b.html"),
44             frameId: 1,
45             parentFrameId: 0,
46           }
47         },
48         { label: "a.html-onResponseStarted",
49           event: "onResponseStarted",
50           details: {
51             type: "main_frame",
52             url: getURL("complexLoad/a.html"),
53             fromCache: false,
54             statusCode: 200,
55             statusLine: "HTTP/1.1 200 OK",
56             // Request to chrome-extension:// url has no IP.
57           }
58         },
59         { label: "b.html-onResponseStarted",
60           event: "onResponseStarted",
61           details: {
62             type: "sub_frame",
63             url: getURL("complexLoad/b.html"),
64             fromCache: false,
65             statusCode: 200,
66             statusLine: "HTTP/1.1 200 OK",
67             frameId: 1,
68             parentFrameId: 0,
69             // Request to chrome-extension:// url has no IP.
70           }
71         },
72         { label: "b.jpg-onResponseStarted",
73           event: "onResponseStarted",
74           details: {
75             type: "image",
76             url: getURL("complexLoad/b.jpg"),
77             fromCache: false,
78             statusCode: 200,
79             statusLine: "HTTP/1.1 200 OK",
80             frameId: 1,
81             parentFrameId: 0,
82             // Request to chrome-extension:// url has no IP.
83           }
84         },
85         { label: "a.html-onCompleted",
86           event: "onCompleted",
87           details: {
88             type: "main_frame",
89             url: getURL("complexLoad/a.html"),
90             fromCache: false,
91             statusCode: 200,
92             statusLine: "HTTP/1.1 200 OK",
93             // Request to chrome-extension:// url has no IP.
94           }
95         },
96         { label: "b.html-onCompleted",
97           event: "onCompleted",
98           details: {
99             type: "sub_frame",
100             url: getURL("complexLoad/b.html"),
101             fromCache: false,
102             statusCode: 200,
103             statusLine: "HTTP/1.1 200 OK",
104             frameId: 1,
105             parentFrameId: 0,
106             // Request to chrome-extension:// url has no IP.
107           }
108         },
109         { label: "b.jpg-onCompleted",
110           event: "onCompleted",
111           details: {
112             type: "image",
113             url: getURL("complexLoad/b.jpg"),
114             fromCache: false,
115             statusCode: 200,
116             statusLine: "HTTP/1.1 200 OK",
117             frameId: 1,
118             parentFrameId: 0,
119             // Request to chrome-extension:// url has no IP.
120           }
121         },
122       ],
123       [  // event order
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"] ]
130       );
131     navigateAndWait(getURL("complexLoad/a.html"));
132   },
134   // Loads several resources, but should only see the complexLoad main_frame
135   // and image due to the filter.
136   function complexLoadFiltered() {
137     expect(
138       [  // events
139         { label: "a-onBeforeRequest",
140           event: "onBeforeRequest",
141           details: {
142             type: "main_frame",
143             url: getURL("complexLoad/a.html"),
144             frameUrl: getURL("complexLoad/a.html")
145           }
146         },
147         { label: "b-onBeforeRequest",
148           event: "onBeforeRequest",
149           details: {
150             type: "image",
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",
154             frameId: 1,
155             parentFrameId: 0,
156           }
157         },
158         { label: "a-onResponseStarted",
159           event: "onResponseStarted",
160           details: {
161             type: "main_frame",
162             url: getURL("complexLoad/a.html"),
163             fromCache: false,
164             statusCode: 200,
165             statusLine: "HTTP/1.1 200 OK",
166             // Request to chrome-extension:// url has no IP.
167           }
168         },
169         { label: "b-onResponseStarted",
170           event: "onResponseStarted",
171           details: {
172             type: "image",
173             url: getURL("complexLoad/b.jpg"),
174             fromCache: false,
175             statusCode: 200,
176             statusLine: "HTTP/1.1 200 OK",
177             frameId: 1,
178             parentFrameId: 0,
179             // Request to chrome-extension:// url has no IP.
180           }
181         },
182         { label: "a-onCompleted",
183           event: "onCompleted",
184           details: {
185             type: "main_frame",
186             url: getURL("complexLoad/a.html"),
187             fromCache: false,
188             statusCode: 200,
189             statusLine: "HTTP/1.1 200 OK",
190             // Request to chrome-extension:// url has no IP.
191           }
192         },
193         { label: "b-onCompleted",
194           event: "onCompleted",
195           details: {
196             type: "image",
197             url: getURL("complexLoad/b.jpg"),
198             fromCache: false,
199             statusCode: 200,
200             statusLine: "HTTP/1.1 200 OK",
201             frameId: 1,
202             parentFrameId: 0,
203             // Request to chrome-extension:// url has no IP.
204           }
205         },
206       ],
207       [  // event order
208         ["a-onBeforeRequest", "a-onResponseStarted",
209          "b-onBeforeRequest", "b-onResponseStarted"],
210         ["a-onResponseStarted", "a-onCompleted"],
211         ["b-onResponseStarted", "b-onCompleted"] ],
212       {  // filters
213         urls: [getURL("complexLoad/*")],
214         types: ["main_frame", "image"],
215         tabId: tabId
216       });
217     chrome.tabs.create({ url: getURL("simpleLoad/a.html") },
218         function(newTab) {
219       chrome.tabs.remove(newTab.id);
220       navigateAndWait(getURL("complexLoad/a.html"));
221     });
222   },
224   // Navigates to a page to generates an XHR.
225   function xhrLoad() {
226     expect(
227       [  // events
228         { label: "onBeforeRequest-1",
229           event: "onBeforeRequest",
230           details: {
231             type: "main_frame",
232             url: getURLHttpXHR(),
233             frameUrl: getURLHttpXHR()
234           }
235         },
236         { label: "onBeforeSendHeaders-1",
237           event: "onBeforeSendHeaders",
238           details: {
239             type: "main_frame",
240             url: getURLHttpXHR(),
241           }
242         },
243         { label: "onSendHeaders-1",
244           event: "onSendHeaders",
245           details: {
246             type: "main_frame",
247             url: getURLHttpXHR(),
248           }
249         },
250         { label: "onHeadersReceived-1",
251           event: "onHeadersReceived",
252           details: {
253             type: "main_frame",
254             url: getURLHttpXHR(),
255             statusLine: "HTTP/1.1 200 OK",
256             statusCode: 200,
257           }
258         },
259         { label: "onResponseStarted-1",
260           event: "onResponseStarted",
261           details: {
262             type: "main_frame",
263             url: getURLHttpXHR(),
264             statusCode: 200,
265             ip: "127.0.0.1",
266             fromCache: false,
267             statusLine: "HTTP/1.1 200 OK",
268           }
269         },
270         { label: "onCompleted-1",
271           event: "onCompleted",
272           details: {
273             type: "main_frame",
274             url: getURLHttpXHR(),
275             statusCode: 200,
276             ip: "127.0.0.1",
277             fromCache: false,
278             statusLine: "HTTP/1.1 200 OK",
279           }
280         },
281         { label: "a.js-onBeforeRequest",
282           event: "onBeforeRequest",
283           details: {
284             type: "script",
285             url: getURLHttpXHRJavaScript(),
286             frameUrl: getURLHttpXHR()
287           }
288         },
289         { label: "a.js-onBeforeSendHeaders",
290           event: "onBeforeSendHeaders",
291           details: {
292             type: "script",
293             url: getURLHttpXHRJavaScript(),
294           }
295         },
296         { label: "a.js-onSendHeaders",
297           event: "onSendHeaders",
298           details: {
299             type: "script",
300             url: getURLHttpXHRJavaScript(),
301           }
302         },
303         { label: "a.js-onHeadersReceived",
304           event: "onHeadersReceived",
305           details: {
306             type: "script",
307             url: getURLHttpXHRJavaScript(),
308             statusLine: "HTTP/1.1 200 OK",
309             statusCode: 200,
310           }
311         },
312         { label: "a.js-onResponseStarted",
313           event: "onResponseStarted",
314           details: {
315             type: "script",
316             url: getURLHttpXHRJavaScript(),
317             statusCode: 200,
318             ip: "127.0.0.1",
319             fromCache: false,
320             statusLine: "HTTP/1.1 200 OK",
321           }
322         },
323         { label: "a.js-onCompleted",
324           event: "onCompleted",
325           details: {
326             type: "script",
327             url: getURLHttpXHRJavaScript(),
328             statusCode: 200,
329             ip: "127.0.0.1",
330             fromCache: false,
331             statusLine: "HTTP/1.1 200 OK",
332           }
333         },
334         { label: "onBeforeRequest-2",
335           event: "onBeforeRequest",
336           details: {
337             type: "xmlhttprequest",
338             url: getURLHttpXHRData(),
339             frameUrl: getURLHttpXHR()
340           }
341         },
342         { label: "onBeforeSendHeaders-2",
343           event: "onBeforeSendHeaders",
344           details: {
345             type: "xmlhttprequest",
346             url: getURLHttpXHRData(),
347           }
348         },
349         { label: "onSendHeaders-2",
350           event: "onSendHeaders",
351           details: {
352             type: "xmlhttprequest",
353             url: getURLHttpXHRData(),
354           }
355         },
356         { label: "onHeadersReceived-2",
357           event: "onHeadersReceived",
358           details: {
359             type: "xmlhttprequest",
360             url: getURLHttpXHRData(),
361             statusLine: "HTTP/1.1 200 OK",
362             statusCode: 200,
363           }
364         },
365         { label: "onResponseStarted-2",
366           event: "onResponseStarted",
367           details: {
368             type: "xmlhttprequest",
369             url: getURLHttpXHRData(),
370             statusCode: 200,
371             ip: "127.0.0.1",
372             fromCache: false,
373             statusLine: "HTTP/1.1 200 OK",
374           }
375         },
376         { label: "onCompleted-2",
377           event: "onCompleted",
378           details: {
379             type: "xmlhttprequest",
380             url: getURLHttpXHRData(),
381             statusCode: 200,
382             ip: "127.0.0.1",
383             fromCache: false,
384             statusLine: "HTTP/1.1 200 OK",
385           }
386         }
387       ],
388       [  // event order
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());
394   },