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"
47 { label: "onAuthRequired",
48 event: "onAuthRequired",
54 challenger: {host: testServer, port: testServerPort},
55 responseHeadersExist: true,
56 statusLine: "HTTP/1.1 401 Unauthorized",
59 { label: "onResponseStarted",
60 event: "onResponseStarted",
66 responseHeadersExist: true,
67 statusLine: "HTTP/1.1 401 Unauthorized",
70 { label: "onCompleted",
77 responseHeadersExist: true,
78 statusLine: "HTTP/1.1 401 Unauthorized",
83 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
84 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
87 {urls: ["<all_urls>"]}, ["responseHeaders"]);
91 // onAuthRequired is a blocking function but takes no action in this variant.
92 function authRequiredSyncNoAction() {
93 var realm = 'syncnoaction';
94 var url = getURLAuthRequired(realm);
97 { label: "onBeforeRequest",
98 event: "onBeforeRequest",
104 { label: "onBeforeSendHeaders",
105 event: "onBeforeSendHeaders",
108 // Note: no requestHeaders because we don't ask for them.
111 { label: "onSendHeaders",
112 event: "onSendHeaders",
117 { label: "onHeadersReceived",
118 event: "onHeadersReceived",
121 responseHeadersExist: true,
122 statusLine: "HTTP/1.1 401 Unauthorized"
125 { label: "onAuthRequired",
126 event: "onAuthRequired",
132 challenger: {host: testServer, port: testServerPort},
133 responseHeadersExist: true,
134 statusLine: "HTTP/1.1 401 Unauthorized",
137 { label: "onResponseStarted",
138 event: "onResponseStarted",
144 responseHeadersExist: true,
145 statusLine: "HTTP/1.1 401 Unauthorized",
148 { label: "onCompleted",
149 event: "onCompleted",
155 responseHeadersExist: true,
156 statusLine: "HTTP/1.1 401 Unauthorized",
161 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
162 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
165 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]);
166 navigateAndWait(url);
169 // onAuthRequired is a blocking function that cancels the auth attempt.
170 function authRequiredSyncCancelAuth() {
171 var realm = 'synccancel';
172 var url = getURLAuthRequired(realm);
175 { label: "onBeforeRequest",
176 event: "onBeforeRequest",
183 { label: "onBeforeSendHeaders",
184 event: "onBeforeSendHeaders",
187 // Note: no requestHeaders because we don't ask for them.
191 { label: "onSendHeaders",
192 event: "onSendHeaders",
197 { label: "onHeadersReceived",
198 event: "onHeadersReceived",
201 responseHeadersExist: true,
202 statusLine: "HTTP/1.1 401 Unauthorized"
205 { label: "onAuthRequired",
206 event: "onAuthRequired",
212 challenger: {host: testServer, port: testServerPort},
213 responseHeadersExist: true,
214 statusLine: "HTTP/1.1 401 Unauthorized",
216 retval: {cancel: true}
218 { label: "onResponseStarted",
219 event: "onResponseStarted",
225 responseHeadersExist: true,
226 statusLine: "HTTP/1.1 401 Unauthorized",
229 { label: "onCompleted",
230 event: "onCompleted",
236 responseHeadersExist: true,
237 statusLine: "HTTP/1.1 401 Unauthorized",
242 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
243 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
246 {urls: ["<all_urls>"]},
247 ["responseHeaders", "blocking"]);
248 navigateAndWait(url);
251 // onAuthRequired is a blocking function that sets authentication credentials.
252 function authRequiredSyncSetAuth() {
253 var realm = 'syncsetauth';
254 var url = getURLAuthRequired(realm);
257 { label: "onBeforeRequest",
258 event: "onBeforeRequest",
265 { label: "onBeforeSendHeaders",
266 event: "onBeforeSendHeaders",
269 // Note: no requestHeaders because we don't ask for them.
273 { label: "onSendHeaders",
274 event: "onSendHeaders",
279 { label: "onHeadersReceived",
280 event: "onHeadersReceived",
283 responseHeadersExist: true,
284 statusLine: "HTTP/1.1 401 Unauthorized"
287 { label: "onAuthRequired",
288 event: "onAuthRequired",
294 challenger: {host: testServer, port: testServerPort},
295 responseHeadersExist: true,
296 statusLine: "HTTP/1.1 401 Unauthorized",
298 retval: {authCredentials: {username: "foo", password: "secret"}}
300 { label: "onResponseStarted",
301 event: "onResponseStarted",
307 responseHeadersExist: true,
308 statusLine: "HTTP/1.1 200 OK",
311 { label: "onCompleted",
312 event: "onCompleted",
318 responseHeadersExist: true,
319 statusLine: "HTTP/1.1 200 OK",
324 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
325 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
328 {urls: ["<all_urls>"]},
329 ["responseHeaders", "blocking"]);
330 navigateAndWait(url);
333 // onAuthRequired is an async function but takes no action in this variant.
334 function authRequiredAsyncNoAction() {
335 var realm = 'asyncnoaction';
336 var url = getURLAuthRequired(realm);
339 { label: "onBeforeRequest",
340 event: "onBeforeRequest",
346 { label: "onBeforeSendHeaders",
347 event: "onBeforeSendHeaders",
350 // Note: no requestHeaders because we don't ask for them.
353 { label: "onSendHeaders",
354 event: "onSendHeaders",
359 { label: "onHeadersReceived",
360 event: "onHeadersReceived",
363 responseHeadersExist: true,
364 statusLine: "HTTP/1.1 401 Unauthorized"
367 { label: "onAuthRequired",
368 event: "onAuthRequired",
374 challenger: {host: testServer, port: testServerPort},
375 responseHeadersExist: true,
376 statusLine: "HTTP/1.1 401 Unauthorized",
379 { label: "onResponseStarted",
380 event: "onResponseStarted",
386 responseHeadersExist: true,
387 statusLine: "HTTP/1.1 401 Unauthorized",
390 { label: "onCompleted",
391 event: "onCompleted",
397 responseHeadersExist: true,
398 statusLine: "HTTP/1.1 401 Unauthorized",
403 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
404 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
407 {urls: ["<all_urls>"]}, ["asyncBlocking", "responseHeaders"]);
408 navigateAndWait(url);
411 // onAuthRequired is an async function that cancels the auth attempt.
412 function authRequiredAsyncCancelAuth() {
413 var realm = 'asynccancel';
414 var url = getURLAuthRequired(realm);
417 { label: "onBeforeRequest",
418 event: "onBeforeRequest",
425 { label: "onBeforeSendHeaders",
426 event: "onBeforeSendHeaders",
429 // Note: no requestHeaders because we don't ask for them.
433 { label: "onSendHeaders",
434 event: "onSendHeaders",
439 { label: "onHeadersReceived",
440 event: "onHeadersReceived",
443 responseHeadersExist: true,
444 statusLine: "HTTP/1.1 401 Unauthorized"
447 { label: "onAuthRequired",
448 event: "onAuthRequired",
454 challenger: {host: testServer, port: testServerPort},
455 responseHeadersExist: true,
456 statusLine: "HTTP/1.1 401 Unauthorized",
458 retval: {cancel: true}
460 { label: "onResponseStarted",
461 event: "onResponseStarted",
467 responseHeadersExist: true,
468 statusLine: "HTTP/1.1 401 Unauthorized",
471 { label: "onCompleted",
472 event: "onCompleted",
478 responseHeadersExist: true,
479 statusLine: "HTTP/1.1 401 Unauthorized",
484 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
485 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
488 {urls: ["<all_urls>"]},
489 ["responseHeaders", "asyncBlocking"]);
490 navigateAndWait(url);
493 // onAuthRequired is an async function that sets authentication credentials.
494 function authRequiredAsyncSetAuth() {
495 var realm = 'asyncsetauth';
496 var url = getURLAuthRequired(realm);
499 { label: "onBeforeRequest",
500 event: "onBeforeRequest",
507 { label: "onBeforeSendHeaders",
508 event: "onBeforeSendHeaders",
511 // Note: no requestHeaders because we don't ask for them.
515 { label: "onSendHeaders",
516 event: "onSendHeaders",
521 { label: "onHeadersReceived",
522 event: "onHeadersReceived",
525 responseHeadersExist: true,
526 statusLine: "HTTP/1.1 401 Unauthorized"
529 { label: "onAuthRequired",
530 event: "onAuthRequired",
536 challenger: {host: testServer, port: testServerPort},
537 responseHeadersExist: true,
538 statusLine: "HTTP/1.1 401 Unauthorized",
540 retval: {authCredentials: {username: "foo", password: "secret"}}
542 { label: "onResponseStarted",
543 event: "onResponseStarted",
549 responseHeadersExist: true,
550 statusLine: "HTTP/1.1 200 OK",
553 { label: "onCompleted",
554 event: "onCompleted",
560 responseHeadersExist: true,
561 statusLine: "HTTP/1.1 200 OK",
566 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
567 "onHeadersReceived", "onAuthRequired", "onResponseStarted",
570 {urls: ["<all_urls>"]},
571 ["responseHeaders", "asyncBlocking"]);
572 navigateAndWait(url);