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