browser/devtools/netmonitor/test/browser_net_timeline_ticks.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests if timeline correctly displays interval divisions.
     6  */
     8 function test() {
     9   initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
    10     info("Starting test... ");
    12     let { document, L10N, NetMonitorView } = aMonitor.panelWin;
    13     let { RequestsMenu } = NetMonitorView;
    15     RequestsMenu.lazyUpdate = false;
    17     ok(document.querySelector("#requests-menu-waterfall-label"),
    18       "An timeline label should be displayed when the frontend is opened.");
    19     ok(document.querySelectorAll(".requests-menu-timings-division").length == 0,
    20       "No tick labels should be displayed when the frontend is opened.");
    22     ok(!RequestsMenu._canvas,
    23       "No canvas should be created when the frontend is opened.");
    24     ok(!RequestsMenu._ctx,
    25       "No 2d context should be created when the frontend is opened.");
    27     waitForNetworkEvents(aMonitor, 1).then(() => {
    28       ok(!document.querySelector("#requests-menu-waterfall-label"),
    29         "The timeline label should be hidden after the first request.");
    30       ok(document.querySelectorAll(".requests-menu-timings-division").length >= 3,
    31         "There should be at least 3 tick labels in the network requests header.");
    33       is(document.querySelectorAll(".requests-menu-timings-division")[0]
    34         .getAttribute("value"), L10N.getFormatStr("networkMenu.millisecond", 0),
    35         "The first tick label has an incorrect value");
    36       is(document.querySelectorAll(".requests-menu-timings-division")[1]
    37         .getAttribute("value"), L10N.getFormatStr("networkMenu.millisecond", 80),
    38         "The second tick label has an incorrect value");
    39       is(document.querySelectorAll(".requests-menu-timings-division")[2]
    40         .getAttribute("value"), L10N.getFormatStr("networkMenu.millisecond", 160),
    41         "The third tick label has an incorrect value");
    43       is(document.querySelectorAll(".requests-menu-timings-division")[0]
    44         .style.transform, "translateX(0px)",
    45         "The first tick label has an incorrect translation");
    46       is(document.querySelectorAll(".requests-menu-timings-division")[1]
    47         .style.transform, "translateX(80px)",
    48         "The second tick label has an incorrect translation");
    49       is(document.querySelectorAll(".requests-menu-timings-division")[2]
    50         .style.transform, "translateX(160px)",
    51         "The third tick label has an incorrect translation");
    53       ok(RequestsMenu._canvas,
    54         "A canvas should be created after the first request.");
    55       ok(RequestsMenu._ctx,
    56         "A 2d context should be created after the first request.");
    58       let imageData = RequestsMenu._ctx.getImageData(0, 0, 161, 1);
    59       ok(imageData, "The image data should have been created.");
    61       let data = imageData.data;
    62       ok(data, "The image data should contain a pixel array.");
    64       ok( hasPixelAt(0), "The tick at 0 is should not be empty.");
    65       ok(!hasPixelAt(1), "The tick at 1 is should be empty.");
    66       ok(!hasPixelAt(19), "The tick at 19 is should be empty.");
    67       ok( hasPixelAt(20), "The tick at 20 is should not be empty.");
    68       ok(!hasPixelAt(21), "The tick at 21 is should be empty.");
    69       ok(!hasPixelAt(39), "The tick at 39 is should be empty.");
    70       ok( hasPixelAt(40), "The tick at 40 is should not be empty.");
    71       ok(!hasPixelAt(41), "The tick at 41 is should be empty.");
    72       ok(!hasPixelAt(59), "The tick at 59 is should be empty.");
    73       ok( hasPixelAt(60), "The tick at 60 is should not be empty.");
    74       ok(!hasPixelAt(61), "The tick at 61 is should be empty.");
    75       ok(!hasPixelAt(79), "The tick at 79 is should be empty.");
    76       ok( hasPixelAt(80), "The tick at 80 is should not be empty.");
    77       ok(!hasPixelAt(81), "The tick at 81 is should be empty.");
    78       ok(!hasPixelAt(159), "The tick at 159 is should be empty.");
    79       ok( hasPixelAt(160), "The tick at 160 is should not be empty.");
    80       ok(!hasPixelAt(161), "The tick at 161 is should be empty.");
    82       ok(isPixelBrighterAtThan(0, 20),
    83         "The tick at 0 should be brighter than the one at 20");
    84       ok(isPixelBrighterAtThan(40, 20),
    85         "The tick at 40 should be brighter than the one at 20");
    86       ok(isPixelBrighterAtThan(40, 60),
    87         "The tick at 40 should be brighter than the one at 60");
    88       ok(isPixelBrighterAtThan(80, 60),
    89         "The tick at 80 should be brighter than the one at 60");
    91       ok(isPixelBrighterAtThan(80, 100),
    92         "The tick at 80 should be brighter than the one at 100");
    93       ok(isPixelBrighterAtThan(120, 100),
    94         "The tick at 120 should be brighter than the one at 100");
    95       ok(isPixelBrighterAtThan(120, 140),
    96         "The tick at 120 should be brighter than the one at 140");
    97       ok(isPixelBrighterAtThan(160, 140),
    98         "The tick at 160 should be brighter than the one at 140");
   100       ok(isPixelEquallyBright(20, 60),
   101         "The tick at 20 should be equally bright to the one at 60");
   102       ok(isPixelEquallyBright(100, 140),
   103         "The tick at 100 should be equally bright to the one at 140");
   105       ok(isPixelEquallyBright(40, 120),
   106         "The tick at 40 should be equally bright to the one at 120");
   108       ok(isPixelEquallyBright(0, 80),
   109         "The tick at 80 should be equally bright to the one at 160");
   110       ok(isPixelEquallyBright(80, 160),
   111         "The tick at 80 should be equally bright to the one at 160");
   113       function hasPixelAt(x) {
   114         let i = (x | 0) * 4;
   115         return data[i] && data[i + 1] && data[i + 2] && data[i + 3];
   116       }
   118       function isPixelBrighterAtThan(x1, x2) {
   119         let i = (x1 | 0) * 4;
   120         let j = (x2 | 0) * 4;
   121         return data[i + 3] > data [j + 3];
   122       }
   124       function isPixelEquallyBright(x1, x2) {
   125         let i = (x1 | 0) * 4;
   126         let j = (x2 | 0) * 4;
   127         return data[i + 3] == data [j + 3];
   128       }
   130       teardown(aMonitor).then(finish);
   131     });
   133     aDebuggee.location.reload();
   134   });
   135 }

mercurial