tor-browser

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

browser_net_timeline_ticks.js (6170B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests if timeline correctly displays interval divisions.
      8 */
      9 
     10 add_task(async function () {
     11  const {
     12    L10N,
     13  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     14 
     15  const { monitor } = await initNetMonitor(HTTPS_SIMPLE_URL, {
     16    requestCount: 1,
     17  });
     18  info("Starting test... ");
     19 
     20  const { $, $all, NetMonitorView, NetMonitorController } = monitor.panelWin;
     21  const { RequestsMenu } = NetMonitorView;
     22 
     23  // Disable transferred size column support for this test.
     24  // Without this, the waterfall only has enough room for one division, which
     25  // would remove most of the value of this test.
     26  // $("#requests-list-transferred-header-box").hidden = true;
     27  // $("#requests-list-item-template .requests-list-transferred").hidden = true;
     28 
     29  RequestsMenu.lazyUpdate = false;
     30 
     31  ok(
     32    $("#requests-list-waterfall-label"),
     33    "An timeline label should be displayed when the frontend is opened."
     34  );
     35  ok(
     36    !$all(".requests-list-timings-division").length,
     37    "No tick labels should be displayed when the frontend is opened."
     38  );
     39 
     40  ok(
     41    !RequestsMenu._canvas,
     42    "No canvas should be created when the frontend is opened."
     43  );
     44  ok(
     45    !RequestsMenu._ctx,
     46    "No 2d context should be created when the frontend is opened."
     47  );
     48 
     49  const wait = waitForNetworkEvents(monitor, 1);
     50  await reloadBrowser();
     51  await wait;
     52 
     53  // Make sure the DOMContentLoaded and load markers don't interfere with
     54  // this test by removing them and redrawing the waterfall (bug 1224088).
     55  NetMonitorController.NetworkEventsHandler.clearMarkers();
     56  RequestsMenu._flushWaterfallViews(true);
     57 
     58  ok(
     59    !$("#requests-list-waterfall-label"),
     60    "The timeline label should be hidden after the first request."
     61  );
     62  Assert.greaterOrEqual(
     63    $all(".requests-list-timings-division").length,
     64    3,
     65    "There should be at least 3 tick labels in the network requests header."
     66  );
     67 
     68  const timingDivisionEls = $all(".requests-list-timings-division");
     69  is(
     70    timingDivisionEls[0].textContent,
     71    L10N.getFormatStr("networkMenu.millisecond", 0),
     72    "The first tick label has correct value"
     73  );
     74  is(
     75    timingDivisionEls[1].textContent,
     76    L10N.getFormatStr("networkMenu.millisecond", 80),
     77    "The second tick label has correct value"
     78  );
     79  is(
     80    timingDivisionEls[2].textContent,
     81    L10N.getFormatStr("networkMenu.millisecond", 160),
     82    "The third tick label has correct value"
     83  );
     84 
     85  is(
     86    timingDivisionEls[0].style.width,
     87    "78px",
     88    "The first tick label has correct width"
     89  );
     90  is(
     91    timingDivisionEls[1].style.width,
     92    "80px",
     93    "The second tick label has correct width"
     94  );
     95  is(
     96    timingDivisionEls[2].style.width,
     97    "80px",
     98    "The third tick label has correct width"
     99  );
    100 
    101  ok(
    102    RequestsMenu._canvas,
    103    "A canvas should be created after the first request."
    104  );
    105  ok(
    106    RequestsMenu._ctx,
    107    "A 2d context should be created after the first request."
    108  );
    109 
    110  const imageData = RequestsMenu._ctx.getImageData(0, 0, 161, 1);
    111  ok(imageData, "The image data should have been created.");
    112 
    113  const { data } = imageData;
    114  ok(data, "The image data should contain a pixel array.");
    115 
    116  ok(hasPixelAt(0), "The tick at 0 is should not be empty.");
    117  ok(!hasPixelAt(1), "The tick at 1 is should be empty.");
    118  ok(!hasPixelAt(19), "The tick at 19 is should be empty.");
    119  ok(hasPixelAt(20), "The tick at 20 is should not be empty.");
    120  ok(!hasPixelAt(21), "The tick at 21 is should be empty.");
    121  ok(!hasPixelAt(39), "The tick at 39 is should be empty.");
    122  ok(hasPixelAt(40), "The tick at 40 is should not be empty.");
    123  ok(!hasPixelAt(41), "The tick at 41 is should be empty.");
    124  ok(!hasPixelAt(59), "The tick at 59 is should be empty.");
    125  ok(hasPixelAt(60), "The tick at 60 is should not be empty.");
    126  ok(!hasPixelAt(61), "The tick at 61 is should be empty.");
    127  ok(!hasPixelAt(79), "The tick at 79 is should be empty.");
    128  ok(hasPixelAt(80), "The tick at 80 is should not be empty.");
    129  ok(!hasPixelAt(81), "The tick at 81 is should be empty.");
    130  ok(!hasPixelAt(159), "The tick at 159 is should be empty.");
    131  ok(hasPixelAt(160), "The tick at 160 is should not be empty.");
    132  ok(!hasPixelAt(161), "The tick at 161 is should be empty.");
    133 
    134  ok(
    135    isPixelBrighterAtThan(0, 20),
    136    "The tick at 0 should be brighter than the one at 20"
    137  );
    138  ok(
    139    isPixelBrighterAtThan(40, 20),
    140    "The tick at 40 should be brighter than the one at 20"
    141  );
    142  ok(
    143    isPixelBrighterAtThan(40, 60),
    144    "The tick at 40 should be brighter than the one at 60"
    145  );
    146  ok(
    147    isPixelBrighterAtThan(80, 60),
    148    "The tick at 80 should be brighter than the one at 60"
    149  );
    150 
    151  ok(
    152    isPixelBrighterAtThan(80, 100),
    153    "The tick at 80 should be brighter than the one at 100"
    154  );
    155  ok(
    156    isPixelBrighterAtThan(120, 100),
    157    "The tick at 120 should be brighter than the one at 100"
    158  );
    159  ok(
    160    isPixelBrighterAtThan(120, 140),
    161    "The tick at 120 should be brighter than the one at 140"
    162  );
    163  ok(
    164    isPixelBrighterAtThan(160, 140),
    165    "The tick at 160 should be brighter than the one at 140"
    166  );
    167 
    168  ok(
    169    isPixelEquallyBright(20, 60),
    170    "The tick at 20 should be equally bright to the one at 60"
    171  );
    172  ok(
    173    isPixelEquallyBright(100, 140),
    174    "The tick at 100 should be equally bright to the one at 140"
    175  );
    176 
    177  ok(
    178    isPixelEquallyBright(40, 120),
    179    "The tick at 40 should be equally bright to the one at 120"
    180  );
    181 
    182  ok(
    183    isPixelEquallyBright(0, 80),
    184    "The tick at 80 should be equally bright to the one at 160"
    185  );
    186  ok(
    187    isPixelEquallyBright(80, 160),
    188    "The tick at 80 should be equally bright to the one at 160"
    189  );
    190 
    191  function hasPixelAt(x) {
    192    const i = (x | 0) * 4;
    193    return data[i] && data[i + 1] && data[i + 2] && data[i + 3];
    194  }
    195 
    196  function isPixelBrighterAtThan(x1, x2) {
    197    const i = (x1 | 0) * 4;
    198    const j = (x2 | 0) * 4;
    199    return data[i + 3] > data[j + 3];
    200  }
    201 
    202  function isPixelEquallyBright(x1, x2) {
    203    const i = (x1 | 0) * 4;
    204    const j = (x2 | 0) * 4;
    205    return data[i + 3] == data[j + 3];
    206  }
    207 
    208  return teardown(monitor);
    209 });