Chromium Code Reviews| 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 function finish() | 482 function finish() |
| 483 { | 483 { |
| 484 test.releaseControl(); | 484 test.releaseControl(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 WebInspector.overridesSupport._deviceMetricsChangedListenerMuted = true; | 487 WebInspector.overridesSupport._deviceMetricsChangedListenerMuted = true; |
| 488 test.takeControl(); | 488 test.takeControl(); |
| 489 this.waitForThrottler(WebInspector.overridesSupport._deviceMetricsThrottler, step1); | 489 this.waitForThrottler(WebInspector.overridesSupport._deviceMetricsThrottler, step1); |
| 490 }; | 490 }; |
| 491 | 491 |
| 492 TestSuite.prototype.testScreenshotRecording = function() | |
| 493 { | |
| 494 var test = this; | |
| 495 | |
| 496 function performActionsInPage(callback) | |
| 497 { | |
| 498 var count = 0; | |
| 499 var d = document.createElement("div"); | |
| 500 d.style.width = "100px"; | |
| 501 d.style.height = "100px"; | |
| 502 d.style.position = "absolute"; | |
| 503 d.style.left = "0px"; | |
| 504 d.style.top = "0px"; | |
| 505 document.body.appendChild(d); | |
| 506 requestAnimationFrame(frame); | |
| 507 function frame() | |
| 508 { | |
| 509 var color = [0, 0, 0]; | |
| 510 color[count % 3] = 255; | |
| 511 d.style.backgroundColor = "rgb(" + color.join(",") + ")"; | |
| 512 if (++count > 5) | |
| 513 requestAnimationFrame(callback); | |
| 514 else | |
| 515 requestAnimationFrame(frame); | |
| 516 } | |
| 517 } | |
| 518 | |
| 519 Runtime.experiments.enableForTest("filmStripInNetworkAndTimeline"); | |
| 520 var captureFilmStripSetting = WebInspector.settings.createSetting("timelineC aptureFilmStrip", false); | |
| 521 captureFilmStripSetting.set(true); | |
| 522 test.evaluateInConsole_(performActionsInPage.toString(), function() {}); | |
| 523 test.invokeAsyncWithTimeline_("performActionsInPage", onTimelineDone); | |
| 524 | |
| 525 function onTimelineDone() | |
| 526 { | |
| 527 captureFilmStripSetting.set(false); | |
| 528 var filmStripModel = new WebInspector.FilmStripModel(WebInspector.panels .timeline._tracingModel); | |
| 529 var frames = filmStripModel.frames(); | |
| 530 console.error("Frame count: " + frames.length); | |
| 531 test.assertTrue(frames.length > 2 && typeof frames.length === "number"); | |
|
alph
2015/06/17 13:47:51
We tend to not use assert in tests, but rather log
| |
| 532 loadFrameImages(frames); | |
| 533 } | |
| 534 | |
| 535 function loadFrameImages(frames) | |
| 536 { | |
| 537 var readyImages = []; | |
| 538 for (var frame of frames) { | |
| 539 var image = new Image(); | |
| 540 image.addEventListener("load", onLoad); | |
| 541 image.src = "data:image/jpg;base64," + frame.imageData; | |
|
alph
2015/06/17 13:47:51
Ain't you just nuked imageData?
| |
| 542 } | |
| 543 | |
| 544 function onLoad(event) | |
| 545 { | |
| 546 readyImages.push(event.target); | |
| 547 if (readyImages.length === frames.length) | |
| 548 validateImagesAndCompleteTest(readyImages); | |
| 549 } | |
| 550 } | |
| 551 | |
| 552 function validateImagesAndCompleteTest(images) | |
| 553 { | |
| 554 var canvas = document.createElement("canvas"); | |
| 555 var ctx = canvas.getContext("2d"); | |
| 556 for (var image of images) { | |
| 557 test.assertTrue(image.naturalWidth > 10); | |
|
alph
2015/06/17 13:47:51
ditto for assertTrue
| |
| 558 test.assertTrue(image.naturalHeight > 10); | |
| 559 canvas.width = image.naturalWidth; | |
| 560 canvas.height = image.naturalHeight; | |
| 561 ctx.drawImage(image, 0, 0); | |
| 562 var data = ctx.getImageData(0, 0, 1, 1); | |
| 563 console.error("Color " + Array.prototype.join.call(data.data, ",")); | |
| 564 } | |
| 565 test.releaseControl(); | |
| 566 } | |
| 567 | |
| 568 test.takeControl(); | |
| 569 } | |
| 570 | |
| 492 TestSuite.prototype.testSettings = function() | 571 TestSuite.prototype.testSettings = function() |
| 493 { | 572 { |
| 494 var test = this; | 573 var test = this; |
| 495 | 574 |
| 496 createSettings(); | 575 createSettings(); |
| 497 test.takeControl(); | 576 test.takeControl(); |
| 498 setTimeout(reset, 0); | 577 setTimeout(reset, 0); |
| 499 | 578 |
| 500 function createSettings() | 579 function createSettings() |
| 501 { | 580 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 if (text === "PASS") | 623 if (text === "PASS") |
| 545 this.releaseControl(); | 624 this.releaseControl(); |
| 546 else if (/^FAIL/.test(text)) | 625 else if (/^FAIL/.test(text)) |
| 547 this.fail(text); | 626 this.fail(text); |
| 548 } | 627 } |
| 549 | 628 |
| 550 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, onConsoleMessage, this); | 629 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo del.Events.MessageAdded, onConsoleMessage, this); |
| 551 this.takeControl(); | 630 this.takeControl(); |
| 552 }; | 631 }; |
| 553 | 632 |
| 633 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) | |
| 634 { | |
| 635 var test = this; | |
| 636 test.showPanel("timeline").then(function() { | |
| 637 WebInspector.panels.timeline._model.addEventListener(WebInspector.Timeli neModel.Events.RecordingStarted, onRecordingStarted); | |
| 638 WebInspector.panels.timeline.toggleTimelineButton.element.click(); | |
| 639 }); | |
| 640 | |
| 641 function onRecordingStarted() | |
| 642 { | |
| 643 WebInspector.panels.timeline._model.removeEventListener(WebInspector.Tim elineModel.Events.RecordingStarted, onRecordingStarted); | |
| 644 test.evaluateInConsole_(functionName + "(function() { console.log('DONE' ); });", function() {}); | |
| 645 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso leModel.Events.MessageAdded, onConsoleMessage, this); | |
|
alph
2015/06/17 13:47:51
Not sure, but does it make sense to addEventListen
| |
| 646 } | |
| 647 | |
| 648 function onConsoleMessage(event) | |
| 649 { | |
| 650 var text = event.data.messageText; | |
| 651 if (text === "DONE") { | |
| 652 WebInspector.multitargetConsoleModel.removeEventListener(WebInspecto r.ConsoleModel.Events.MessageAdded, onConsoleMessage, this); | |
| 653 pageActionsDone(); | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 function pageActionsDone() | |
| 658 { | |
| 659 WebInspector.panels.timeline._model.addEventListener(WebInspector.Timeli neModel.Events.RecordingStopped, onRecordingStopped); | |
| 660 WebInspector.panels.timeline.toggleTimelineButton.element.click(); | |
| 661 } | |
| 662 | |
| 663 function onRecordingStopped() | |
| 664 { | |
| 665 WebInspector.panels.timeline._model.removeEventListener(WebInspector.Tim elineModel.Events.RecordingStopped, onRecordingStopped); | |
| 666 callback(); | |
| 667 } | |
| 668 }; | |
| 669 | |
| 554 /** | 670 /** |
| 555 * Serializes array of uiSourceCodes to string. | 671 * Serializes array of uiSourceCodes to string. |
| 556 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes | 672 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes |
| 557 * @return {string} | 673 * @return {string} |
| 558 */ | 674 */ |
| 559 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) | 675 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) |
| 560 { | 676 { |
| 561 var names = []; | 677 var names = []; |
| 562 for (var i = 0; i < uiSourceCodes.length; i++) | 678 for (var i = 0; i < uiSourceCodes.length; i++) |
| 563 names.push('"' + WebInspector.networkMapping.networkURL(uiSourceCodes[i] ) + '"'); | 679 names.push('"' + WebInspector.networkMapping.networkURL(uiSourceCodes[i] ) + '"'); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 } | 823 } |
| 708 | 824 |
| 709 WebInspector.notifications.addEventListener(WebInspector.NotificationService.Eve nts.InspectorAgentEnabledForTests, runTests); | 825 WebInspector.notifications.addEventListener(WebInspector.NotificationService.Eve nts.InspectorAgentEnabledForTests, runTests); |
| 710 | 826 |
| 711 return new TestSuite(); | 827 return new TestSuite(); |
| 712 | 828 |
| 713 } | 829 } |
| 714 | 830 |
| 715 if (window.uiTests) | 831 if (window.uiTests) |
| 716 window.uiTests.testSuiteReady(createTestSuite, WebInspector.TestBase); | 832 window.uiTests.testSuiteReady(createTestSuite, WebInspector.TestBase); |
| OLD | NEW |