Web Inspector: Timelines: can't reliably stop/start a recording
[WebKit-https.git] / LayoutTests / inspector / timeline / recording-start-stop-timestamps.html
1 <!doctype html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script>
6 function test()
7 {
8     var recordingStartTime = NaN;
9     var recordingEndTime = NaN;
10
11     function check(condition, message)
12     {
13         InspectorTest.log((condition ? "PASS" : "FAIL") + ": " + message);
14     }
15
16     WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, (event) => {
17         if (WI.timelineManager.capturingState === WI.TimelineManager.CapturingState.Active) {
18             InspectorTest.assert(typeof event.data.startTime === "number");
19             InspectorTest.assert(event.data.startTime > 0);
20
21             if (isNaN(recordingStartTime)) {
22                 InspectorTest.log("PASS: 1st CapturingStarted had startTime");
23             } else {
24                 InspectorTest.assert(event.data.startTime > recordingStartTime, "FAIL: 2nd CapturingStarted should be > 1st CapturingStarted");
25                 InspectorTest.log("PASS: 2nd CapturingStarted had startTime > 1st CapturingStarted");
26                 InspectorTest.assert(event.data.startTime > recordingEndTime, "FAIL: 2nd CapturingStarted should be > 1st CapturingStopped");
27                 InspectorTest.log("PASS: 2nd CapturingStarted had startTime > 1st CapturingStopped");
28             }
29
30             recordingStartTime = event.data.startTime;
31             return;
32         }
33
34         if (WI.timelineManager.capturingState === WI.TimelineManager.CapturingState.Inactive) {
35             InspectorTest.assert(typeof event.data.endTime === "number");
36             InspectorTest.assert(event.data.endTime > 0);
37
38             if (isNaN(recordingEndTime)) {
39                 InspectorTest.log("PASS: 1st CapturingStopped had endTime");
40                 InspectorTest.assert(event.data.endTime > recordingStartTime, "FAIL: 1st CapturingStopped should be > 1st CapturingStarted");
41                 InspectorTest.log("PASS: 1st CapturingStopped had endTime > 1st CapturingStarted");
42             } else {
43                 InspectorTest.assert(event.data.endTime > recordingEndTime, "FAIL: 2nd CapturingStopped should be > 1st CapturingStopped");
44                 InspectorTest.log("PASS: 2nd CapturingStopped had endTime > 1st CapturingStopped");
45                 InspectorTest.assert(event.data.endTime > recordingStartTime, "FAIL: 2nd CapturingStopped should be > 2nd CapturingStarted");
46                 InspectorTest.log("PASS: 2nd CapturingStopped had endTime > 2nd CapturingStarted");
47                 InspectorTest.completeTest();
48             }
49
50             recordingEndTime = event.data.endTime;
51             return;
52         }
53     });
54
55     TimelineAgent.start()
56         .then(function() { return TimelineAgent.stop(); })
57         .then(function() { return TimelineAgent.start(); })
58         .then(function() { return TimelineAgent.stop(); });
59 }
60 </script>
61 </head>
62 <body onload="runTest()">
63     <p>Testing that timeline start and stop events have timestamps and are ordered reasonably.</p>
64 </body>
65 </html>