chromium/third_party/blink/web_tests/fast/dom/MutationObserver/delivery-order.html

<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<script>
window.jsTestIsAsync = true;

description('Test that MutationObservers are delivered to in order of creation.');
function finish() {
    shouldBe('order.length', '10');
    shouldBe('order[0]', '0');
    shouldBe('order[1]', '1');
    shouldBe('order[2]', '2');
    shouldBe('order[3]', '3');
    shouldBe('order[4]', '4');
    shouldBe('order[5]', '5');
    shouldBe('order[6]', '6');
    shouldBe('order[7]', '7');
    shouldBe('order[8]', '8');
    shouldBe('order[9]', '9');
    finishJSTest();
}

var order = [];
var observers = [];

function setUpOrdering(num) {
    observers.push(new MutationObserver(function(mutations) {
        order.push(num);
    }));
}

for (var i = 0; i < 10; ++i) {
    setUpOrdering(i);
}

var div = document.createElement('div');
observers[3].observe(div, {attributes: true});
observers[2].observe(div, {characterData: true, subtree: true});
observers[1].observe(div, {attributes: true});
observers[7].observe(div, {childList: true});
observers[4].observe(div, {attributes: true});
observers[9].observe(div, {attributes: true});
observers[0].observe(div, {childList: true});
observers[5].observe(div, {attributes: true});
observers[6].observe(div, {characterData: true, subtree: true});
observers[8].observe(div, {attributes: true});
div.setAttribute('foo', 'bar');
div.appendChild(document.createTextNode('hello'));
div.firstChild.textContent = 'goodbye';
setTimeout(finish, 0);
</script>