Index: third_party/WebKit/Source/devtools/front_end/main/Tests.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/main/Tests.js b/third_party/WebKit/Source/devtools/front_end/main/Tests.js |
index e63ad970792b6cf8a8a99612efb519969a7b3133..4e3588faf341348ae949105e738d39ccf318b96e 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/main/Tests.js |
+++ b/third_party/WebKit/Source/devtools/front_end/main/Tests.js |
@@ -47,6 +47,7 @@ function createTestSuite(domAutomationController) |
function TestSuite() |
{ |
WebInspector.TestBase.call(this, domAutomationController); |
+ this._asyncInvocationId = 0; |
}; |
TestSuite.prototype = { |
@@ -651,10 +652,9 @@ TestSuite.prototype.waitForTestResultsInConsole = function() |
this.takeControl(); |
}; |
-TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) |
+TestSuite.prototype.startTimeline = function(callback) |
{ |
- var test = this; |
- test.showPanel("timeline").then(function() { |
+ this.showPanel("timeline").then(function() { |
WebInspector.panels.timeline._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStarted, onRecordingStarted); |
WebInspector.panels.timeline._toggleRecording(); |
}); |
@@ -662,32 +662,77 @@ TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) |
function onRecordingStarted() |
{ |
WebInspector.panels.timeline._model.removeEventListener(WebInspector.TimelineModel.Events.RecordingStarted, onRecordingStarted); |
- test.evaluateInConsole_(functionName + "(function() { console.log('DONE'); });", function() {}); |
- WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
+ callback(); |
+ } |
+} |
+ |
+TestSuite.prototype.stopTimeline = function(callback) |
+{ |
+ WebInspector.panels.timeline._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStopped, onRecordingStopped); |
+ WebInspector.panels.timeline._toggleRecording(); |
+ function onRecordingStopped() |
+ { |
+ WebInspector.panels.timeline._model.removeEventListener(WebInspector.TimelineModel.Events.RecordingStopped, onRecordingStopped); |
+ callback(); |
} |
+} |
+ |
+TestSuite.prototype.invokePageFunctionAsync = function(functionName, opt_args, callback_is_always_last) |
+{ |
+ var callback = arguments[arguments.length - 1]; |
+ var doneMessage = `DONE: ${functionName}.${++this._asyncInvocationId}`; |
+ var argsString = arguments.length < 3 ? "" : Array.prototype.slice.call(arguments, 1, -1).map(arg => JSON.stringify(arg)).join(",") + ","; |
+ this.evaluateInConsole_(`${functionName}(${argsString} function() { console.log('${doneMessage}'); });`, function() {}); |
+ WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
function onConsoleMessage(event) |
{ |
var text = event.data.messageText; |
- if (text === "DONE") { |
+ if (text === doneMessage) { |
WebInspector.multitargetConsoleModel.removeEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage); |
- pageActionsDone(); |
+ callback(); |
} |
} |
+} |
- function pageActionsDone() |
+TestSuite.prototype.invokeAsyncWithTimeline_ = function(functionName, callback) |
+{ |
+ var test = this; |
+ |
+ this.startTimeline(onRecordingStarted); |
+ |
+ function onRecordingStarted() |
{ |
- WebInspector.panels.timeline._model.addEventListener(WebInspector.TimelineModel.Events.RecordingStopped, onRecordingStopped); |
- WebInspector.panels.timeline._toggleRecording(); |
+ test.invokePageFunctionAsync(functionName, pageActionsDone); |
} |
- function onRecordingStopped() |
+ function pageActionsDone() |
{ |
- WebInspector.panels.timeline._model.removeEventListener(WebInspector.TimelineModel.Events.RecordingStopped, onRecordingStopped); |
- callback(); |
+ test.stopTimeline(callback); |
} |
}; |
+TestSuite.prototype.enableExperiment = function(name) |
+{ |
+ Runtime.experiments.enableForTest(name); |
+} |
+ |
+TestSuite.prototype.checkInputEventsPresent = function() |
+{ |
+ var expectedEvents = new Set(arguments); |
+ var model = WebInspector.panels.timeline._model; |
+ var asyncEvents = model.mainThreadAsyncEvents(); |
+ var input = asyncEvents.get(WebInspector.TimelineUIUtils.asyncEventGroups().input) || []; |
+ var prefix = "InputLatency::"; |
+ for (var e of input) { |
+ if (!e.name.startsWith(prefix)) |
+ continue; |
+ expectedEvents.delete(e.name.substr(prefix.length)); |
+ } |
+ if (expectedEvents.size) |
+ throw "Some expected events are not found: " + Array.from(expectedEvents.keys()).join(","); |
+} |
+ |
/** |
* Serializes array of uiSourceCodes to string. |
* @param {!Array.<!WebInspectorUISourceCode>} uiSourceCodes |