()
| 1 | function TestFlame() { |
| 2 | const PADDING = 2; // Matches PADDING in stackViewer |
| 3 | |
| 4 | const test = new TestFixture(); |
| 5 | const chart = document.getElementById("stack-chart"); |
| 6 | if (!chart) { |
| 7 | test.err("could not find stack-chart"); |
| 8 | return; |
| 9 | } |
| 10 | const chartRect = chart.getBoundingClientRect(); |
| 11 | |
| 12 | // Create map from box text to DOM element. |
| 13 | // TODO: Generalize to support multiple boxes for a given piece of text. |
| 14 | let boxMap; |
| 15 | fetchBoxes(); |
| 16 | function fetchBoxes() { |
| 17 | boxMap = new Map(); |
| 18 | const boxes = document.querySelectorAll(".boxbg"); |
| 19 | for (let box of boxes) { |
| 20 | const text = box.innerText; |
| 21 | boxMap.set(text, box); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // rect gets the bounding box for box with text t. |
| 26 | function rect(t) { |
| 27 | const elem = boxMap.get(t); |
| 28 | if (!elem) { |
| 29 | test.err("did not find", t); |
| 30 | return null; |
| 31 | } |
| 32 | return elem.getBoundingClientRect(); |
| 33 | } |
| 34 | |
| 35 | // checkCalls checks that box with text a is positioned w.r.t. box with |
| 36 | // text b to indicate a call from a to b. Expect a gap of the specified |
| 37 | // number of rows. |
| 38 | function checkCalls(a, b, gap = 0) { |
| 39 | test.setContext("checkCalls", a, b, gap); |
| 40 | const ra = rect(a); |
| 41 | const rb = rect(b); |
| 42 | if (!ra || !rb) return; |
| 43 | |
| 44 | const pixelGap = gap * rb.height; |
| 45 | if (rb.top != ra.bottom + pixelGap) { |
| 46 | test.err("not above"); |
| 47 | } |
| 48 | // TODO: Allow checking boxes above pivots. |
| 49 | if (rb.left < ra.left || rb.right > ra.right) { |
| 50 | test.err("horizontal span of", a, "is not nested inside horizontal span of", b); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // checkWidth checks that the width of the box with text t is approximately |
| 55 | // the specified fraction of the total width. |
| 56 | function checkWidth(t, fraction) { |
| 57 | test.setContext("checkWidth", t, fraction); |
| 58 | const r = rect(t); |
| 59 | if (!r) return; |
| 60 | const expect = (chartRect.width - 2*PADDING) * fraction; |
no test coverage detected
searching dependent graphs…