browser_timeline-waterfall-workers.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /* eslint-disable */
  5. /**
  6. * Tests if the sidebar is properly updated with worker markers.
  7. */
  8. function* spawnTest() {
  9. let { panel } = yield initPerformance(WORKER_URL);
  10. let { $$, $, PerformanceController } = panel.panelWin;
  11. loadFrameScripts();
  12. yield startRecording(panel);
  13. ok(true, "Recording has started.");
  14. evalInDebuggee("performWork()");
  15. yield waitUntil(() => {
  16. // Wait until we get the worker markers.
  17. let markers = PerformanceController.getCurrentRecording().getMarkers();
  18. if (!markers.some(m => m.name == "Worker") ||
  19. !markers.some(m => m.workerOperation == "serializeDataOffMainThread") ||
  20. !markers.some(m => m.workerOperation == "serializeDataOnMainThread") ||
  21. !markers.some(m => m.workerOperation == "deserializeDataOffMainThread") ||
  22. !markers.some(m => m.workerOperation == "deserializeDataOnMainThread")) {
  23. return false;
  24. }
  25. testWorkerMarkerData(markers.find(m => m.name == "Worker"));
  26. return true;
  27. });
  28. yield stopRecording(panel);
  29. ok(true, "Recording has ended.");
  30. for (let node of $$(".waterfall-marker-name[value=Worker")) {
  31. testWorkerMarkerUI(node.parentNode.parentNode);
  32. }
  33. yield teardown(panel);
  34. finish();
  35. }
  36. function testWorkerMarkerData(marker) {
  37. ok(true, "Found a worker marker.");
  38. ok("start" in marker,
  39. "The start time is specified in the worker marker.");
  40. ok("end" in marker,
  41. "The end time is specified in the worker marker.");
  42. ok("workerOperation" in marker,
  43. "The worker operation is specified in the worker marker.");
  44. ok("processType" in marker,
  45. "The process type is specified in the worker marker.");
  46. ok("isOffMainThread" in marker,
  47. "The thread origin is specified in the worker marker.");
  48. }
  49. function testWorkerMarkerUI(node) {
  50. is(node.className, "waterfall-tree-item",
  51. "The marker node has the correct class name.");
  52. ok(node.hasAttribute("otmt"),
  53. "The marker node specifies if it is off the main thread or not.");
  54. }
  55. /**
  56. * Takes a string `script` and evaluates it directly in the content
  57. * in potentially a different process.
  58. */
  59. function evalInDebuggee(script) {
  60. let { generateUUID } = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
  61. let deferred = Promise.defer();
  62. if (!mm) {
  63. throw new Error("`loadFrameScripts()` must be called when using MessageManager.");
  64. }
  65. let id = generateUUID().toString();
  66. mm.sendAsyncMessage("devtools:test:eval", { script: script, id: id });
  67. mm.addMessageListener("devtools:test:eval:response", handler);
  68. function handler({ data }) {
  69. if (id !== data.id) {
  70. return;
  71. }
  72. mm.removeMessageListener("devtools:test:eval:response", handler);
  73. deferred.resolve(data.value);
  74. }
  75. return deferred.promise;
  76. }
  77. /* eslint-enable */