<!DOCTYPE HTML>
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("Ensure PerformanceObservers are notified in order of registration (observe).");
window.jsTestIsAsync = true;

window.count = 0;

let observer1 = new PerformanceObserver((list) => {
    count++;
    testPassed("PerformanceObserver 1 callback fired");
    shouldBe(`count`, `1`);
});

let observer2 = new PerformanceObserver((list) => {
    count++;
    testPassed("PerformanceObserver 2 callback fired");
    shouldBe(`count`, `2`);
});

// Ensure creation doesn't impact order.
let observerSpecial = new PerformanceObserver((list) => {
    count++;
    testPassed("PerformanceObserver 6 callback fired");
    shouldBe(`count`, `6`);
    finishJSTest();
});

let observer3 = new PerformanceObserver((list) => {
    count++;
    testPassed("PerformanceObserver 3 callback fired");
    shouldBe(`count`, `3`);
});

let observer4 = new PerformanceObserver((list) => {
    count++;
    testPassed("PerformanceObserver 4 callback fired");
    shouldBe(`count`, `4`);
});

let observer5 = new PerformanceObserver((list) => {
    count++;
    testPassed("PerformanceObserver 5 callback fired");
    shouldBe(`count`, `5`);
});

// Register all in order.
for (let o of [observer1, observer2, observerSpecial, observer3, observer4, observer5])
    o.observe({entryTypes: ["mark"]});

// Unregister and re-register moves this to the back of the line.
observerSpecial.disconnect();
observerSpecial.observe({entryTypes: ["mark"]});

performance.mark("mark1");
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>
