tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_memory_tree_map-01.js (3639B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Make sure the canvases are created correctly
      6 
      7 "use strict";
      8 
      9 const CanvasUtils = require("resource://devtools/client/memory/components/tree-map/canvas-utils.js");
     10 const D3_SCRIPT =
     11  '<script type="application/javascript" ' +
     12  'src="chrome://global/content/third_party/d3/d3.js">';
     13 const TEST_URL = `data:text/html,<html><body>${D3_SCRIPT}</body></html>`;
     14 
     15 this.test = makeMemoryTest(TEST_URL, async function ({ panel }) {
     16  const document = panel.panelWin.document;
     17  const window = panel.panelWin;
     18  const div = document.createElement("div");
     19 
     20  Object.assign(div.style, {
     21    width: "100px",
     22    height: "200px",
     23    position: "absolute",
     24  });
     25 
     26  document.body.appendChild(div);
     27 
     28  info("Create the canvases");
     29 
     30  const canvases = new CanvasUtils(div, 0);
     31 
     32  info("Test the shape of the returned object");
     33 
     34  is(typeof canvases, "object", "Canvases create an object");
     35  is(typeof canvases.emit, "function", "Decorated with an EventEmitter");
     36  is(typeof canvases.on, "function", "Decorated with an EventEmitter");
     37  is(div.children[0], canvases.container, "Div has the container");
     38  ok(
     39    canvases.main.canvas instanceof window.HTMLCanvasElement,
     40    "Creates the main canvas"
     41  );
     42  ok(
     43    canvases.zoom.canvas instanceof window.HTMLCanvasElement,
     44    "Creates the zoom canvas"
     45  );
     46  ok(
     47    canvases.main.ctx instanceof window.CanvasRenderingContext2D,
     48    "Creates the main canvas context"
     49  );
     50  ok(
     51    canvases.zoom.ctx instanceof window.CanvasRenderingContext2D,
     52    "Creates the zoom canvas context"
     53  );
     54 
     55  info("Test resizing");
     56 
     57  let timesResizeCalled = 0;
     58  canvases.on("resize", function () {
     59    timesResizeCalled++;
     60  });
     61 
     62  const main = canvases.main.canvas;
     63  const zoom = canvases.zoom.canvas;
     64  const ratio = window.devicePixelRatio;
     65 
     66  is(
     67    main.width,
     68    100 * ratio,
     69    "Main canvas width is the same as the parent div"
     70  );
     71  is(
     72    main.height,
     73    200 * ratio,
     74    "Main canvas height is the same as the parent div"
     75  );
     76  is(
     77    zoom.width,
     78    100 * ratio,
     79    "Zoom canvas width is the same as the parent div"
     80  );
     81  is(
     82    zoom.height,
     83    200 * ratio,
     84    "Zoom canvas height is the same as the parent div"
     85  );
     86  is(timesResizeCalled, 0, "Resize was not emitted");
     87 
     88  div.style.width = "500px";
     89  div.style.height = "700px";
     90 
     91  window.dispatchEvent(new Event("resize"));
     92 
     93  is(
     94    main.width,
     95    500 * ratio,
     96    "Main canvas width is resized to be the same as the parent div"
     97  );
     98  is(
     99    main.height,
    100    700 * ratio,
    101    "Main canvas height is resized to be the same as the parent div"
    102  );
    103  is(
    104    zoom.width,
    105    500 * ratio,
    106    "Zoom canvas width is resized to be the same as the parent div"
    107  );
    108  is(
    109    zoom.height,
    110    700 * ratio,
    111    "Zoom canvas height is resized to be the same as the parent div"
    112  );
    113  is(timesResizeCalled, 1, "'resize' was emitted was emitted");
    114 
    115  div.style.width = "1100px";
    116  div.style.height = "1300px";
    117 
    118  canvases.destroy();
    119  window.dispatchEvent(new Event("resize"));
    120 
    121  is(main.width, 500 * ratio, "Main canvas width is not resized after destroy");
    122  is(
    123    main.height,
    124    700 * ratio,
    125    "Main canvas height is not resized after destroy"
    126  );
    127  is(zoom.width, 500 * ratio, "Zoom canvas width is not resized after destroy");
    128  is(
    129    zoom.height,
    130    700 * ratio,
    131    "Zoom canvas height is not resized after destroy"
    132  );
    133  is(timesResizeCalled, 1, "onResize was not called again");
    134 
    135  document.body.removeChild(div);
    136 });