Web Inspector: Timelines: can't reliably stop/start a recording
[WebKit-https.git] / LayoutTests / inspector / timeline / timeline-recording.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     let suite = InspectorTest.createAsyncSuite("TimelineRecording");
9
10     let exportData = null;
11
12     suite.addTestCase({
13         name: "TimelineRecording.Basic",
14         description: "Make a basic Timeline recording.",
15         async test() {
16             async function awaitCapturingState(capturingState) {
17                 return new Promise((resolve, reject) => {
18                     let listener = WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, (event) => {
19                         if (WI.timelineManager.capturingState !== capturingState)
20                             return;
21
22                         WI.timelineManager.removeEventListener(WI.TimelineManager.Event.CapturingStateChanged, listener);
23                         resolve();
24                     });
25                 });
26             }
27
28             let recording = WI.timelineManager.activeRecording;
29
30             InspectorTest.log("Loaded");
31             InspectorTest.expectFalse(WI.timelineManager.isCapturing(), "TimelineManager should not be capturing.");
32             InspectorTest.expectFalse(recording.capturing, "TimelineRecording should not be capturing.");
33             InspectorTest.expectFalse(recording.readonly, "TimelineRecording should not be readonly.");
34             InspectorTest.expectFalse(recording.imported, "TimelineRecording should not be imported.");
35             InspectorTest.expectThat(isNaN(recording.startTime), "TimelineRecording should not have a startTime.");
36             InspectorTest.expectThat(isNaN(recording.endTime), "TimelineRecording should not have a endTime.");
37
38             InspectorTest.log("Start");
39             WI.timelineManager.startCapturing();
40
41             await awaitCapturingState(WI.TimelineManager.CapturingState.Active);
42
43             InspectorTest.expectTrue(WI.timelineManager.isCapturing(), "TimelineManager should be capturing.");
44             InspectorTest.expectEqual(WI.timelineManager.activeRecording, recording, "TimelineManager active recording should not have changed.");
45             InspectorTest.expectTrue(recording.capturing, "TimelineRecording should be capturing.");
46             InspectorTest.expectFalse(recording.readonly, "TimelineRecording should not be readonly.");
47
48             InspectorTest.log("Reload");
49             await Promise.all([
50                 InspectorTest.awaitEvent(FrontendTestHarness.Event.TestPageDidLoad),
51                 InspectorTest.reloadPage(),
52             ]);
53
54             InspectorTest.log("Stop");
55             WI.timelineManager.stopCapturing();
56
57             await awaitCapturingState(WI.TimelineManager.CapturingState.Inactive);
58
59             InspectorTest.expectFalse(WI.timelineManager.isCapturing(), "TimelineManager should not be capturing.");
60             InspectorTest.expectFalse(recording.capturing, "TimelineRecording should not be capturing.");
61             InspectorTest.expectFalse(recording.readonly, "TimelineRecording should not be readonly.");
62             InspectorTest.expectFalse(recording.imported, "TimelineRecording should not be imported.");
63             InspectorTest.expectThat(!isNaN(recording.startTime), "TimelineRecording should have a startTime.");
64             InspectorTest.expectThat(!isNaN(recording.endTime), "TimelineRecording should have a endTime.");
65         }
66     });
67
68     suite.addTestCase({
69         name: "TimelineRecording.prototype.exportData",
70         description: "Test for a recording export.",
71         async test() {
72             let recording = WI.timelineManager.activeRecording;
73             InspectorTest.assert(!isNaN(recording.startTime), "FAIL: Previous test loading a recording failed.");
74             InspectorTest.assert(!isNaN(recording.endTime), "FAIL: Previous test loading a recording failed.");
75
76             InspectorTest.expectTrue(recording.canExport(), "TimelineRecording should be able to export.");
77
78             exportData = recording.exportData();
79             InspectorTest.expectThat(exportData, "TimelineRecording should be able to produce export data.");
80             InspectorTest.expectThat(exportData.records.length > 10, "TimelineRecording should have at least 10 Timeline Records.");
81
82             InspectorTest.log("Export Data:");
83             let filterKeys = new Set(["startTime", "endTime", "time", "records", "displayName"]);
84             InspectorTest.json(exportData, (key, value) => {
85                 if (filterKeys.has(key))
86                     return "<filtered>";
87                 if (key === "markers")
88                     return ["<filtered>"];
89                 return value;
90             });
91         }
92     });
93
94     suite.addTestCase({
95         name: "TimelineRecording.import",
96         description: "Test for a recording import.",
97         async test() {
98             InspectorTest.assert(exportData, "FAIL: Previous test exporting a recording failed.");
99
100             // NOTE: This runs the toJSON handlers on the timeline records and other model objects,
101             // which is important because importing expects the serialized form of the objects, not
102             // actual model objects.
103             let jsonData = JSON.parse(JSON.stringify(exportData));
104
105             const identifier = 999;
106             let recording = WI.TimelineRecording.import(identifier, jsonData, "TEST");
107             InspectorTest.expectNotEqual(WI.timelineManager.activeRecording, recording, "TimelineManager active recording is not this imported recording.");
108             InspectorTest.expectFalse(recording.capturing, "TimelineRecording should not be capturing.");
109             InspectorTest.expectTrue(recording.readonly, "TimelineRecording should be readonly.");
110             InspectorTest.expectTrue(recording.imported, "TimelineRecording should be imported.");
111             InspectorTest.expectThat(!isNaN(recording.startTime), "TimelineRecording should have a startTime.");
112             InspectorTest.expectThat(!isNaN(recording.endTime), "TimelineRecording should have a endTime.");
113             InspectorTest.expectEqual(recording.identifier, identifier, `TimelineRecording identifier should be ${identifier}.`);
114
115             InspectorTest.log("Display Name:");
116             InspectorTest.log(recording.displayName);
117         }
118     });
119
120     suite.runTestCasesAndFinish();
121 }
122 </script>
123 </head>
124 <body onload="runTest()">
125 <p>Tests for timeline recording.</p>
126 </body>
127 </html>