OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 382 |
383 this.takeControl(); | 383 this.takeControl(); |
384 }; | 384 }; |
385 | 385 |
386 /** | 386 /** |
387 * Tests network size. | 387 * Tests network size. |
388 */ | 388 */ |
389 TestSuite.prototype.testNetworkSize = function() { | 389 TestSuite.prototype.testNetworkSize = function() { |
390 var test = this; | 390 var test = this; |
391 | 391 |
392 function finishResource(resource, finishTime) { | 392 function finishRequest(request, finishTime) { |
393 test.assertEquals(25, resource.resourceSize, 'Incorrect total data length'
); | 393 test.assertEquals(25, request.resourceSize, 'Incorrect total data length')
; |
394 test.releaseControl(); | 394 test.releaseControl(); |
395 } | 395 } |
396 | 396 |
397 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); | 397 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishRequest); |
398 | 398 |
399 // Reload inspected page to sniff network events | 399 // Reload inspected page to sniff network events |
400 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); | 400 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); |
401 | 401 |
402 this.takeControl(); | 402 this.takeControl(); |
403 }; | 403 }; |
404 | 404 |
405 /** | 405 /** |
406 * Tests network sync size. | 406 * Tests network sync size. |
407 */ | 407 */ |
408 TestSuite.prototype.testNetworkSyncSize = function() { | 408 TestSuite.prototype.testNetworkSyncSize = function() { |
409 var test = this; | 409 var test = this; |
410 | 410 |
411 function finishResource(resource, finishTime) { | 411 function finishRequest(request, finishTime) { |
412 test.assertEquals(25, resource.resourceSize, 'Incorrect total data length'
); | 412 test.assertEquals(25, request.resourceSize, 'Incorrect total data length')
; |
413 test.releaseControl(); | 413 test.releaseControl(); |
414 } | 414 } |
415 | 415 |
416 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); | 416 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishRequest); |
417 | 417 |
418 // Send synchronous XHR to sniff network events | 418 // Send synchronous XHR to sniff network events |
419 test.evaluateInConsole_( | 419 test.evaluateInConsole_( |
420 'var xhr = new XMLHttpRequest(); xhr.open("GET", "chunked", false); xhr.
send(null);', function() {}); | 420 'var xhr = new XMLHttpRequest(); xhr.open("GET", "chunked", false); xhr.
send(null);', function() {}); |
421 | 421 |
422 this.takeControl(); | 422 this.takeControl(); |
423 }; | 423 }; |
424 | 424 |
425 /** | 425 /** |
426 * Tests network raw headers text. | 426 * Tests network raw headers text. |
427 */ | 427 */ |
428 TestSuite.prototype.testNetworkRawHeadersText = function() { | 428 TestSuite.prototype.testNetworkRawHeadersText = function() { |
429 var test = this; | 429 var test = this; |
430 | 430 |
431 function finishResource(resource, finishTime) { | 431 function finishRequest(request, finishTime) { |
432 if (!resource.responseHeadersText) | 432 if (!request.responseHeadersText) |
433 test.fail('Failure: resource does not have response headers text'); | 433 test.fail('Failure: resource does not have response headers text'); |
434 var index = resource.responseHeadersText.indexOf('Date:'); | 434 var index = request.responseHeadersText.indexOf('Date:'); |
435 test.assertEquals( | 435 test.assertEquals( |
436 112, resource.responseHeadersText.substring(index).length, 'Incorrect
response headers text length'); | 436 112, request.responseHeadersText.substring(index).length, 'Incorrect r
esponse headers text length'); |
437 test.releaseControl(); | 437 test.releaseControl(); |
438 } | 438 } |
439 | 439 |
440 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); | 440 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishRequest); |
441 | 441 |
442 // Reload inspected page to sniff network events | 442 // Reload inspected page to sniff network events |
443 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); | 443 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); |
444 | 444 |
445 this.takeControl(); | 445 this.takeControl(); |
446 }; | 446 }; |
447 | 447 |
448 /** | 448 /** |
449 * Tests network timing. | 449 * Tests network timing. |
450 */ | 450 */ |
451 TestSuite.prototype.testNetworkTiming = function() { | 451 TestSuite.prototype.testNetworkTiming = function() { |
452 var test = this; | 452 var test = this; |
453 | 453 |
454 function finishResource(resource, finishTime) { | 454 function finishRequest(request, finishTime) { |
455 // Setting relaxed expectations to reduce flakiness. | 455 // Setting relaxed expectations to reduce flakiness. |
456 // Server sends headers after 100ms, then sends data during another 100ms. | 456 // Server sends headers after 100ms, then sends data during another 100ms. |
457 // We expect these times to be measured at least as 70ms. | 457 // We expect these times to be measured at least as 70ms. |
458 test.assertTrue( | 458 test.assertTrue( |
459 resource.timing.receiveHeadersEnd - resource.timing.connectStart >= 70
, | 459 request.timing.receiveHeadersEnd - request.timing.connectStart >= 70, |
460 'Time between receiveHeadersEnd and connectStart should be >=70ms, but
was ' + | 460 'Time between receiveHeadersEnd and connectStart should be >=70ms, but
was ' + |
461 'receiveHeadersEnd=' + resource.timing.receiveHeadersEnd + ', conn
ectStart=' + | 461 'receiveHeadersEnd=' + request.timing.receiveHeadersEnd + ', conne
ctStart=' + |
462 resource.timing.connectStart + '.'); | 462 request.timing.connectStart + '.'); |
463 test.assertTrue( | 463 test.assertTrue( |
464 resource.responseReceivedTime - resource.startTime >= 0.07, | 464 request.responseReceivedTime - request.startTime >= 0.07, |
465 'Time between responseReceivedTime and startTime should be >=0.07s, bu
t was ' + | 465 'Time between responseReceivedTime and startTime should be >=0.07s, bu
t was ' + |
466 'responseReceivedTime=' + resource.responseReceivedTime + ', start
Time=' + resource.startTime + '.'); | 466 'responseReceivedTime=' + request.responseReceivedTime + ', startT
ime=' + request.startTime + '.'); |
467 test.assertTrue( | 467 test.assertTrue( |
468 resource.endTime - resource.startTime >= 0.14, | 468 request.endTime - request.startTime >= 0.14, |
469 'Time between endTime and startTime should be >=0.14s, but was ' + | 469 'Time between endTime and startTime should be >=0.14s, but was ' + |
470 'endtime=' + resource.endTime + ', startTime=' + resource.startTim
e + '.'); | 470 'endtime=' + request.endTime + ', startTime=' + request.startTime
+ '.'); |
471 | 471 |
472 test.releaseControl(); | 472 test.releaseControl(); |
473 } | 473 } |
474 | 474 |
475 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource); | 475 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishRequest); |
476 | 476 |
477 // Reload inspected page to sniff network events | 477 // Reload inspected page to sniff network events |
478 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); | 478 test.evaluateInConsole_('window.location.reload(true);', function(resultText
) {}); |
479 | 479 |
480 this.takeControl(); | 480 this.takeControl(); |
481 }; | 481 }; |
482 | 482 |
483 TestSuite.prototype.testPushTimes = function(url) { | 483 TestSuite.prototype.testPushTimes = function(url) { |
484 var test = this; | 484 var test = this; |
485 var pendingResourceCount = 2; | 485 var pendingRequestCount = 2; |
486 | 486 |
487 function finishResource(resource, finishTime) { | 487 function finishRequest(request, finishTime) { |
488 test.assertTrue( | 488 test.assertTrue( |
489 typeof resource.timing.pushStart === 'number' && resource.timing.pushS
tart > 0, | 489 typeof request.timing.pushStart === 'number' && request.timing.pushSta
rt > 0, |
490 `pushStart is invalid: ${resource.timing.pushStart}`); | 490 `pushStart is invalid: ${request.timing.pushStart}`); |
491 test.assertTrue(typeof resource.timing.pushEnd === 'number', `pushEnd is i
nvalid: ${resource.timing.pushEnd}`); | 491 test.assertTrue(typeof request.timing.pushEnd === 'number', `pushEnd is in
valid: ${request.timing.pushEnd}`); |
492 test.assertTrue(resource.timing.pushStart < resource.startTime, 'pushStart
should be before startTime'); | 492 test.assertTrue(request.timing.pushStart < request.startTime, 'pushStart s
hould be before startTime'); |
493 if (resource.url.endsWith('?pushUseNullEndTime')) { | 493 if (request.url().endsWith('?pushUseNullEndTime')) { |
494 test.assertTrue(resource.timing.pushEnd === 0, `pushEnd should be 0 but
is ${resource.timing.pushEnd}`); | 494 test.assertTrue(request.timing.pushEnd === 0, `pushEnd should be 0 but i
s ${request.timing.pushEnd}`); |
495 } else { | 495 } else { |
496 test.assertTrue( | 496 test.assertTrue( |
497 resource.timing.pushStart < resource.timing.pushEnd, | 497 request.timing.pushStart < request.timing.pushEnd, |
498 `pushStart should be before pushEnd (${resource.timing.pushStart} >=
${resource.timing.pushEnd})`); | 498 `pushStart should be before pushEnd (${request.timing.pushStart} >=
${request.timing.pushEnd})`); |
499 // The below assertion is just due to the way we generate times in the m
och URLRequestJob and is not generally an invariant. | 499 // The below assertion is just due to the way we generate times in the m
och URLRequestJob and is not generally an invariant. |
500 test.assertTrue(resource.timing.pushEnd < resource.endTime, 'pushEnd sho
uld be before endTime'); | 500 test.assertTrue(request.timing.pushEnd < request.endTime, 'pushEnd shoul
d be before endTime'); |
501 test.assertTrue(resource.startTime < resource.timing.pushEnd, 'pushEnd s
hould be after startTime'); | 501 test.assertTrue(request.startTime < request.timing.pushEnd, 'pushEnd sho
uld be after startTime'); |
502 } | 502 } |
503 if (!--pendingResourceCount) | 503 if (!--pendingRequestCount) |
504 test.releaseControl(); | 504 test.releaseControl(); |
505 } | 505 } |
506 | 506 |
507 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishResource, true); | 507 this.addSniffer(SDK.NetworkDispatcher.prototype, '_finishNetworkRequest', fi
nishRequest, true); |
508 | 508 |
509 test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {}
); | 509 test.evaluateInConsole_('addImage(\'' + url + '\')', function(resultText) {}
); |
510 test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', func
tion(resultText) {}); | 510 test.evaluateInConsole_('addImage(\'' + url + '?pushUseNullEndTime\')', func
tion(resultText) {}); |
511 this.takeControl(); | 511 this.takeControl(); |
512 }; | 512 }; |
513 | 513 |
514 TestSuite.prototype.testConsoleOnNavigateBack = function() { | 514 TestSuite.prototype.testConsoleOnNavigateBack = function() { |
515 | 515 |
516 function filteredMessages() { | 516 function filteredMessages() { |
517 return SDK.multitargetConsoleModel.messages().filter( | 517 return SDK.multitargetConsoleModel.messages().filter( |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 if (runtimeModel.executionContexts().length >= n) | 1103 if (runtimeModel.executionContexts().length >= n) |
1104 callback.call(null); | 1104 callback.call(null); |
1105 else | 1105 else |
1106 this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated',
checkForExecutionContexts.bind(this)); | 1106 this.addSniffer(SDK.RuntimeModel.prototype, '_executionContextCreated',
checkForExecutionContexts.bind(this)); |
1107 } | 1107 } |
1108 }; | 1108 }; |
1109 | 1109 |
1110 | 1110 |
1111 window.uiTests = new TestSuite(window.domAutomationController); | 1111 window.uiTests = new TestSuite(window.domAutomationController); |
1112 })(window); | 1112 })(window); |
OLD | NEW |