Web Inspector: Timelines: can't reliably stop/start a recording
[WebKit-https.git] / LayoutTests / inspector / timeline / resources / timeline-event-utilities.js
index b0e4127..b7cffef 100644 (file)
@@ -10,34 +10,40 @@ TestPage.registerInitializer(() => {
 
         let promise = new WI.WrappedPromise;
 
-        WI.timelineManager.awaitEvent(WI.TimelineManager.Event.CapturingStopped).then((capturingStoppedEvent) => {
-            InspectorTest.assert(pageRecordingData, "savePageData should have been called in the page before capturing was stopped.");
-            promise.resolve(pageRecordingData);
+        let listener = WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, (event) => {
+            if (WI.timelineManager.capturingState === WI.TimelineManager.CapturingState.Active) {
+                let recording = WI.timelineManager.activeRecording;
+                let scriptTimeline = recording.timelines.get(WI.TimelineRecord.Type.Script);
+
+                let recordAddedListener = scriptTimeline.addEventListener(WI.Timeline.Event.RecordAdded, (recordAddedEvent) => {
+                    let {record} = recordAddedEvent.data;
+                    if (record.eventType !== eventType)
+                        return;
+
+                    scriptTimeline.removeEventListener(WI.Timeline.Event.RecordAdded, recordAddedListener);
+
+                    InspectorTest.log("Stopping Capture...");
+                    WI.timelineManager.stopCapturing();
+                });
+
+                InspectorTest.log("Evaluating...");
+                InspectorTest.evaluateInPage(expression)
+                .catch(promise.reject);
+                return;
+            }
+
+            if (WI.timelineManager.capturingState === WI.TimelineManager.CapturingState.Inactive) {
+                WI.timelineManager.removeEventListener(WI.TimelineManager.Event.CapturingStateChanged, listener);
+                InspectorTest.assert(pageRecordingData, "savePageData should have been called in the page before capturing was stopped.");
+                promise.resolve(pageRecordingData);
+                return;
+            }
         });
 
         InspectorTest.awaitEvent("SavePageData").then((event) => {
             pageRecordingData = event.data;
         });
 
-        WI.timelineManager.awaitEvent(WI.TimelineManager.Event.CapturingStarted).then((capturingStartedEvent) => {
-            let recording = WI.timelineManager.activeRecording;
-            let scriptTimeline = recording.timelines.get(WI.TimelineRecord.Type.Script);
-
-            let recordAddedListener = scriptTimeline.addEventListener(WI.Timeline.Event.RecordAdded, (recordAddedEvent) => {
-                let {record} = recordAddedEvent.data;
-                if (record.eventType !== eventType)
-                    return;
-
-                scriptTimeline.removeEventListener(WI.Timeline.Event.RecordAdded, recordAddedListener);
-
-                InspectorTest.log("Stopping Capture...");
-                WI.timelineManager.stopCapturing();
-            });
-
-            InspectorTest.log("Evaluating...");
-            return InspectorTest.evaluateInPage(expression);
-        });
-
         InspectorTest.log("Starting Capture...");
         const newRecording = true;
         WI.timelineManager.startCapturing(newRecording);