OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script src="../../../http/tests/inspector/inspector-test.js"></script> | |
4 <script src="../canvas-profiler-test.js"></script> | |
5 <script> | |
6 | |
7 var canvas; | |
8 var context; | |
9 var round = 0; | |
10 var colors = ["red", "green", "blue", "yellow", "black"]; | |
11 | |
12 function createCanvasContext() | |
13 { | |
14 canvas = document.getElementById("canvas"); | |
15 context = canvas.getContext("2d"); | |
16 console.assert(context, "Failed to create a canvas context"); | |
17 } | |
18 | |
19 function doSomeCanvasCalls(repeats) | |
20 { | |
21 if (!context) | |
22 createCanvasContext(); | |
23 repeats = repeats || 1; | |
24 while (repeats-- > 0) { | |
25 var offset = 5 * round; | |
26 context.save(); | |
27 context.beginPath(); | |
28 context.rect(offset, offset, 100 - offset, 100 - offset); | |
29 context.fillStyle = colors[round % colors.length]; | |
30 context.fill(); | |
31 context.restore(); | |
32 ++round; | |
33 } | |
34 } | |
35 | |
36 function test() | |
37 { | |
38 // FIXME: Remove once taken out of experiments. Also a hack below should be
removed. | |
39 Runtime.experiments.enableForTest("canvasInspection"); | |
40 | |
41 var profilesPanel = WebInspector.panels.profiles; | |
42 var typeRegistry = WebInspector.ProfileTypeRegistry.instance; | |
43 var profileType = typeRegistry.canvasProfileType; | |
44 | |
45 // FIXME: This hack is added because ProfilesPanel might have been already c
reated before experiment was enabled. | |
46 // This could be removed once canvas inspection is out of experiments. | |
47 if (!profileType) { | |
48 profileType = new WebInspector.CanvasProfileType(); | |
49 typeRegistry.canvasProfileType = profileType; | |
50 typeRegistry._addProfileType(profileType); | |
51 profilesPanel._registerProfileType(profileType); | |
52 } | |
53 | |
54 profilesPanel._onProfileTypeSelected({data: profileType}); | |
55 | |
56 InspectorTest.override(profileType, "_isSingleFrameMode", function() { retur
n false; }, true /*sticky*/); | |
57 InspectorTest.addSniffer(profileType, "_didStartCapturingFrame", didStartCap
turingFrame); | |
58 | |
59 profileType._onProfilerEnableButtonClick(true); | |
60 InspectorTest.addSniffer(profileType, "_updateDecorationElement", profilesPa
nel.toggleRecordButton.bind(profilesPanel)); | |
61 | |
62 var profileHeader; | |
63 var profileView; | |
64 var dataGrid; | |
65 | |
66 function didStartCapturingFrame(frameId, error, traceLogId) | |
67 { | |
68 profileHeader = profileType.getProfiles()[0] | |
69 profilesPanel.showProfile(profileHeader); | |
70 InspectorTest.addSniffer(profileHeader, "_updateCapturingStatus", didRec
eiveFirstFrame); | |
71 InspectorTest.evaluateInPage("doSomeCanvasCalls(2)"); | |
72 } | |
73 function didReceiveFirstFrame(traceLog) | |
74 { | |
75 if (!traceLog || traceLog.calls.length < 2) { | |
76 InspectorTest.addSniffer(profileHeader, "_updateCapturingStatus", di
dReceiveFirstFrame); | |
77 return; | |
78 } | |
79 InspectorTest.evaluateInPage("doSomeCanvasCalls(3)", didSecondFrameCalls
); | |
80 } | |
81 function didSecondFrameCalls() | |
82 { | |
83 profileView = profilesPanel.visibleView; | |
84 dataGrid = profileView._logGrid; | |
85 InspectorTest.addSniffer(InspectorTest.CanvasAgent, "replayTraceLog", on
ReplayTraceLog); | |
86 profilesPanel.toggleRecordButton(); | |
87 } | |
88 function onReplayTraceLog(traceLogId, index) | |
89 { | |
90 testControlButtons(); | |
91 | |
92 InspectorTest.addResult(""); | |
93 InspectorTest.dumpDataGrid(dataGrid); | |
94 InspectorTest.completeTest(); | |
95 } | |
96 | |
97 function testControlButtons() | |
98 { | |
99 var rootNode = dataGrid.rootNode(); | |
100 var frameNodes = []; | |
101 var drawCallGroups = []; | |
102 var nodes = []; | |
103 var allNodesFlat = []; | |
104 | |
105 frameNodes = frameNodes.concat(rootNode.children); | |
106 frameNodes.forEach(function(frameNode) { | |
107 drawCallGroups = drawCallGroups.concat(frameNode.children); | |
108 }); | |
109 drawCallGroups.forEach(function(drawCallGroup) { | |
110 nodes = nodes.concat(drawCallGroup.children); | |
111 }); | |
112 for (var node = rootNode; node; node = node.traverseNextNode(false)) { | |
113 if (node !== rootNode) | |
114 allNodesFlat.push(node); | |
115 } | |
116 allNodesFlat.forEach(function(node) { | |
117 node.toString = function() | |
118 { | |
119 return "Node{" + this.element.textContent + "}"; | |
120 } | |
121 }); | |
122 | |
123 InspectorTest.addResult(""); | |
124 InspectorTest.addResult("Total frames: " + frameNodes.length); | |
125 InspectorTest.addResult("Total draw call groups: " + drawCallGroups.leng
th); | |
126 InspectorTest.addResult("Total calls: " + nodes.length); | |
127 InspectorTest.addResult("Total grid nodes: " + allNodesFlat.length); | |
128 InspectorTest.addResult(""); | |
129 | |
130 InspectorTest.assertEquals(frameNodes.peekLast(), dataGrid.selectedNode,
"Expected last frame node before testing control buttons"); | |
131 | |
132 InspectorTest.addResult("Testing ReplayFirstStepClick"); | |
133 profileView._onReplayFirstStepClick(); | |
134 InspectorTest.assertEquals(frameNodes[0], dataGrid.selectedNode); | |
135 | |
136 InspectorTest.addResult("Testing ReplayNextStepClick"); | |
137 for (var i = 0; i < nodes.length + 5; ++i) { | |
138 profileView._onReplayStepClick(true); | |
139 InspectorTest.assertEquals(nodes[i] || nodes.peekLast(), dataGrid.se
lectedNode, "error on index " + i); | |
140 } | |
141 | |
142 InspectorTest.addResult("Testing ReplayPreviousStepClick"); | |
143 for (var i = nodes.length - 2; i >= -5; --i) { | |
144 profileView._onReplayStepClick(false); | |
145 InspectorTest.assertEquals(nodes[i] || nodes[0], dataGrid.selectedNo
de, "error on index " + i); | |
146 } | |
147 | |
148 allNodesFlat[0].revealAndSelect(); | |
149 InspectorTest.assertEquals(allNodesFlat[0], dataGrid.selectedNode, "Expe
cted to select the first node before testing ReplayNextDrawingCallClick"); | |
150 | |
151 InspectorTest.addResult("Testing ReplayNextDrawingCallClick starting on
a frame node"); | |
152 for (var i = 1; i < frameNodes.length + 5; ++i) { | |
153 profileView._onReplayDrawingCallClick(true); | |
154 InspectorTest.assertEquals(frameNodes[i] || allNodesFlat.peekLast(),
dataGrid.selectedNode, "error on index " + i); | |
155 } | |
156 | |
157 frameNodes.peekLast().revealAndSelect(); | |
158 InspectorTest.assertEquals(frameNodes.peekLast(), dataGrid.selectedNode,
"Expected to select last frame node"); | |
159 | |
160 InspectorTest.addResult("Testing ReplayPreviousDrawingCallClick starting
on a frame node"); | |
161 for (var i = frameNodes.length - 2; i >= -5; --i) { | |
162 profileView._onReplayDrawingCallClick(false); | |
163 InspectorTest.assertEquals(frameNodes[i] || frameNodes[0], dataGrid.
selectedNode, "error on index " + i); | |
164 } | |
165 | |
166 drawCallGroups[0].revealAndSelect(); | |
167 InspectorTest.assertEquals(drawCallGroups[0], dataGrid.selectedNode, "Ex
pected to move to the first draw call group"); | |
168 | |
169 InspectorTest.addResult("Testing ReplayNextDrawingCallClick starting on
a draw call group"); | |
170 var expected = [drawCallGroups[1], frameNodes[1], allNodesFlat.peekLast(
)]; | |
171 for (var i = 0; i < expected.length + 5; ++i) { | |
172 profileView._onReplayDrawingCallClick(true); | |
173 InspectorTest.assertEquals(expected[i] || expected.peekLast(), dataG
rid.selectedNode, "error on index " + i); | |
174 } | |
175 | |
176 profileView._onReplayLastStepClick(); | |
177 InspectorTest.assertEquals(allNodesFlat.peekLast(), dataGrid.selectedNod
e, "Expected to move to the last call"); | |
178 | |
179 InspectorTest.addResult("Testing ReplayPreviousDrawingCallClick starting
on a call node"); | |
180 var expected = [frameNodes[0], frameNodes[1], drawCallGroups[2], drawCal
lGroups[3], drawCallGroups[4], nodes[28]]; | |
181 for (var i = expected.length - 1; i >= -5; --i) { | |
182 profileView._onReplayDrawingCallClick(false); | |
183 InspectorTest.assertEquals(expected[i] || expected[0], dataGrid.sele
ctedNode, "error on index " + i); | |
184 } | |
185 | |
186 nodes[15].revealAndSelect(); | |
187 InspectorTest.assertEquals(nodes[15], dataGrid.selectedNode, "Expected t
o select node #20"); | |
188 | |
189 InspectorTest.addResult("Testing ReplayNextDrawingCallClick starting on
a call node"); | |
190 var expected = [nodes[16], drawCallGroups[3], drawCallGroups[4], allNode
sFlat.peekLast()]; | |
191 for (var i = 0; i < expected.length + 5; ++i) { | |
192 profileView._onReplayDrawingCallClick(true); | |
193 InspectorTest.assertEquals(expected[i] || expected.peekLast(), dataG
rid.selectedNode, "error on index " + i); | |
194 } | |
195 } | |
196 } | |
197 | |
198 </script> | |
199 </head> | |
200 <body onload="runTest()"> | |
201 <p> | |
202 Tests replay log grid. | |
203 </p> | |
204 <a href="https://bugs.webkit.org/show_bug.cgi?id=109592">Bug 109592</a> | |
205 <canvas id="canvas"></canvas> | |
206 </body> | |
207 </html> | |
OLD | NEW |