cf0e3f5d2cb71a589fb90fada4e075a5af28eb28
[WebKit-https.git] / LayoutTests / inspector-protocol / debugger / didSampleProbe-multiple-probes.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
4 <script src="resources/breakpoint.js"></script>
5 <script>
6 function test()
7 {
8     InspectorTest.importScript("../../../../inspector-protocol/resources/probe-helper.js");
9
10     InspectorTest.sendCommand("Debugger.enable", {});
11     InspectorTest.sendCommand("Debugger.setBreakpointsActive", {active: true}, function() {
12         InspectorTest.log("Breakpoints Enabled");
13     });
14
15     var samples = [];
16     const expectedSampleCount = 2;
17
18     function receivedAllExpectedSamples() {
19         return samples.length === expectedSampleCount;
20     }
21
22     function dumpSamples()
23     {
24         InspectorTest.log("Sample 1: " + JSON.stringify(samples[0]));
25         InspectorTest.log("Sample 2: " + JSON.stringify(samples[1]));
26     }
27
28     var tests = [
29         {
30             message: "Samples from probe actions on the same breakpoint should have unique action identifiers.",
31             predicate: function samplesHaveUniqueActionIds() {
32                 return samples[0].probeId !== samples[1].probeId;
33             },
34             error: dumpSamples
35         },
36         {
37             message: "Samples from probe actions on the same breakpoint should have the same batch identifiers.",
38             predicate: function samplesHaveEqualBatchIds() {
39                 return samples[0].batchId === samples[1].batchId;
40             },
41             error: dumpSamples
42         },
43     ];
44
45     InspectorTest.eventHandler["Debugger.scriptParsed"] = function(messageObject)
46     {
47         if (/resources\/breakpoint\.js$/.test(messageObject.params.url)) {
48             InspectorTest.log("Found breakpoint.js");
49             var scriptIdentifier = messageObject.params.scriptId;
50             var location = {scriptId: scriptIdentifier, lineNumber: 18, columnNumber: 0};
51             var options = {
52                 autoContinue: true,
53                 actions: [
54                     {"type": "probe", "data": "a"},
55                     {"type": "probe", "data": "a"}
56                 ]
57             };
58
59             InspectorTest.sendCommand("Debugger.setBreakpoint", {location: location, options: options}, function(responseObject) {
60                 InspectorTest.checkForError(responseObject);
61                 var actionIdentifiers = responseObject.result.breakpointActionIdentifiers;
62                 InspectorTest.assert(actionIdentifiers instanceof Array && actionIdentifiers.length === 2,
63                                      "Should receive two breakpoint action identifiers on Debugger.setBreakpoint callback.");
64
65                 // FIXME: should we use the Breakpoint/BreakpointAction model objects to manage this?
66                 if (actionIdentifiers.length === 2) {
67                     options.actions[0].identifier = actionIdentifiers[0];
68                     options.actions[1].identifier = actionIdentifiers[1];
69                 }
70                 InspectorTest.log("Running breakpointActions to trigger probe samples.");
71                 InspectorTest.sendCommand("Runtime.evaluate", {expression: "breakpointActions(12, {x:1,y:2})"});
72             });
73         }
74     }
75
76     InspectorTest.eventHandler["Debugger.didSampleProbe"] = function(messageObject)
77     {
78         var sample = ProbeHelper.simplifiedProbeSample(messageObject);
79         samples.push(sample);
80         InspectorTest.log("Received probe sample payload: " + JSON.stringify(sample.payload));
81
82         if (receivedAllExpectedSamples()) {
83             tests.forEach(function(test) {
84                 var result = test.predicate();
85                 InspectorTest.assert(result, test.message);
86                 if (!result)
87                     test.error();
88             });
89             InspectorTest.completeTest();
90         }
91     }
92 }
93 </script>
94 </head>
95 <body onload="runTest()">
96 <p>Debugger.setBreakpoint with multiple probe actions at the same breakpoint. Test Debugger.didSampleProbe events for the probe samples.</p>
97 </body>
98 </html>