Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / webrequest / test_complex.js
blob9d4e24c41eec2b5c8756abeedb7d76d7b268e4a2
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           }
257         },
258         { label: "onResponseStarted-1",
259           event: "onResponseStarted",
260           details: {
261             type: "main_frame",
262             url: getURLHttpXHR(),
263             statusCode: 200,
264             ip: "127.0.0.1",
265             fromCache: false,
266             statusLine: "HTTP/1.1 200 OK",
267           }
268         },
269         { label: "onCompleted-1",
270           event: "onCompleted",
271           details: {
272             type: "main_frame",
273             url: getURLHttpXHR(),
274             statusCode: 200,
275             ip: "127.0.0.1",
276             fromCache: false,
277             statusLine: "HTTP/1.1 200 OK",
278           }
279         },
280         { label: "a.js-onBeforeRequest",
281           event: "onBeforeRequest",
282           details: {
283             type: "script",
284             url: getURLHttpXHRJavaScript(),
285             frameUrl: getURLHttpXHR()
286           }
287         },
288         { label: "a.js-onBeforeSendHeaders",
289           event: "onBeforeSendHeaders",
290           details: {
291             type: "script",
292             url: getURLHttpXHRJavaScript(),
293           }
294         },
295         { label: "a.js-onSendHeaders",
296           event: "onSendHeaders",
297           details: {
298             type: "script",
299             url: getURLHttpXHRJavaScript(),
300           }
301         },
302         { label: "a.js-onHeadersReceived",
303           event: "onHeadersReceived",
304           details: {
305             type: "script",
306             url: getURLHttpXHRJavaScript(),
307             statusLine: "HTTP/1.1 200 OK",
308           }
309         },
310         { label: "a.js-onResponseStarted",
311           event: "onResponseStarted",
312           details: {
313             type: "script",
314             url: getURLHttpXHRJavaScript(),
315             statusCode: 200,
316             ip: "127.0.0.1",
317             fromCache: false,
318             statusLine: "HTTP/1.1 200 OK",
319           }
320         },
321         { label: "a.js-onCompleted",
322           event: "onCompleted",
323           details: {
324             type: "script",
325             url: getURLHttpXHRJavaScript(),
326             statusCode: 200,
327             ip: "127.0.0.1",
328             fromCache: false,
329             statusLine: "HTTP/1.1 200 OK",
330           }
331         },
332         { label: "onBeforeRequest-2",
333           event: "onBeforeRequest",
334           details: {
335             type: "xmlhttprequest",
336             url: getURLHttpXHRData(),
337             frameUrl: getURLHttpXHR()
338           }
339         },
340         { label: "onBeforeSendHeaders-2",
341           event: "onBeforeSendHeaders",
342           details: {
343             type: "xmlhttprequest",
344             url: getURLHttpXHRData(),
345           }
346         },
347         { label: "onSendHeaders-2",
348           event: "onSendHeaders",
349           details: {
350             type: "xmlhttprequest",
351             url: getURLHttpXHRData(),
352           }
353         },
354         { label: "onHeadersReceived-2",
355           event: "onHeadersReceived",
356           details: {
357             type: "xmlhttprequest",
358             url: getURLHttpXHRData(),
359             statusLine: "HTTP/1.1 200 OK",
360           }
361         },
362         { label: "onResponseStarted-2",
363           event: "onResponseStarted",
364           details: {
365             type: "xmlhttprequest",
366             url: getURLHttpXHRData(),
367             statusCode: 200,
368             ip: "127.0.0.1",
369             fromCache: false,
370             statusLine: "HTTP/1.1 200 OK",
371           }
372         },
373         { label: "onCompleted-2",
374           event: "onCompleted",
375           details: {
376             type: "xmlhttprequest",
377             url: getURLHttpXHRData(),
378             statusCode: 200,
379             ip: "127.0.0.1",
380             fromCache: false,
381             statusLine: "HTTP/1.1 200 OK",
382           }
383         }
384       ],
385       [  // event order
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());
391   },