summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/xpcshell/test_tree-map-01.js
blob: 1e91a43ec979194351bc061b875196e2b1cf0461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const {
  drawBox,
} = require("resource://devtools/client/memory/components/tree-map/draw.js");

add_task(async function () {
  let fillRectValues, strokeRectValues;
  const ctx = {
    fillRect: (...args) => {
      fillRectValues = args;
    },
    strokeRect: (...args) => {
      strokeRectValues = args;
    },
  };
  const node = {
    x: 20,
    y: 30,
    dx: 50,
    dy: 70,
    type: "other",
    depth: 2,
  };
  const padding = [10, 10];
  const borderWidth = () => 1;
  const dragZoom = {
    offsetX: 0,
    offsetY: 0,
    zoom: 0,
  };
  drawBox(ctx, node, borderWidth, dragZoom, padding);
  ok(true, JSON.stringify([ctx, fillRectValues, strokeRectValues]));
  equal(ctx.fillStyle, "hsl(204,60%,70%)", "The fillStyle is set");
  equal(ctx.strokeStyle, "hsl(204,60%,35%)", "The strokeStyle is set");
  equal(ctx.lineWidth, 1, "The lineWidth is set");
  deepEqual(fillRectValues, [10.5, 20.5, 49, 69], "Draws a filled rectangle");
  deepEqual(
    strokeRectValues,
    [10.5, 20.5, 49, 69],
    "Draws a stroked rectangle"
  );

  dragZoom.zoom = 0.5;

  drawBox(ctx, node, borderWidth, dragZoom, padding);
  ok(true, JSON.stringify([ctx, fillRectValues, strokeRectValues]));
  deepEqual(
    fillRectValues,
    [15.5, 30.5, 74, 104],
    "Draws a zoomed filled rectangle"
  );
  deepEqual(
    strokeRectValues,
    [15.5, 30.5, 74, 104],
    "Draws a zoomed stroked rectangle"
  );

  dragZoom.offsetX = 110;
  dragZoom.offsetY = 130;

  drawBox(ctx, node, borderWidth, dragZoom, padding);
  deepEqual(
    fillRectValues,
    [-94.5, -99.5, 74, 104],
    "Draws a zoomed and offset filled rectangle"
  );
  deepEqual(
    strokeRectValues,
    [-94.5, -99.5, 74, 104],
    "Draws a zoomed and offset stroked rectangle"
  );
});