Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/test_types.js

Issue 1515703005: WebRequest API: add more resource types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace == with && 2x Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 function getStyleURL() {
6 // This is not a style sheet, but it must still be classified as "stylesheet"
7 // because it is loaded as a style sheet.
8 return getServerURL('empty.html?as-style');
9 }
10
11 function getFontURL() {
12 // Not a font, but will be loaded as a font.
13 return getServerURL('empty.html?as-font');
14 }
15
16 function getWorkerURL() {
17 // This file is empty, so it does not generate JavaScript errors when loaded
18 // as a worker script.
19 return getServerURL('empty.html?as-worker');
20 }
21
22 function getPingURL() {
23 return getServerURL('empty.html?as-ping');
24 }
25
26 function getBeaconURL() {
27 return getServerURL('empty.html?as-beacon');
28 }
29
30 runTests([
31 function typeStylesheet() {
32 expect([
33 { label: 'onBeforeRequest',
34 event: 'onBeforeRequest',
35 details: {
36 type: 'stylesheet',
37 url: getStyleURL(),
38 frameUrl: 'unknown frame URL',
39 // tabId 0 = tab opened by test runner;
40 // tabId 1 = this tab.
41 tabId: 1,
42 }
43 },
44 { label: 'onBeforeSendHeaders',
45 event: 'onBeforeSendHeaders',
46 details: {
47 type: 'stylesheet',
48 url: getStyleURL(),
49 tabId: 1,
50 },
51 },
52 { label: 'onSendHeaders',
53 event: 'onSendHeaders',
54 details: {
55 type: 'stylesheet',
56 url: getStyleURL(),
57 tabId: 1,
58 },
59 },
60 { label: 'onHeadersReceived',
61 event: 'onHeadersReceived',
62 details: {
63 type: 'stylesheet',
64 url: getStyleURL(),
65 tabId: 1,
66 statusLine: 'HTTP/1.1 200 OK',
67 statusCode: 200,
68 },
69 },
70 { label: 'onResponseStarted',
71 event: 'onResponseStarted',
72 details: {
73 type: 'stylesheet',
74 url: getStyleURL(),
75 tabId: 1,
76 ip: '127.0.0.1',
77 fromCache: false,
78 statusLine: 'HTTP/1.1 200 OK',
79 statusCode: 200,
80 },
81 },
82 { label: 'onCompleted',
83 event: 'onCompleted',
84 details: {
85 type: 'stylesheet',
86 url: getStyleURL(),
87 tabId: 1,
88 ip: '127.0.0.1',
89 fromCache: false,
90 statusLine: 'HTTP/1.1 200 OK',
91 statusCode: 200,
92 },
93 }],
94 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
95 'onHeadersReceived', 'onResponseStarted', 'onCompleted']]);
96 var style = document.createElement('link');
97 style.rel = 'stylesheet';
98 style.type = 'text/css';
99 style.href = getStyleURL();
100 document.body.appendChild(style);
101 },
102
103 function typeFont() {
104 expect([
105 { label: 'onBeforeRequest',
106 event: 'onBeforeRequest',
107 details: {
108 type: 'font',
109 url: getFontURL(),
110 frameUrl: 'unknown frame URL',
111 // tabId 0 = tab opened by test runner;
112 // tabId 1 = this tab.
113 tabId: 1,
114 }
115 },
116 { label: 'onBeforeSendHeaders',
117 event: 'onBeforeSendHeaders',
118 details: {
119 type: 'font',
120 url: getFontURL(),
121 tabId: 1,
122 },
123 },
124 { label: 'onSendHeaders',
125 event: 'onSendHeaders',
126 details: {
127 type: 'font',
128 url: getFontURL(),
129 tabId: 1,
130 },
131 },
132 { label: 'onHeadersReceived',
133 event: 'onHeadersReceived',
134 details: {
135 type: 'font',
136 url: getFontURL(),
137 tabId: 1,
138 statusLine: 'HTTP/1.1 200 OK',
139 statusCode: 200,
140 },
141 },
142 { label: 'onResponseStarted',
143 event: 'onResponseStarted',
144 details: {
145 type: 'font',
146 url: getFontURL(),
147 tabId: 1,
148 ip: '127.0.0.1',
149 fromCache: false,
150 statusLine: 'HTTP/1.1 200 OK',
151 statusCode: 200,
152 },
153 },
154 { label: 'onCompleted',
155 event: 'onCompleted',
156 details: {
157 type: 'font',
158 url: getFontURL(),
159 tabId: 1,
160 ip: '127.0.0.1',
161 fromCache: false,
162 statusLine: 'HTTP/1.1 200 OK',
163 statusCode: 200,
164 },
165 }],
166 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
167 'onHeadersReceived', 'onResponseStarted', 'onCompleted']]);
168
169 new FontFace('allegedly-a-font-family', 'url(' + getFontURL() + ')').load();
170 },
171
172 function typeWorker() {
173 expect([
174 { label: 'onBeforeRequest',
175 event: 'onBeforeRequest',
176 details: {
177 type: 'script',
178 url: getWorkerURL(),
179 frameUrl: 'unknown frame URL',
180 // tabId 0 = tab opened by test runner;
181 // tabId 1 = this tab.
182 tabId: 1,
183 }
184 },
185 { label: 'onBeforeSendHeaders',
186 event: 'onBeforeSendHeaders',
187 details: {
188 type: 'script',
189 url: getWorkerURL(),
190 tabId: 1,
191 },
192 },
193 { label: 'onSendHeaders',
194 event: 'onSendHeaders',
195 details: {
196 type: 'script',
197 url: getWorkerURL(),
198 tabId: 1,
199 },
200 },
201 { label: 'onHeadersReceived',
202 event: 'onHeadersReceived',
203 details: {
204 type: 'script',
205 url: getWorkerURL(),
206 tabId: 1,
207 statusLine: 'HTTP/1.1 200 OK',
208 statusCode: 200,
209 },
210 },
211 { label: 'onResponseStarted',
212 event: 'onResponseStarted',
213 details: {
214 type: 'script',
215 url: getWorkerURL(),
216 tabId: 1,
217 ip: '127.0.0.1',
218 fromCache: false,
219 statusLine: 'HTTP/1.1 200 OK',
220 statusCode: 200,
221 },
222 },
223 { label: 'onCompleted',
224 event: 'onCompleted',
225 details: {
226 type: 'script',
227 url: getWorkerURL(),
228 tabId: 1,
229 ip: '127.0.0.1',
230 fromCache: false,
231 statusLine: 'HTTP/1.1 200 OK',
232 statusCode: 200,
233 },
234 }],
235 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
236 'onHeadersReceived', 'onResponseStarted', 'onCompleted']]);
237
238 new Worker(getWorkerURL());
239
240 // TODO(robwu): add tests for SharedWorker and ServiceWorker.
241 // (probably same as above, but using -1 because they are not specific to
242 // any tab. In general we really need a lot more test coverage for the
243 // interaction between Service workers and extensions.)
244 },
245
246 function typePing() {
247 expect([
248 { label: 'onBeforeRequest',
249 event: 'onBeforeRequest',
250 details: {
251 type: 'ping',
252 method: 'POST',
253 url: getPingURL(),
254 frameUrl: 'unknown frame URL',
255 // TODO(robwu): Ping / beacons are not associated with a tab/frame
256 // because they are detached requests. However, it would be useful if
257 // the frameId and tabId are set to the source of the request.
258 // See crbug.com/522124.
259 frameId: -1,
260 tabId: -1,
261 }
262 },
263 { label: 'onBeforeSendHeaders',
264 event: 'onBeforeSendHeaders',
265 details: {
266 type: 'ping',
267 method: 'POST',
268 url: getPingURL(),
269 frameId: -1,
270 tabId: -1,
271 },
272 },
273 { label: 'onSendHeaders',
274 event: 'onSendHeaders',
275 details: {
276 type: 'ping',
277 method: 'POST',
278 url: getPingURL(),
279 frameId: -1,
280 tabId: -1,
281 },
282 },
283 { label: 'onHeadersReceived',
284 event: 'onHeadersReceived',
285 details: {
286 type: 'ping',
287 method: 'POST',
288 url: getPingURL(),
289 frameId: -1,
290 tabId: -1,
291 statusLine: 'HTTP/1.1 200 OK',
292 statusCode: 200,
293 },
294 },
295 { label: 'onResponseStarted',
296 event: 'onResponseStarted',
297 details: {
298 type: 'ping',
299 method: 'POST',
300 url: getPingURL(),
301 frameId: -1,
302 tabId: -1,
303 ip: '127.0.0.1',
304 fromCache: false,
305 statusLine: 'HTTP/1.1 200 OK',
306 statusCode: 200,
307 },
308 },
309 { label: 'onCompleted',
310 event: 'onCompleted',
311 details: {
312 type: 'ping',
313 method: 'POST',
314 url: getPingURL(),
315 frameId: -1,
316 tabId: -1,
317 ip: '127.0.0.1',
318 fromCache: false,
319 statusLine: 'HTTP/1.1 200 OK',
320 statusCode: 200,
321 },
322 }],
323 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
324 'onHeadersReceived', 'onResponseStarted', 'onCompleted']]);
325
326 var a = document.createElement('a');
327 a.ping = getPingURL();
328 a.href = 'javascript:';
329 a.click();
330 },
331
332 function typeBeacon() {
333 expect([
334 { label: 'onBeforeRequest',
335 event: 'onBeforeRequest',
336 details: {
337 type: 'ping',
338 method: 'POST',
339 url: getBeaconURL(),
340 frameUrl: 'unknown frame URL',
341 // TODO(robwu): these IDs should not be -1. See comment at typePing.
342 frameId: -1,
343 tabId: -1,
344 }
345 },
346 { label: 'onBeforeSendHeaders',
347 event: 'onBeforeSendHeaders',
348 details: {
349 type: 'ping',
350 method: 'POST',
351 url: getBeaconURL(),
352 frameId: -1,
353 tabId: -1,
354 },
355 },
356 { label: 'onSendHeaders',
357 event: 'onSendHeaders',
358 details: {
359 type: 'ping',
360 method: 'POST',
361 url: getBeaconURL(),
362 frameId: -1,
363 tabId: -1,
364 },
365 },
366 { label: 'onHeadersReceived',
367 event: 'onHeadersReceived',
368 details: {
369 type: 'ping',
370 method: 'POST',
371 url: getBeaconURL(),
372 frameId: -1,
373 tabId: -1,
374 statusLine: 'HTTP/1.1 200 OK',
375 statusCode: 200,
376 },
377 },
378 { label: 'onResponseStarted',
379 event: 'onResponseStarted',
380 details: {
381 type: 'ping',
382 method: 'POST',
383 url: getBeaconURL(),
384 frameId: -1,
385 tabId: -1,
386 ip: '127.0.0.1',
387 fromCache: false,
388 statusLine: 'HTTP/1.1 200 OK',
389 statusCode: 200,
390 },
391 },
392 { label: 'onCompleted',
393 event: 'onCompleted',
394 details: {
395 type: 'ping',
396 method: 'POST',
397 url: getBeaconURL(),
398 frameId: -1,
399 tabId: -1,
400 ip: '127.0.0.1',
401 fromCache: false,
402 statusLine: 'HTTP/1.1 200 OK',
403 statusCode: 200,
404 },
405 }],
406 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
407 'onHeadersReceived', 'onResponseStarted', 'onCompleted']]);
408
409 navigator.sendBeacon(getBeaconURL(), 'beacon data');
410 },
411 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698