Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / devtools / client / netmonitor / test / browser_net_waterfall-resize.js
blobb0c28173d5a25c895f3ce03225036a2270267f16
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7 * Test that waterfall timing elements are resized when the column is resized.
8 */
10 add_task(async function () {
11 // Use a test page with slow requests.
12 const { monitor } = await initNetMonitor(HTTPS_SLOW_REQUESTS_URL, {
13 requestCount: 2,
14 });
15 const { document, store, windowRequire } = monitor.panelWin;
16 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
17 store.dispatch(Actions.batchEnable(false));
19 const onEvents = waitForNetworkEvents(monitor, 2);
20 await reloadBrowser();
21 await onEvents;
23 info("Resize waterfall column a first time");
24 const waterfallHeader = document.querySelector(
25 `#requests-list-waterfall-header-box`
27 const headers = document.querySelector(".requests-list-headers");
28 const parentWidth = headers.getBoundingClientRect().width;
30 let onWaterfallResize = waitForDispatch(store, "WATERFALL_RESIZE");
31 resizeWaterfallColumn(waterfallHeader, 30, parentWidth);
32 await onWaterfallResize;
34 info("Mesure the initial width of a request timing element");
35 const initialWidth = await getStableTimingBoxesWidth(document);
36 info("Measured initialWidth: " + initialWidth);
38 info("Resize waterfall column again");
39 onWaterfallResize = waitForDispatch(store, "WATERFALL_RESIZE");
40 resizeWaterfallColumn(waterfallHeader, 60, parentWidth);
41 await onWaterfallResize;
43 info("Mesure the request timing element again");
44 const finalWidth = await getStableTimingBoxesWidth(
45 document,
46 width => width > 200
48 info("Measured finalWidth: " + finalWidth);
50 // We want to check that finalWidth is different from initialWidth, but
51 // the size might be slightly updated so we can't use isnot to assert this.
52 // The finalWidth should be significantly bigger, so check the difference is
53 // at least greater than 1.
54 Assert.greater(
55 Math.abs(finalWidth - initialWidth),
57 "The request timing element should be updated"
59 return teardown(monitor);
60 });
62 /**
63 * Timings are updated with a slight delay so wait until the dimension is
64 * stabilized.
65 * Measure the widths of all waterfall timing boxes.
67 * @param {Document} doc
68 * Netmonitor document.
69 * @param {function=} predicate
70 * Optional predicate to avoid returning erroneous width. On windows CI,
71 * the second measure is hard to get right, so we use the predicate to make
72 * sure we retrieve the good size.
73 * @returns {number}
74 * The measured width.
76 async function getStableTimingBoxesWidth(doc, predicate = null) {
77 let stableWidth = -1;
78 await waitFor(
79 () => {
80 // Sum the width of all displayed timings.
81 const timingBoxes = [
82 ...doc.querySelectorAll(".requests-list-timings-box"),
84 const widths = timingBoxes.map(el => el.getBoundingClientRect().width);
85 const width = widths.reduce((sum, w) => sum + w, 0);
87 // If the width changed, updated it and return.
88 if (width != stableWidth) {
89 stableWidth = width;
90 return false;
93 // Otherwise, check the predicate if provided.
94 if (typeof predicate == "function") {
95 return predicate(width);
98 return true;
100 "Wait for the timings width to stabilize",
104 return stableWidth;