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
);
13 // onAuthRequired is not a blocking function in this variant.
14 function authRequiredNonBlocking() {
15 var realm
= 'nonblock';
16 var url
= getURLAuthRequired(realm
);
19 { label
: "onBeforeRequest",
20 event
: "onBeforeRequest",
26 { label
: "onBeforeSendHeaders",
27 event
: "onBeforeSendHeaders",
30 // Note: no requestHeaders because we don't ask for them.
33 { label
: "onSendHeaders",
34 event
: "onSendHeaders",
39 { label
: "onHeadersReceived",
40 event
: "onHeadersReceived",
43 responseHeadersExist
: true,
44 statusLine
: "HTTP/1.1 401 Unauthorized",
48 { label
: "onAuthRequired",
49 event
: "onAuthRequired",
55 challenger
: {host
: testServer
, port
: testServerPort
},
56 responseHeadersExist
: true,
57 statusLine
: "HTTP/1.1 401 Unauthorized",
60 { label
: "onResponseStarted",
61 event
: "onResponseStarted",
67 responseHeadersExist
: true,
68 statusLine
: "HTTP/1.1 401 Unauthorized",
71 { label
: "onCompleted",
78 responseHeadersExist
: true,
79 statusLine
: "HTTP/1.1 401 Unauthorized",
84 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
85 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
88 {urls
: ["<all_urls>"]}, ["responseHeaders"]);
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
);
98 { label
: "onBeforeRequest",
99 event
: "onBeforeRequest",
105 { label
: "onBeforeSendHeaders",
106 event
: "onBeforeSendHeaders",
109 // Note: no requestHeaders because we don't ask for them.
112 { label
: "onSendHeaders",
113 event
: "onSendHeaders",
118 { label
: "onHeadersReceived",
119 event
: "onHeadersReceived",
122 responseHeadersExist
: true,
123 statusLine
: "HTTP/1.1 401 Unauthorized",
127 { label
: "onAuthRequired",
128 event
: "onAuthRequired",
134 challenger
: {host
: testServer
, port
: testServerPort
},
135 responseHeadersExist
: true,
136 statusLine
: "HTTP/1.1 401 Unauthorized",
139 { label
: "onResponseStarted",
140 event
: "onResponseStarted",
146 responseHeadersExist
: true,
147 statusLine
: "HTTP/1.1 401 Unauthorized",
150 { label
: "onCompleted",
151 event
: "onCompleted",
157 responseHeadersExist
: true,
158 statusLine
: "HTTP/1.1 401 Unauthorized",
163 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
164 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
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
);
177 { label
: "onBeforeRequest",
178 event
: "onBeforeRequest",
185 { label
: "onBeforeSendHeaders",
186 event
: "onBeforeSendHeaders",
189 // Note: no requestHeaders because we don't ask for them.
193 { label
: "onSendHeaders",
194 event
: "onSendHeaders",
199 { label
: "onHeadersReceived",
200 event
: "onHeadersReceived",
203 responseHeadersExist
: true,
204 statusLine
: "HTTP/1.1 401 Unauthorized",
208 { label
: "onAuthRequired",
209 event
: "onAuthRequired",
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",
228 responseHeadersExist
: true,
229 statusLine
: "HTTP/1.1 401 Unauthorized",
232 { label
: "onCompleted",
233 event
: "onCompleted",
239 responseHeadersExist
: true,
240 statusLine
: "HTTP/1.1 401 Unauthorized",
245 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
246 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
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
);
260 { label
: "onBeforeRequest",
261 event
: "onBeforeRequest",
268 { label
: "onBeforeSendHeaders",
269 event
: "onBeforeSendHeaders",
272 // Note: no requestHeaders because we don't ask for them.
276 { label
: "onSendHeaders",
277 event
: "onSendHeaders",
282 { label
: "onHeadersReceived",
283 event
: "onHeadersReceived",
286 responseHeadersExist
: true,
287 statusLine
: "HTTP/1.1 401 Unauthorized",
291 { label
: "onAuthRequired",
292 event
: "onAuthRequired",
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",
311 responseHeadersExist
: true,
312 statusLine
: "HTTP/1.1 200 OK",
315 { label
: "onCompleted",
316 event
: "onCompleted",
322 responseHeadersExist
: true,
323 statusLine
: "HTTP/1.1 200 OK",
328 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
329 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
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
);
343 { label
: "onBeforeRequest",
344 event
: "onBeforeRequest",
350 { label
: "onBeforeSendHeaders",
351 event
: "onBeforeSendHeaders",
354 // Note: no requestHeaders because we don't ask for them.
357 { label
: "onSendHeaders",
358 event
: "onSendHeaders",
363 { label
: "onHeadersReceived",
364 event
: "onHeadersReceived",
367 responseHeadersExist
: true,
368 statusLine
: "HTTP/1.1 401 Unauthorized",
372 { label
: "onAuthRequired",
373 event
: "onAuthRequired",
379 challenger
: {host
: testServer
, port
: testServerPort
},
380 responseHeadersExist
: true,
381 statusLine
: "HTTP/1.1 401 Unauthorized",
384 { label
: "onResponseStarted",
385 event
: "onResponseStarted",
391 responseHeadersExist
: true,
392 statusLine
: "HTTP/1.1 401 Unauthorized",
395 { label
: "onCompleted",
396 event
: "onCompleted",
402 responseHeadersExist
: true,
403 statusLine
: "HTTP/1.1 401 Unauthorized",
408 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
409 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
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
);
422 { label
: "onBeforeRequest",
423 event
: "onBeforeRequest",
430 { label
: "onBeforeSendHeaders",
431 event
: "onBeforeSendHeaders",
434 // Note: no requestHeaders because we don't ask for them.
438 { label
: "onSendHeaders",
439 event
: "onSendHeaders",
444 { label
: "onHeadersReceived",
445 event
: "onHeadersReceived",
448 responseHeadersExist
: true,
449 statusLine
: "HTTP/1.1 401 Unauthorized",
453 { label
: "onAuthRequired",
454 event
: "onAuthRequired",
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",
473 responseHeadersExist
: true,
474 statusLine
: "HTTP/1.1 401 Unauthorized",
477 { label
: "onCompleted",
478 event
: "onCompleted",
484 responseHeadersExist
: true,
485 statusLine
: "HTTP/1.1 401 Unauthorized",
490 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
491 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
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
);
505 { label
: "onBeforeRequest",
506 event
: "onBeforeRequest",
513 { label
: "onBeforeSendHeaders",
514 event
: "onBeforeSendHeaders",
517 // Note: no requestHeaders because we don't ask for them.
521 { label
: "onSendHeaders",
522 event
: "onSendHeaders",
527 { label
: "onHeadersReceived",
528 event
: "onHeadersReceived",
531 responseHeadersExist
: true,
532 statusLine
: "HTTP/1.1 401 Unauthorized",
536 { label
: "onAuthRequired",
537 event
: "onAuthRequired",
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",
556 responseHeadersExist
: true,
557 statusLine
: "HTTP/1.1 200 OK",
560 { label
: "onCompleted",
561 event
: "onCompleted",
567 responseHeadersExist
: true,
568 statusLine
: "HTTP/1.1 200 OK",
573 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
574 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
577 {urls
: ["<all_urls>"]},
578 ["responseHeaders", "asyncBlocking"]);
579 navigateAndWait(url
);