Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / webrequest / test_auth_required.js
blob7e6b779449fac098a7bd81e20f88d89614c8ac9a
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 // Generates a unique authentication URL so each test can run
6 // without hitting the HTTP authentication cache. Each test
7 // must use a unique realm, however.
8 function getURLAuthRequired(realm) {
9 return getServerURL('auth-basic/' + realm + '/subpath?realm=' + realm);
12 runTests([
13 // onAuthRequired is not a blocking function in this variant.
14 function authRequiredNonBlocking() {
15 var realm = 'nonblock';
16 var url = getURLAuthRequired(realm);
17 expect(
18 [ // events
19 { label: "onBeforeRequest",
20 event: "onBeforeRequest",
21 details: {
22 url: url,
23 frameUrl: url
26 { label: "onBeforeSendHeaders",
27 event: "onBeforeSendHeaders",
28 details: {
29 url: url,
30 // Note: no requestHeaders because we don't ask for them.
33 { label: "onSendHeaders",
34 event: "onSendHeaders",
35 details: {
36 url: url,
39 { label: "onHeadersReceived",
40 event: "onHeadersReceived",
41 details: {
42 url: url,
43 responseHeadersExist: true,
44 statusLine: "HTTP/1.1 401 Unauthorized",
45 statusCode: 401,
48 { label: "onAuthRequired",
49 event: "onAuthRequired",
50 details: {
51 url: url,
52 isProxy: false,
53 scheme: "basic",
54 realm: realm,
55 challenger: {host: testServer, port: testServerPort},
56 responseHeadersExist: true,
57 statusLine: "HTTP/1.1 401 Unauthorized",
60 { label: "onResponseStarted",
61 event: "onResponseStarted",
62 details: {
63 url: url,
64 fromCache: false,
65 statusCode: 401,
66 ip: "127.0.0.1",
67 responseHeadersExist: true,
68 statusLine: "HTTP/1.1 401 Unauthorized",
71 { label: "onCompleted",
72 event: "onCompleted",
73 details: {
74 url: url,
75 fromCache: false,
76 statusCode: 401,
77 ip: "127.0.0.1",
78 responseHeadersExist: true,
79 statusLine: "HTTP/1.1 401 Unauthorized",
83 [ // event order
84 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
85 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
86 "onCompleted"]
88 {urls: ["<all_urls>"]}, ["responseHeaders"]);
89 navigateAndWait(url);
92 // onAuthRequired is a blocking function but takes no action in this variant.
93 function authRequiredSyncNoAction() {
94 var realm = 'syncnoaction';
95 var url = getURLAuthRequired(realm);
96 expect(
97 [ // events
98 { label: "onBeforeRequest",
99 event: "onBeforeRequest",
100 details: {
101 url: url,
102 frameUrl: url
105 { label: "onBeforeSendHeaders",
106 event: "onBeforeSendHeaders",
107 details: {
108 url: url,
109 // Note: no requestHeaders because we don't ask for them.
112 { label: "onSendHeaders",
113 event: "onSendHeaders",
114 details: {
115 url: url,
118 { label: "onHeadersReceived",
119 event: "onHeadersReceived",
120 details: {
121 url: url,
122 responseHeadersExist: true,
123 statusLine: "HTTP/1.1 401 Unauthorized",
124 statusCode: 401,
127 { label: "onAuthRequired",
128 event: "onAuthRequired",
129 details: {
130 url: url,
131 isProxy: false,
132 scheme: "basic",
133 realm: realm,
134 challenger: {host: testServer, port: testServerPort},
135 responseHeadersExist: true,
136 statusLine: "HTTP/1.1 401 Unauthorized",
139 { label: "onResponseStarted",
140 event: "onResponseStarted",
141 details: {
142 url: url,
143 fromCache: false,
144 statusCode: 401,
145 ip: "127.0.0.1",
146 responseHeadersExist: true,
147 statusLine: "HTTP/1.1 401 Unauthorized",
150 { label: "onCompleted",
151 event: "onCompleted",
152 details: {
153 url: url,
154 fromCache: false,
155 statusCode: 401,
156 ip: "127.0.0.1",
157 responseHeadersExist: true,
158 statusLine: "HTTP/1.1 401 Unauthorized",
162 [ // event order
163 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
164 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
165 "onCompleted"]
167 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
168 navigateAndWait(url);
171 // onAuthRequired is a blocking function that cancels the auth attempt.
172 function authRequiredSyncCancelAuth() {
173 var realm = 'synccancel';
174 var url = getURLAuthRequired(realm);
175 expect(
176 [ // events
177 { label: "onBeforeRequest",
178 event: "onBeforeRequest",
179 details: {
180 url: url,
181 frameUrl: url
183 retval: {}
185 { label: "onBeforeSendHeaders",
186 event: "onBeforeSendHeaders",
187 details: {
188 url: url,
189 // Note: no requestHeaders because we don't ask for them.
191 retval: {}
193 { label: "onSendHeaders",
194 event: "onSendHeaders",
195 details: {
196 url: url,
199 { label: "onHeadersReceived",
200 event: "onHeadersReceived",
201 details: {
202 url: url,
203 responseHeadersExist: true,
204 statusLine: "HTTP/1.1 401 Unauthorized",
205 statusCode: 401,
208 { label: "onAuthRequired",
209 event: "onAuthRequired",
210 details: {
211 url: url,
212 isProxy: false,
213 scheme: "basic",
214 realm: realm,
215 challenger: {host: testServer, port: testServerPort},
216 responseHeadersExist: true,
217 statusLine: "HTTP/1.1 401 Unauthorized",
219 retval: {cancel: true}
221 { label: "onResponseStarted",
222 event: "onResponseStarted",
223 details: {
224 url: url,
225 fromCache: false,
226 statusCode: 401,
227 ip: "127.0.0.1",
228 responseHeadersExist: true,
229 statusLine: "HTTP/1.1 401 Unauthorized",
232 { label: "onCompleted",
233 event: "onCompleted",
234 details: {
235 url: url,
236 fromCache: false,
237 statusCode: 401,
238 ip: "127.0.0.1",
239 responseHeadersExist: true,
240 statusLine: "HTTP/1.1 401 Unauthorized",
244 [ // event order
245 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
246 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
247 "onCompleted"]
249 {urls: ["<all_urls>"]},
250 ["responseHeaders", "blocking"]);
251 navigateAndWait(url);
254 // onAuthRequired is a blocking function that sets authentication credentials.
255 function authRequiredSyncSetAuth() {
256 var realm = 'syncsetauth';
257 var url = getURLAuthRequired(realm);
258 expect(
259 [ // events
260 { label: "onBeforeRequest",
261 event: "onBeforeRequest",
262 details: {
263 url: url,
264 frameUrl: url
266 retval: {}
268 { label: "onBeforeSendHeaders",
269 event: "onBeforeSendHeaders",
270 details: {
271 url: url,
272 // Note: no requestHeaders because we don't ask for them.
274 retval: {}
276 { label: "onSendHeaders",
277 event: "onSendHeaders",
278 details: {
279 url: url,
282 { label: "onHeadersReceived",
283 event: "onHeadersReceived",
284 details: {
285 url: url,
286 responseHeadersExist: true,
287 statusLine: "HTTP/1.1 401 Unauthorized",
288 statusCode: 401,
291 { label: "onAuthRequired",
292 event: "onAuthRequired",
293 details: {
294 url: url,
295 isProxy: false,
296 scheme: "basic",
297 realm: realm,
298 challenger: {host: testServer, port: testServerPort},
299 responseHeadersExist: true,
300 statusLine: "HTTP/1.1 401 Unauthorized",
302 retval: {authCredentials: {username: "foo", password: "secret"}}
304 { label: "onResponseStarted",
305 event: "onResponseStarted",
306 details: {
307 url: url,
308 fromCache: false,
309 statusCode: 200,
310 ip: "127.0.0.1",
311 responseHeadersExist: true,
312 statusLine: "HTTP/1.1 200 OK",
315 { label: "onCompleted",
316 event: "onCompleted",
317 details: {
318 url: url,
319 fromCache: false,
320 statusCode: 200,
321 ip: "127.0.0.1",
322 responseHeadersExist: true,
323 statusLine: "HTTP/1.1 200 OK",
327 [ // event order
328 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
329 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
330 "onCompleted"]
332 {urls: ["<all_urls>"]},
333 ["responseHeaders", "blocking"]);
334 navigateAndWait(url);
337 // onAuthRequired is an async function but takes no action in this variant.
338 function authRequiredAsyncNoAction() {
339 var realm = 'asyncnoaction';
340 var url = getURLAuthRequired(realm);
341 expect(
342 [ // events
343 { label: "onBeforeRequest",
344 event: "onBeforeRequest",
345 details: {
346 url: url,
347 frameUrl: url
350 { label: "onBeforeSendHeaders",
351 event: "onBeforeSendHeaders",
352 details: {
353 url: url,
354 // Note: no requestHeaders because we don't ask for them.
357 { label: "onSendHeaders",
358 event: "onSendHeaders",
359 details: {
360 url: url,
363 { label: "onHeadersReceived",
364 event: "onHeadersReceived",
365 details: {
366 url: url,
367 responseHeadersExist: true,
368 statusLine: "HTTP/1.1 401 Unauthorized",
369 statusCode: 401,
372 { label: "onAuthRequired",
373 event: "onAuthRequired",
374 details: {
375 url: url,
376 isProxy: false,
377 scheme: "basic",
378 realm: realm,
379 challenger: {host: testServer, port: testServerPort},
380 responseHeadersExist: true,
381 statusLine: "HTTP/1.1 401 Unauthorized",
384 { label: "onResponseStarted",
385 event: "onResponseStarted",
386 details: {
387 url: url,
388 fromCache: false,
389 statusCode: 401,
390 ip: "127.0.0.1",
391 responseHeadersExist: true,
392 statusLine: "HTTP/1.1 401 Unauthorized",
395 { label: "onCompleted",
396 event: "onCompleted",
397 details: {
398 url: url,
399 fromCache: false,
400 statusCode: 401,
401 ip: "127.0.0.1",
402 responseHeadersExist: true,
403 statusLine: "HTTP/1.1 401 Unauthorized",
407 [ // event order
408 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
409 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
410 "onCompleted"]
412 {urls: ["<all_urls>"]}, ["asyncBlocking", "responseHeaders"]);
413 navigateAndWait(url);
416 // onAuthRequired is an async function that cancels the auth attempt.
417 function authRequiredAsyncCancelAuth() {
418 var realm = 'asynccancel';
419 var url = getURLAuthRequired(realm);
420 expect(
421 [ // events
422 { label: "onBeforeRequest",
423 event: "onBeforeRequest",
424 details: {
425 url: url,
426 frameUrl: url
428 retval: {}
430 { label: "onBeforeSendHeaders",
431 event: "onBeforeSendHeaders",
432 details: {
433 url: url,
434 // Note: no requestHeaders because we don't ask for them.
436 retval: {}
438 { label: "onSendHeaders",
439 event: "onSendHeaders",
440 details: {
441 url: url,
444 { label: "onHeadersReceived",
445 event: "onHeadersReceived",
446 details: {
447 url: url,
448 responseHeadersExist: true,
449 statusLine: "HTTP/1.1 401 Unauthorized",
450 statusCode: 401,
453 { label: "onAuthRequired",
454 event: "onAuthRequired",
455 details: {
456 url: url,
457 isProxy: false,
458 scheme: "basic",
459 realm: realm,
460 challenger: {host: testServer, port: testServerPort},
461 responseHeadersExist: true,
462 statusLine: "HTTP/1.1 401 Unauthorized",
464 retval: {cancel: true}
466 { label: "onResponseStarted",
467 event: "onResponseStarted",
468 details: {
469 url: url,
470 fromCache: false,
471 statusCode: 401,
472 ip: "127.0.0.1",
473 responseHeadersExist: true,
474 statusLine: "HTTP/1.1 401 Unauthorized",
477 { label: "onCompleted",
478 event: "onCompleted",
479 details: {
480 url: url,
481 fromCache: false,
482 statusCode: 401,
483 ip: "127.0.0.1",
484 responseHeadersExist: true,
485 statusLine: "HTTP/1.1 401 Unauthorized",
489 [ // event order
490 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
491 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
492 "onCompleted"]
494 {urls: ["<all_urls>"]},
495 ["responseHeaders", "asyncBlocking"]);
496 navigateAndWait(url);
499 // onAuthRequired is an async function that sets authentication credentials.
500 function authRequiredAsyncSetAuth() {
501 var realm = 'asyncsetauth';
502 var url = getURLAuthRequired(realm);
503 expect(
504 [ // events
505 { label: "onBeforeRequest",
506 event: "onBeforeRequest",
507 details: {
508 url: url,
509 frameUrl: url
511 retval: {}
513 { label: "onBeforeSendHeaders",
514 event: "onBeforeSendHeaders",
515 details: {
516 url: url,
517 // Note: no requestHeaders because we don't ask for them.
519 retval: {}
521 { label: "onSendHeaders",
522 event: "onSendHeaders",
523 details: {
524 url: url,
527 { label: "onHeadersReceived",
528 event: "onHeadersReceived",
529 details: {
530 url: url,
531 responseHeadersExist: true,
532 statusLine: "HTTP/1.1 401 Unauthorized",
533 statusCode: 401,
536 { label: "onAuthRequired",
537 event: "onAuthRequired",
538 details: {
539 url: url,
540 isProxy: false,
541 scheme: "basic",
542 realm: realm,
543 challenger: {host: testServer, port: testServerPort},
544 responseHeadersExist: true,
545 statusLine: "HTTP/1.1 401 Unauthorized",
547 retval: {authCredentials: {username: "foo", password: "secret"}}
549 { label: "onResponseStarted",
550 event: "onResponseStarted",
551 details: {
552 url: url,
553 fromCache: false,
554 statusCode: 200,
555 ip: "127.0.0.1",
556 responseHeadersExist: true,
557 statusLine: "HTTP/1.1 200 OK",
560 { label: "onCompleted",
561 event: "onCompleted",
562 details: {
563 url: url,
564 fromCache: false,
565 statusCode: 200,
566 ip: "127.0.0.1",
567 responseHeadersExist: true,
568 statusLine: "HTTP/1.1 200 OK",
572 [ // event order
573 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
574 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
575 "onCompleted"]
577 {urls: ["<all_urls>"]},
578 ["responseHeaders", "asyncBlocking"]);
579 navigateAndWait(url);