OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var pass = chrome.test.callbackPass; | 5 var pass = chrome.test.callbackPass; |
6 | 6 |
7 // Constants as functions, not to be called until after runTests. | 7 // Constants as functions, not to be called until after runTests. |
8 function getURLEchoUserAgent() { | 8 function getURLEchoUserAgent() { |
9 return getServerURL('echoheader?User-Agent'); | 9 return getServerURL('echoheader?User-Agent'); |
10 } | 10 } |
11 | 11 |
12 function getURLSetCookie() { | 12 function getURLSetCookie() { |
13 return getServerURL('set-cookie?Foo=Bar'); | 13 return getServerURL('set-cookie?Foo=Bar'); |
14 } | 14 } |
15 | 15 |
16 function getURLNonUTF8SetCookie() { | 16 function getURLNonUTF8SetCookie() { |
17 return getServerURL('set-header?Set-Cookie%3A%20Foo%3D%FE%D1'); | 17 return getServerURL('set-header?Set-Cookie%3A%20Foo%3D%FE%D1'); |
18 } | 18 } |
19 | 19 |
20 function getURLHttpSimpleLoad() { | 20 function getURLHttpSimpleLoad() { |
21 return getServerURL('files/extensions/api_test/webrequest/simpleLoad/a.html'); | 21 return getServerURL('extensions/api_test/webrequest/simpleLoad/a.html'); |
22 } | 22 } |
23 function getURLHttpXHRData() { | 23 function getURLHttpXHRData() { |
24 return getServerURL('files/extensions/api_test/webrequest/xhr/data.json'); | 24 return getServerURL('extensions/api_test/webrequest/xhr/data.json'); |
25 } | 25 } |
26 | 26 |
27 function toCharCodes(str) { | 27 function toCharCodes(str) { |
28 var result = []; | 28 var result = []; |
29 for (var i = 0; i < str.length; ++i) { | 29 for (var i = 0; i < str.length; ++i) { |
30 result[i] = str.charCodeAt(i); | 30 result[i] = str.charCodeAt(i); |
31 } | 31 } |
32 return result; | 32 return result; |
33 } | 33 } |
34 | 34 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 { label: "onSendHeaders", | 93 { label: "onSendHeaders", |
94 event: "onSendHeaders", | 94 event: "onSendHeaders", |
95 details: { | 95 details: { |
96 url: getURLHttpSimpleLoad() | 96 url: getURLHttpSimpleLoad() |
97 } | 97 } |
98 }, | 98 }, |
99 { label: "onHeadersReceived", | 99 { label: "onHeadersReceived", |
100 event: "onHeadersReceived", | 100 event: "onHeadersReceived", |
101 details: { | 101 details: { |
102 url: getURLHttpSimpleLoad(), | 102 url: getURLHttpSimpleLoad(), |
103 statusLine: "HTTP/1.0 200 OK", | 103 statusLine: "HTTP/1.1 200 OK", |
104 }, | 104 }, |
105 retval: {cancel: true} | 105 retval: {cancel: true} |
106 }, | 106 }, |
107 // Cancelling is considered an error. | 107 // Cancelling is considered an error. |
108 { label: "onErrorOccurred", | 108 { label: "onErrorOccurred", |
109 event: "onErrorOccurred", | 109 event: "onErrorOccurred", |
110 details: { | 110 details: { |
111 url: getURLHttpSimpleLoad(), | 111 url: getURLHttpSimpleLoad(), |
112 fromCache: false, | 112 fromCache: false, |
113 error: "net::ERR_BLOCKED_BY_CLIENT" | 113 error: "net::ERR_BLOCKED_BY_CLIENT" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 { label: "onSendHeaders", | 208 { label: "onSendHeaders", |
209 event: "onSendHeaders", | 209 event: "onSendHeaders", |
210 details: { | 210 details: { |
211 url: getURLEchoUserAgent() | 211 url: getURLEchoUserAgent() |
212 } | 212 } |
213 }, | 213 }, |
214 { label: "onHeadersReceived", | 214 { label: "onHeadersReceived", |
215 event: "onHeadersReceived", | 215 event: "onHeadersReceived", |
216 details: { | 216 details: { |
217 url: getURLEchoUserAgent(), | 217 url: getURLEchoUserAgent(), |
218 statusLine: "HTTP/1.0 200 OK", | 218 statusLine: "HTTP/1.1 200 OK", |
219 } | 219 } |
220 }, | 220 }, |
221 { label: "onResponseStarted", | 221 { label: "onResponseStarted", |
222 event: "onResponseStarted", | 222 event: "onResponseStarted", |
223 details: { | 223 details: { |
224 url: getURLEchoUserAgent(), | 224 url: getURLEchoUserAgent(), |
225 fromCache: false, | 225 fromCache: false, |
226 statusCode: 200, | 226 statusCode: 200, |
227 ip: "127.0.0.1", | 227 ip: "127.0.0.1", |
228 statusLine: "HTTP/1.0 200 OK", | 228 statusLine: "HTTP/1.1 200 OK", |
229 } | 229 } |
230 }, | 230 }, |
231 { label: "onCompleted", | 231 { label: "onCompleted", |
232 event: "onCompleted", | 232 event: "onCompleted", |
233 details: { | 233 details: { |
234 url: getURLEchoUserAgent(), | 234 url: getURLEchoUserAgent(), |
235 fromCache: false, | 235 fromCache: false, |
236 statusCode: 200, | 236 statusCode: 200, |
237 ip: "127.0.0.1", | 237 ip: "127.0.0.1", |
238 statusLine: "HTTP/1.0 200 OK", | 238 statusLine: "HTTP/1.1 200 OK", |
239 } | 239 } |
240 }, | 240 }, |
241 ], | 241 ], |
242 [ // event order | 242 [ // event order |
243 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | 243 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
244 "onHeadersReceived", "onResponseStarted", "onCompleted"] | 244 "onHeadersReceived", "onResponseStarted", "onCompleted"] |
245 ], | 245 ], |
246 {urls: ["<all_urls>"]}, ["blocking"]); | 246 {urls: ["<all_urls>"]}, ["blocking"]); |
247 // Check the page content for our modified User-Agent string. | 247 // Check the page content for our modified User-Agent string. |
248 navigateAndWait(getURLEchoUserAgent(), function() { | 248 navigateAndWait(getURLEchoUserAgent(), function() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 { label: "onSendHeaders", | 283 { label: "onSendHeaders", |
284 event: "onSendHeaders", | 284 event: "onSendHeaders", |
285 details: { | 285 details: { |
286 url: getURLEchoUserAgent() | 286 url: getURLEchoUserAgent() |
287 } | 287 } |
288 }, | 288 }, |
289 { label: "onHeadersReceived", | 289 { label: "onHeadersReceived", |
290 event: "onHeadersReceived", | 290 event: "onHeadersReceived", |
291 details: { | 291 details: { |
292 url: getURLEchoUserAgent(), | 292 url: getURLEchoUserAgent(), |
293 statusLine: "HTTP/1.0 200 OK", | 293 statusLine: "HTTP/1.1 200 OK", |
294 } | 294 } |
295 }, | 295 }, |
296 { label: "onResponseStarted", | 296 { label: "onResponseStarted", |
297 event: "onResponseStarted", | 297 event: "onResponseStarted", |
298 details: { | 298 details: { |
299 url: getURLEchoUserAgent(), | 299 url: getURLEchoUserAgent(), |
300 fromCache: false, | 300 fromCache: false, |
301 statusCode: 200, | 301 statusCode: 200, |
302 ip: "127.0.0.1", | 302 ip: "127.0.0.1", |
303 statusLine: "HTTP/1.0 200 OK", | 303 statusLine: "HTTP/1.1 200 OK", |
304 } | 304 } |
305 }, | 305 }, |
306 { label: "onCompleted", | 306 { label: "onCompleted", |
307 event: "onCompleted", | 307 event: "onCompleted", |
308 details: { | 308 details: { |
309 url: getURLEchoUserAgent(), | 309 url: getURLEchoUserAgent(), |
310 fromCache: false, | 310 fromCache: false, |
311 statusCode: 200, | 311 statusCode: 200, |
312 ip: "127.0.0.1", | 312 ip: "127.0.0.1", |
313 statusLine: "HTTP/1.0 200 OK", | 313 statusLine: "HTTP/1.1 200 OK", |
314 } | 314 } |
315 }, | 315 }, |
316 ], | 316 ], |
317 [ // event order | 317 [ // event order |
318 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | 318 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
319 "onHeadersReceived", "onResponseStarted", "onCompleted"] | 319 "onHeadersReceived", "onResponseStarted", "onCompleted"] |
320 ], | 320 ], |
321 {urls: ["<all_urls>"]}, ["blocking"]); | 321 {urls: ["<all_urls>"]}, ["blocking"]); |
322 // Check the page content for our modified User-Agent string. | 322 // Check the page content for our modified User-Agent string. |
323 navigateAndWait(getURLEchoUserAgent(), function() { | 323 navigateAndWait(getURLEchoUserAgent(), function() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 { label: "onSendHeaders", | 356 { label: "onSendHeaders", |
357 event: "onSendHeaders", | 357 event: "onSendHeaders", |
358 details: { | 358 details: { |
359 url: getURLSetCookie(), | 359 url: getURLSetCookie(), |
360 } | 360 } |
361 }, | 361 }, |
362 { label: "onHeadersReceived", | 362 { label: "onHeadersReceived", |
363 event: "onHeadersReceived", | 363 event: "onHeadersReceived", |
364 details: { | 364 details: { |
365 url: getURLSetCookie(), | 365 url: getURLSetCookie(), |
366 statusLine: "HTTP/1.0 200 OK", | 366 statusLine: "HTTP/1.1 200 OK", |
367 responseHeadersExist: true, | 367 responseHeadersExist: true, |
368 }, | 368 }, |
369 retval_function: function(name, details) { | 369 retval_function: function(name, details) { |
370 responseHeaders = details.responseHeaders; | 370 responseHeaders = details.responseHeaders; |
371 var found = false; | 371 var found = false; |
372 for (var i = 0; i < responseHeaders.length; ++i) { | 372 for (var i = 0; i < responseHeaders.length; ++i) { |
373 if (responseHeaders[i].name === "Set-Cookie" && | 373 if (responseHeaders[i].name === "Set-Cookie" && |
374 responseHeaders[i].value.indexOf("Foo") != -1) { | 374 responseHeaders[i].value.indexOf("Foo") != -1) { |
375 found = true; | 375 found = true; |
376 responseHeaders.splice(i); | 376 responseHeaders.splice(i); |
377 break; | 377 break; |
378 } | 378 } |
379 } | 379 } |
380 chrome.test.assertTrue(found); | 380 chrome.test.assertTrue(found); |
381 return {responseHeaders: responseHeaders}; | 381 return {responseHeaders: responseHeaders}; |
382 } | 382 } |
383 }, | 383 }, |
384 { label: "onResponseStarted", | 384 { label: "onResponseStarted", |
385 event: "onResponseStarted", | 385 event: "onResponseStarted", |
386 details: { | 386 details: { |
387 url: getURLSetCookie(), | 387 url: getURLSetCookie(), |
388 fromCache: false, | 388 fromCache: false, |
389 statusCode: 200, | 389 statusCode: 200, |
390 statusLine: "HTTP/1.0 200 OK", | 390 statusLine: "HTTP/1.1 200 OK", |
391 ip: "127.0.0.1", | 391 ip: "127.0.0.1", |
392 responseHeadersExist: true, | 392 responseHeadersExist: true, |
393 } | 393 } |
394 }, | 394 }, |
395 { label: "onCompleted", | 395 { label: "onCompleted", |
396 event: "onCompleted", | 396 event: "onCompleted", |
397 details: { | 397 details: { |
398 url: getURLSetCookie(), | 398 url: getURLSetCookie(), |
399 fromCache: false, | 399 fromCache: false, |
400 statusCode: 200, | 400 statusCode: 200, |
401 statusLine: "HTTP/1.0 200 OK", | 401 statusLine: "HTTP/1.1 200 OK", |
402 ip: "127.0.0.1", | 402 ip: "127.0.0.1", |
403 responseHeadersExist: true, | 403 responseHeadersExist: true, |
404 } | 404 } |
405 }, | 405 }, |
406 ], | 406 ], |
407 [ // event order | 407 [ // event order |
408 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | 408 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
409 "onHeadersReceived", "onResponseStarted", "onCompleted"] | 409 "onHeadersReceived", "onResponseStarted", "onCompleted"] |
410 ], | 410 ], |
411 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]); | 411 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 { label: "onSendHeaders", | 446 { label: "onSendHeaders", |
447 event: "onSendHeaders", | 447 event: "onSendHeaders", |
448 details: { | 448 details: { |
449 url: getURLNonUTF8SetCookie(), | 449 url: getURLNonUTF8SetCookie(), |
450 } | 450 } |
451 }, | 451 }, |
452 { label: "onHeadersReceived", | 452 { label: "onHeadersReceived", |
453 event: "onHeadersReceived", | 453 event: "onHeadersReceived", |
454 details: { | 454 details: { |
455 url: getURLNonUTF8SetCookie(), | 455 url: getURLNonUTF8SetCookie(), |
456 statusLine: "HTTP/1.0 200 OK", | 456 statusLine: "HTTP/1.1 200 OK", |
457 responseHeadersExist: true, | 457 responseHeadersExist: true, |
458 }, | 458 }, |
459 retval_function: function(name, details) { | 459 retval_function: function(name, details) { |
460 responseHeaders = details.responseHeaders; | 460 responseHeaders = details.responseHeaders; |
461 var found = false; | 461 var found = false; |
462 var expectedValue = [ | 462 var expectedValue = [ |
463 "F".charCodeAt(0), | 463 "F".charCodeAt(0), |
464 "o".charCodeAt(0), | 464 "o".charCodeAt(0), |
465 "o".charCodeAt(0), | 465 "o".charCodeAt(0), |
466 0x3D, 0xFE, 0xD1 | 466 0x3D, 0xFE, 0xD1 |
(...skipping 10 matching lines...) Expand all Loading... |
477 chrome.test.assertTrue(found); | 477 chrome.test.assertTrue(found); |
478 return {responseHeaders: responseHeaders}; | 478 return {responseHeaders: responseHeaders}; |
479 } | 479 } |
480 }, | 480 }, |
481 { label: "onResponseStarted", | 481 { label: "onResponseStarted", |
482 event: "onResponseStarted", | 482 event: "onResponseStarted", |
483 details: { | 483 details: { |
484 url: getURLNonUTF8SetCookie(), | 484 url: getURLNonUTF8SetCookie(), |
485 fromCache: false, | 485 fromCache: false, |
486 statusCode: 200, | 486 statusCode: 200, |
487 statusLine: "HTTP/1.0 200 OK", | 487 statusLine: "HTTP/1.1 200 OK", |
488 ip: "127.0.0.1", | 488 ip: "127.0.0.1", |
489 responseHeadersExist: true, | 489 responseHeadersExist: true, |
490 } | 490 } |
491 }, | 491 }, |
492 { label: "onCompleted", | 492 { label: "onCompleted", |
493 event: "onCompleted", | 493 event: "onCompleted", |
494 details: { | 494 details: { |
495 url: getURLNonUTF8SetCookie(), | 495 url: getURLNonUTF8SetCookie(), |
496 fromCache: false, | 496 fromCache: false, |
497 statusCode: 200, | 497 statusCode: 200, |
498 statusLine: "HTTP/1.0 200 OK", | 498 statusLine: "HTTP/1.1 200 OK", |
499 ip: "127.0.0.1", | 499 ip: "127.0.0.1", |
500 responseHeadersExist: true, | 500 responseHeadersExist: true, |
501 } | 501 } |
502 }, | 502 }, |
503 ], | 503 ], |
504 [ // event order | 504 [ // event order |
505 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | 505 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
506 "onHeadersReceived", "onResponseStarted", "onCompleted"] | 506 "onHeadersReceived", "onResponseStarted", "onCompleted"] |
507 ], | 507 ], |
508 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]); | 508 {urls: ["<all_urls>"]}, ["blocking", "responseHeaders"]); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 tabId: 1, | 559 tabId: 1, |
560 type: "xmlhttprequest", | 560 type: "xmlhttprequest", |
561 } | 561 } |
562 }, | 562 }, |
563 { label: "x-onResponseStarted", | 563 { label: "x-onResponseStarted", |
564 event: "onResponseStarted", | 564 event: "onResponseStarted", |
565 details: { | 565 details: { |
566 url: getURLHttpXHRData(), | 566 url: getURLHttpXHRData(), |
567 statusCode: 200, | 567 statusCode: 200, |
568 fromCache: false, | 568 fromCache: false, |
569 statusLine: "HTTP/1.0 200 OK", | 569 statusLine: "HTTP/1.1 200 OK", |
570 tabId: 1, | 570 tabId: 1, |
571 type: "xmlhttprequest", | 571 type: "xmlhttprequest", |
572 ip: "127.0.0.1", | 572 ip: "127.0.0.1", |
573 // Request to chrome-extension:// url has no IP. | 573 // Request to chrome-extension:// url has no IP. |
574 } | 574 } |
575 }, | 575 }, |
576 { label: "x-onCompleted", | 576 { label: "x-onCompleted", |
577 event: "onCompleted", | 577 event: "onCompleted", |
578 details: { | 578 details: { |
579 url: getURLHttpXHRData(), | 579 url: getURLHttpXHRData(), |
580 statusCode: 200, | 580 statusCode: 200, |
581 fromCache: false, | 581 fromCache: false, |
582 statusLine: "HTTP/1.0 200 OK", | 582 statusLine: "HTTP/1.1 200 OK", |
583 tabId: 1, | 583 tabId: 1, |
584 type: "xmlhttprequest", | 584 type: "xmlhttprequest", |
585 ip: "127.0.0.1", | 585 ip: "127.0.0.1", |
586 // Request to chrome-extension:// url has no IP. | 586 // Request to chrome-extension:// url has no IP. |
587 } | 587 } |
588 }, | 588 }, |
589 { label: "b-onBeforeRequest", | 589 { label: "b-onBeforeRequest", |
590 event: "onBeforeRequest", | 590 event: "onBeforeRequest", |
591 details: { | 591 details: { |
592 url: getURL("complexLoad/b.jpg"), | 592 url: getURL("complexLoad/b.jpg"), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 tabId: 1, | 688 tabId: 1, |
689 type: "xmlhttprequest", | 689 type: "xmlhttprequest", |
690 } | 690 } |
691 }, | 691 }, |
692 { label: "x-onResponseStarted", | 692 { label: "x-onResponseStarted", |
693 event: "onResponseStarted", | 693 event: "onResponseStarted", |
694 details: { | 694 details: { |
695 url: getURLHttpXHRData(), | 695 url: getURLHttpXHRData(), |
696 statusCode: 200, | 696 statusCode: 200, |
697 fromCache: false, | 697 fromCache: false, |
698 statusLine: "HTTP/1.0 200 OK", | 698 statusLine: "HTTP/1.1 200 OK", |
699 tabId: 1, | 699 tabId: 1, |
700 type: "xmlhttprequest", | 700 type: "xmlhttprequest", |
701 ip: "127.0.0.1", | 701 ip: "127.0.0.1", |
702 // Request to chrome-extension:// url has no IP. | 702 // Request to chrome-extension:// url has no IP. |
703 } | 703 } |
704 }, | 704 }, |
705 { | 705 { |
706 label: "x-onHeadersReceived", | 706 label: "x-onHeadersReceived", |
707 event: "onHeadersReceived", | 707 event: "onHeadersReceived", |
708 details: { | 708 details: { |
709 url: getURLHttpXHRData(), | 709 url: getURLHttpXHRData(), |
710 tabId: 1, | 710 tabId: 1, |
711 type: "xmlhttprequest", | 711 type: "xmlhttprequest", |
712 statusLine: "HTTP/1.0 200 OK", | 712 statusLine: "HTTP/1.1 200 OK", |
713 } | 713 } |
714 }, | 714 }, |
715 { label: "x-onCompleted", | 715 { label: "x-onCompleted", |
716 event: "onCompleted", | 716 event: "onCompleted", |
717 details: { | 717 details: { |
718 url: getURLHttpXHRData(), | 718 url: getURLHttpXHRData(), |
719 statusCode: 200, | 719 statusCode: 200, |
720 fromCache: false, | 720 fromCache: false, |
721 statusLine: "HTTP/1.0 200 OK", | 721 statusLine: "HTTP/1.1 200 OK", |
722 tabId: 1, | 722 tabId: 1, |
723 type: "xmlhttprequest", | 723 type: "xmlhttprequest", |
724 ip: "127.0.0.1", | 724 ip: "127.0.0.1", |
725 // Request to chrome-extension:// url has no IP. | 725 // Request to chrome-extension:// url has no IP. |
726 } | 726 } |
727 }, | 727 }, |
728 { label: "b-onBeforeRequest", | 728 { label: "b-onBeforeRequest", |
729 event: "onBeforeRequest", | 729 event: "onBeforeRequest", |
730 details: { | 730 details: { |
731 url: getURL("complexLoad/b.jpg"), | 731 url: getURL("complexLoad/b.jpg"), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 // Check the page content for our modified User-Agent string. | 764 // Check the page content for our modified User-Agent string. |
765 navigateAndWait(getURL("simpleLoad/a.html"), function() { | 765 navigateAndWait(getURL("simpleLoad/a.html"), function() { |
766 var req = new XMLHttpRequest(); | 766 var req = new XMLHttpRequest(); |
767 var asynchronous = true; | 767 var asynchronous = true; |
768 req.open("GET", getURLHttpXHRData(), asynchronous); | 768 req.open("GET", getURLHttpXHRData(), asynchronous); |
769 req.send(null); | 769 req.send(null); |
770 navigateAndWait(getURL("complexLoad/b.jpg")); | 770 navigateAndWait(getURL("complexLoad/b.jpg")); |
771 }); | 771 }); |
772 }, | 772 }, |
773 ]); | 773 ]); |
OLD | NEW |