|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if timeline correctly displays interval divisions. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 let { document, L10N, NetMonitorView } = aMonitor.panelWin; |
|
13 let { RequestsMenu } = NetMonitorView; |
|
14 |
|
15 RequestsMenu.lazyUpdate = false; |
|
16 |
|
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."); |
|
21 |
|
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."); |
|
26 |
|
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."); |
|
32 |
|
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"); |
|
42 |
|
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"); |
|
52 |
|
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."); |
|
57 |
|
58 let imageData = RequestsMenu._ctx.getImageData(0, 0, 161, 1); |
|
59 ok(imageData, "The image data should have been created."); |
|
60 |
|
61 let data = imageData.data; |
|
62 ok(data, "The image data should contain a pixel array."); |
|
63 |
|
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."); |
|
81 |
|
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"); |
|
90 |
|
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"); |
|
99 |
|
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"); |
|
104 |
|
105 ok(isPixelEquallyBright(40, 120), |
|
106 "The tick at 40 should be equally bright to the one at 120"); |
|
107 |
|
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"); |
|
112 |
|
113 function hasPixelAt(x) { |
|
114 let i = (x | 0) * 4; |
|
115 return data[i] && data[i + 1] && data[i + 2] && data[i + 3]; |
|
116 } |
|
117 |
|
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 } |
|
123 |
|
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 } |
|
129 |
|
130 teardown(aMonitor).then(finish); |
|
131 }); |
|
132 |
|
133 aDebuggee.location.reload(); |
|
134 }); |
|
135 } |