| 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 29 matching lines...) Expand all Loading... |
| 40 function createTestSuite(domAutomationController) | 40 function createTestSuite(domAutomationController) |
| 41 { | 41 { |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Test suite for interactive UI tests. | 44 * Test suite for interactive UI tests. |
| 45 * @constructor | 45 * @constructor |
| 46 */ | 46 */ |
| 47 function TestSuite() | 47 function TestSuite() |
| 48 { | 48 { |
| 49 WebInspector.TestBase.call(this, domAutomationController); | 49 WebInspector.TestBase.call(this, domAutomationController); |
| 50 this._asyncInvocationId = 0; | |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 TestSuite.prototype = { | 52 TestSuite.prototype = { |
| 54 __proto__: WebInspector.TestBase.prototype | 53 __proto__: WebInspector.TestBase.prototype |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 | 56 |
| 58 /** | 57 /** |
| 59 * @param {string} panelName Name of the panel to show. | 58 * @param {string} panelName Name of the panel to show. |
| 60 */ | 59 */ |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 if (text === "PASS") | 644 if (text === "PASS") |
| 646 this.releaseControl(); | 645 this.releaseControl(); |
| 647 else if (/^FAIL/.test(text)) | 646 else if (/^FAIL/.test(text)) |
| 648 this.fail(text); | 647 this.fail(text); |
| 649 } | 648 } |
| 650 | 649 |
| 651 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo
del.Events.MessageAdded, onConsoleMessage, this); | 650 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo
del.Events.MessageAdded, onConsoleMessage, this); |
| 652 this.takeControl(); | 651 this.takeControl(); |
| 653 }; | 652 }; |
| 654 | 653 |
| 655 TestSuite.prototype.startTimeline = function(callback) | 654 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) |
| 656 { | 655 { |
| 657 this.showPanel("timeline").then(function() { | 656 var test = this; |
| 657 test.showPanel("timeline").then(function() { |
| 658 WebInspector.panels.timeline._model.addEventListener(WebInspector.Timeli
neModel.Events.RecordingStarted, onRecordingStarted); | 658 WebInspector.panels.timeline._model.addEventListener(WebInspector.Timeli
neModel.Events.RecordingStarted, onRecordingStarted); |
| 659 WebInspector.panels.timeline._toggleRecording(); | 659 WebInspector.panels.timeline._toggleRecording(); |
| 660 }); | 660 }); |
| 661 | 661 |
| 662 function onRecordingStarted() | 662 function onRecordingStarted() |
| 663 { | 663 { |
| 664 WebInspector.panels.timeline._model.removeEventListener(WebInspector.Tim
elineModel.Events.RecordingStarted, onRecordingStarted); | 664 WebInspector.panels.timeline._model.removeEventListener(WebInspector.Tim
elineModel.Events.RecordingStarted, onRecordingStarted); |
| 665 callback(); | 665 test.evaluateInConsole_(functionName + "(function() { console.log('DONE'
); });", function() {}); |
| 666 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.Conso
leModel.Events.MessageAdded, onConsoleMessage); |
| 666 } | 667 } |
| 667 } | |
| 668 | 668 |
| 669 TestSuite.prototype.stopTimeline = function(callback) | 669 function onConsoleMessage(event) |
| 670 { | 670 { |
| 671 WebInspector.panels.timeline._model.addEventListener(WebInspector.TimelineMo
del.Events.RecordingStopped, onRecordingStopped); | 671 var text = event.data.messageText; |
| 672 WebInspector.panels.timeline._toggleRecording(); | 672 if (text === "DONE") { |
| 673 WebInspector.multitargetConsoleModel.removeEventListener(WebInspecto
r.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
| 674 pageActionsDone(); |
| 675 } |
| 676 } |
| 677 |
| 678 function pageActionsDone() |
| 679 { |
| 680 WebInspector.panels.timeline._model.addEventListener(WebInspector.Timeli
neModel.Events.RecordingStopped, onRecordingStopped); |
| 681 WebInspector.panels.timeline._toggleRecording(); |
| 682 } |
| 683 |
| 673 function onRecordingStopped() | 684 function onRecordingStopped() |
| 674 { | 685 { |
| 675 WebInspector.panels.timeline._model.removeEventListener(WebInspector.Tim
elineModel.Events.RecordingStopped, onRecordingStopped); | 686 WebInspector.panels.timeline._model.removeEventListener(WebInspector.Tim
elineModel.Events.RecordingStopped, onRecordingStopped); |
| 676 callback(); | 687 callback(); |
| 677 } | 688 } |
| 678 } | |
| 679 | |
| 680 TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, c
allback_is_always_last) | |
| 681 { | |
| 682 var callback = arguments[arguments.length - 1]; | |
| 683 var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; | |
| 684 var argsString = arguments.length < 3 ? "" : Array.prototype.slice.call(argu
ments, 1, -1).map(arg => JSON.stringify(arg)).join(",") + ","; | |
| 685 this.evaluateInConsole_(`${functionName}(${argsString} function() { console.
log('${doneMessage}'); });`, function() {}); | |
| 686 WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleMo
del.Events.MessageAdded, onConsoleMessage); | |
| 687 | |
| 688 function onConsoleMessage(event) | |
| 689 { | |
| 690 var text = event.data.messageText; | |
| 691 if (text === doneMessage) { | |
| 692 WebInspector.multitargetConsoleModel.removeEventListener(WebInspecto
r.ConsoleModel.Events.MessageAdded, onConsoleMessage); | |
| 693 callback(); | |
| 694 } | |
| 695 } | |
| 696 } | |
| 697 | |
| 698 TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) | |
| 699 { | |
| 700 var test = this; | |
| 701 | |
| 702 this.startTimeline(onRecordingStarted); | |
| 703 | |
| 704 function onRecordingStarted() | |
| 705 { | |
| 706 test.invokePageFunctionAsync(functionName, pageActionsDone); | |
| 707 } | |
| 708 | |
| 709 function pageActionsDone() | |
| 710 { | |
| 711 test.stopTimeline(callback); | |
| 712 } | |
| 713 }; | 689 }; |
| 714 | 690 |
| 715 TestSuite.prototype.enableExperiment = function(name) | |
| 716 { | |
| 717 Runtime.experiments.enableForTest(name); | |
| 718 } | |
| 719 | |
| 720 TestSuite.prototype.checkInputEventsPresent = function() | |
| 721 { | |
| 722 var expectedEvents = new Set(arguments); | |
| 723 var model = WebInspector.panels.timeline._model; | |
| 724 var asyncEvents = model.mainThreadAsyncEvents(); | |
| 725 var input = asyncEvents.get(WebInspector.TimelineUIUtils.asyncEventGroups().
input) || []; | |
| 726 var prefix = "InputLatency::"; | |
| 727 for (var e of input) { | |
| 728 if (!e.name.startsWith(prefix)) | |
| 729 continue; | |
| 730 expectedEvents.delete(e.name.substr(prefix.length)); | |
| 731 } | |
| 732 if (expectedEvents.size) | |
| 733 throw "Some expected events are not found: " + Array.from(expectedEvents
.keys()).join(","); | |
| 734 } | |
| 735 | |
| 736 /** | 691 /** |
| 737 * Serializes array of uiSourceCodes to string. | 692 * Serializes array of uiSourceCodes to string. |
| 738 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes | 693 * @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes |
| 739 * @return {string} | 694 * @return {string} |
| 740 */ | 695 */ |
| 741 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) | 696 TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes) |
| 742 { | 697 { |
| 743 var names = []; | 698 var names = []; |
| 744 for (var i = 0; i < uiSourceCodes.length; i++) | 699 for (var i = 0; i < uiSourceCodes.length; i++) |
| 745 names.push('"' + WebInspector.networkMapping.networkURL(uiSourceCodes[i]
) + '"'); | 700 names.push('"' + WebInspector.networkMapping.networkURL(uiSourceCodes[i]
) + '"'); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 }; | 833 }; |
| 879 | 834 |
| 880 return new TestSuite(); | 835 return new TestSuite(); |
| 881 | 836 |
| 882 } | 837 } |
| 883 | 838 |
| 884 if (window.uiTests) { | 839 if (window.uiTests) { |
| 885 WebInspector.notifications.addEventListener(WebInspector.NotificationService
.Events.InspectorAgentEnabledForTests, | 840 WebInspector.notifications.addEventListener(WebInspector.NotificationService
.Events.InspectorAgentEnabledForTests, |
| 886 window.uiTests.testSuiteReady.bind(null, createTestSuite)); | 841 window.uiTests.testSuiteReady.bind(null, createTestSuite)); |
| 887 } | 842 } |
| OLD | NEW |