/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

add_task(async function test_markers_parent_process() {
  info("Test markers that are generated by the browser's parent process.");

  info("Start the profiler in nostacksampling mode.");
  await startProfiler({ features: ["nostacksampling"] });

  info("Dispatch a DOMEvent");
  window.dispatchEvent(new Event("synthetic"));

  info("Stop the profiler and get the profile.");
  const profile = await stopNowAndGetProfile();

  const markers = getInflatedMarkerData(profile.threads[0]);
  {
    const domEventStart = markers.find(
      ({ phase, data }) =>
        phase === INTERVAL_START && data?.eventType === "synthetic"
    );
    const domEventEnd = markers.find(
      ({ phase, data }) =>
        phase === INTERVAL_END && data?.eventType === "synthetic"
    );
    ok(domEventStart, "A start DOMEvent was generated");
    ok(domEventEnd, "An end DOMEvent was generated");
    ok(
      domEventEnd.data.latency > 0,
      "DOMEvent had a a latency value generated."
    );
    ok(domEventEnd.data.type === "DOMEvent");
    ok(domEventEnd.name === "DOMEvent");
  }
  // Add more marker tests.
});
