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

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/events/test.html

Issue 7599027: Add support for XMLHttpRequests to the webRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months 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 | Annotate | Revision Log
OLDNEW
1 <script> 1 <script>
2 var getURL = chrome.extension.getURL; 2 var getURL = chrome.extension.getURL;
3 var deepEq = chrome.test.checkDeepEq; 3 var deepEq = chrome.test.checkDeepEq;
4 var expectedEventData; 4 var expectedEventData;
5 var capturedEventData; 5 var capturedEventData;
6 var expectedEventOrder; 6 var expectedEventOrder;
7 var tabId; 7 var tabId;
8 var eventsCaptured; 8 var eventsCaptured;
9 9
10 // PORT will be changed to the port of the test server. 10 // PORT will be changed to the port of the test server.
11 var URL_HTTP_SIMPLE_LOAD = 11 var URL_HTTP_SIMPLE_LOAD =
12 'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/simpleLoa d/a.html'; 12 'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/simpleLoa d/a.html';
13 var URL_HTTP_SIMPLE_LOAD_REDIRECT = 13 var URL_HTTP_SIMPLE_LOAD_REDIRECT =
14 'http://www.a.com:PORT/server-redirect?'+URL_HTTP_SIMPLE_LOAD; 14 'http://www.a.com:PORT/server-redirect?'+URL_HTTP_SIMPLE_LOAD;
15 var URL_ECHO_USER_AGENT = 15 var URL_ECHO_USER_AGENT =
16 'http://www.a.com:PORT/echoheader?User-Agent'; 16 'http://www.a.com:PORT/echoheader?User-Agent';
17 var URL_AUTH_REQUIRED = 17 var URL_AUTH_REQUIRED =
18 'http://www.a.com:PORT/auth-basic'; 18 'http://www.a.com:PORT/auth-basic';
19 var URL_HTTP_XHR =
20 'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/xhr/a.htm l';
21 var URL_HTTP_XHR_DATA =
22 'http://www.a.com:PORT/files/extensions/api_test/webrequest/events/xhr/data. json';
19 23
20 function runTests(tests) { 24 function runTests(tests) {
21 chrome.tabs.getSelected(null, function(tab) { 25 chrome.tabs.getSelected(null, function(tab) {
22 tabId = tab.id; 26 tabId = tab.id;
23 chrome.test.getConfig(function(config) { 27 chrome.test.getConfig(function(config) {
24 var fixPort = function(url) { 28 var fixPort = function(url) {
25 return url.replace(/PORT/g, config.testServer.port); 29 return url.replace(/PORT/g, config.testServer.port);
26 }; 30 };
27 URL_HTTP_SIMPLE_LOAD = fixPort(URL_HTTP_SIMPLE_LOAD); 31 URL_HTTP_SIMPLE_LOAD = fixPort(URL_HTTP_SIMPLE_LOAD);
28 URL_HTTP_SIMPLE_LOAD_REDIRECT = fixPort(URL_HTTP_SIMPLE_LOAD_REDIRECT); 32 URL_HTTP_SIMPLE_LOAD_REDIRECT = fixPort(URL_HTTP_SIMPLE_LOAD_REDIRECT);
29 URL_ECHO_USER_AGENT = fixPort(URL_ECHO_USER_AGENT); 33 URL_ECHO_USER_AGENT = fixPort(URL_ECHO_USER_AGENT);
30 URL_AUTH_REQUIRED = fixPort(URL_AUTH_REQUIRED); 34 URL_AUTH_REQUIRED = fixPort(URL_AUTH_REQUIRED);
35 URL_HTTP_XHR = fixPort(URL_HTTP_XHR);
36 URL_HTTP_XHR_DATA = fixPort(URL_HTTP_XHR_DATA);
31 37
32 chrome.test.runTests(tests); 38 chrome.test.runTests(tests);
33 }); 39 });
34 }); 40 });
35 } 41 }
36 42
37 // Helper to advance to the next test only when the tab has finished loading. 43 // Helper to advance to the next test only when the tab has finished loading.
38 // This is because tabs.update can sometimes fail if the tab is in the middle 44 // This is because tabs.update can sometimes fail if the tab is in the middle
39 // of a navigation (from the previous test), resulting in flakiness. 45 // of a navigation (from the previous test), resulting in flakiness.
40 function navigateAndWait(url, callback) { 46 function navigateAndWait(url, callback) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 [ // event order 381 [ // event order
376 ["onBeforeRequest-1", "onBeforeSendHeaders-1", "onSendHeaders-1", 382 ["onBeforeRequest-1", "onBeforeSendHeaders-1", "onSendHeaders-1",
377 "onBeforeRedirect", 383 "onBeforeRedirect",
378 "onBeforeRequest-2", "onBeforeSendHeaders-2", "onSendHeaders-2", 384 "onBeforeRequest-2", "onBeforeSendHeaders-2", "onSendHeaders-2",
379 "onResponseStarted", "onCompleted"] ], 385 "onResponseStarted", "onCompleted"] ],
380 {}, // filter 386 {}, // filter
381 ["requestHeaders", "responseHeaders", "statusLine"]); 387 ["requestHeaders", "responseHeaders", "statusLine"]);
382 navigateAndWait(URL_HTTP_SIMPLE_LOAD_REDIRECT); 388 navigateAndWait(URL_HTTP_SIMPLE_LOAD_REDIRECT);
383 }, 389 },
384 390
391 // Navigates to a page to generates an XHR.
392 function xhrLoad() {
393 expect(
394 [ // events
395 { label: "onBeforeRequest-1",
396 event: "onBeforeRequest",
397 details: {
398 method: "GET",
399 tabId: tabId,
400 type: "main_frame",
401 url: URL_HTTP_XHR,
402 frameUrl: URL_HTTP_XHR
403 }
404 },
405 { label: "onBeforeSendHeaders-1",
406 event: "onBeforeSendHeaders",
407 details: {
408 url: URL_HTTP_XHR,
409 }
410 },
411 { label: "onSendHeaders-1",
412 event: "onSendHeaders",
413 details: {
414 url: URL_HTTP_XHR,
415 }
416 },
417 { label: "onResponseStarted-1",
418 event: "onResponseStarted",
419 details: {
420 url: URL_HTTP_XHR,
421 statusCode: 200,
422 ip: "127.0.0.1",
423 fromCache: false,
424 }
425 },
426 { label: "onCompleted-1",
427 event: "onCompleted",
428 details: {
429 url: URL_HTTP_XHR,
430 statusCode: 200,
431 ip: "127.0.0.1",
432 fromCache: false,
433 }
434 },
435 { label: "onBeforeRequest-2",
436 event: "onBeforeRequest",
437 details: {
438 method: "GET",
439 tabId: tabId,
440 type: "xmlhttprequest",
441 url: URL_HTTP_XHR_DATA,
442 frameUrl: URL_HTTP_XHR
443 }
444 },
445 { label: "onBeforeSendHeaders-2",
446 event: "onBeforeSendHeaders",
447 details: {
448 url: URL_HTTP_XHR_DATA,
449 }
450 },
451 { label: "onSendHeaders-2",
452 event: "onSendHeaders",
453 details: {
454 url: URL_HTTP_XHR_DATA,
455 }
456 },
457 { label: "onResponseStarted-2",
458 event: "onResponseStarted",
459 details: {
460 url: URL_HTTP_XHR_DATA,
461 statusCode: 200,
462 ip: "127.0.0.1",
463 fromCache: false,
464 }
465 },
466 { label: "onCompleted-2",
467 event: "onCompleted",
468 details: {
469 url: URL_HTTP_XHR_DATA,
470 statusCode: 200,
471 ip: "127.0.0.1",
472 fromCache: false,
473 }
474 }
475 ],
476 [ // event order
477 ["onBeforeRequest-1", "onBeforeSendHeaders-1", "onSendHeaders-1",
478 "onResponseStarted-1", "onCompleted-1",
479 "onBeforeRequest-2", "onBeforeSendHeaders-2", "onSendHeaders-2",
480 "onResponseStarted-2", "onCompleted-2"] ],
481 {}, []);
482 navigateAndWait(URL_HTTP_XHR);
483 },
484
385 // Navigates to a page with subresources. 485 // Navigates to a page with subresources.
386 // TODO(mpcomplete): add multiple subresources; requires support for 486 // TODO(mpcomplete): add multiple subresources; requires support for
387 // recognizing partial ordering. 487 // recognizing partial ordering.
388 function complexLoad() { 488 function complexLoad() {
389 expect( 489 expect(
390 [ // events 490 [ // events
391 { label: "a.html-onBeforeRequest", 491 { label: "a.html-onBeforeRequest",
392 event: "onBeforeRequest", 492 event: "onBeforeRequest",
393 details: { 493 details: {
394 method: "GET", 494 method: "GET",
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 ], 919 ],
820 [ // event order 920 [ // event order
821 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", 921 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders",
822 "onAuthRequired", "onResponseStarted", "onCompleted"] 922 "onAuthRequired", "onResponseStarted", "onCompleted"]
823 ], 923 ],
824 {}, []); 924 {}, []);
825 navigateAndWait(URL_AUTH_REQUIRED); 925 navigateAndWait(URL_AUTH_REQUIRED);
826 }, 926 },
827 ]); 927 ]);
828 </script> 928 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698