browser_timeline-waterfall-sidebar.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /* eslint-disable */
  4. /**
  5. * Tests if the sidebar is properly updated when a marker is selected.
  6. */
  7. function* spawnTest() {
  8. let { target, panel } = yield initPerformance(SIMPLE_URL);
  9. let { $, $$, PerformanceController, WaterfallView } = panel.panelWin;
  10. let { L10N } = require("devtools/client/performance/modules/global");
  11. let { MarkerBlueprintUtils } = require("devtools/client/performance/modules/marker-blueprint-utils");
  12. // Hijack the markers massaging part of creating the waterfall view,
  13. // to prevent collapsing markers and allowing this test to verify
  14. // everything individually. A better solution would be to just expand
  15. // all markers first and then skip the meta nodes, but I'm lazy.
  16. WaterfallView._prepareWaterfallTree = markers => {
  17. return { submarkers: markers };
  18. };
  19. yield startRecording(panel);
  20. ok(true, "Recording has started.");
  21. yield waitUntil(() => {
  22. // Wait until we get 3 different markers.
  23. let markers = PerformanceController.getCurrentRecording().getMarkers();
  24. return markers.some(m => m.name == "Styles") &&
  25. markers.some(m => m.name == "Reflow") &&
  26. markers.some(m => m.name == "Paint");
  27. });
  28. yield stopRecording(panel);
  29. ok(true, "Recording has ended.");
  30. info("No need to select everything in the timeline.");
  31. info("All the markers should be displayed by default.");
  32. let bars = $$(".waterfall-marker-bar");
  33. let markers = PerformanceController.getCurrentRecording().getMarkers();
  34. info(`Got ${bars.length} bars and ${markers.length} markers.`);
  35. info("Markers types from datasrc: " + Array.map(markers, e => e.name));
  36. info("Markers names from sidebar: " + Array.map(bars, e => e.parentNode.parentNode.querySelector(".waterfall-marker-name").getAttribute("value")));
  37. ok(bars.length > 2, "Got at least 3 markers (1)");
  38. ok(markers.length > 2, "Got at least 3 markers (2)");
  39. let toMs = ms => L10N.getFormatStrWithNumbers("timeline.tick", ms);
  40. for (let i = 0; i < bars.length; i++) {
  41. let bar = bars[i];
  42. let mkr = markers[i];
  43. EventUtils.sendMouseEvent({ type: "mousedown" }, bar);
  44. let type = $(".marker-details-type").getAttribute("value");
  45. let tooltip = $(".marker-details-duration").getAttribute("tooltiptext");
  46. let duration = $(".marker-details-duration .marker-details-labelvalue").getAttribute("value");
  47. info("Current marker data: " + mkr.toSource());
  48. info("Current marker output: " + $("#waterfall-details").innerHTML);
  49. is(type, MarkerBlueprintUtils.getMarkerLabel(mkr), "Sidebar title matches markers name.");
  50. // Values are rounded. We don't use a strict equality.
  51. is(toMs(mkr.end - mkr.start), duration, "Sidebar duration is valid.");
  52. // For some reason, anything that creates "→" here turns it into a "â" for some reason.
  53. // So just check that start and end time are in there somewhere.
  54. ok(tooltip.indexOf(toMs(mkr.start)) !== -1, "Tooltip has start time.");
  55. ok(tooltip.indexOf(toMs(mkr.end)) !== -1, "Tooltip has end time.");
  56. }
  57. yield teardown(panel);
  58. finish();
  59. }
  60. /* eslint-enable */