chromium/third_party/blink/web_tests/fast/dom/MutationObserver/document-write.html

<!DOCTYPE html>

<div id="result">RESULT</div>

<script>
var resultDiv = document.getElementById('result');

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

var count = 0;
var observer = new MutationObserver(function(r) {
    count += r.length;
});

var div = document.createElement('div');
observer.observe(div, { attributes: true });

function mutate() {
      div.setAttribute('count', count);
}

var counts = [];
function check() {
    counts.push(count);
}

function finish() {
    requestAnimationFrame(() => requestAnimationFrame(() => {
        check();
        var result = counts[0] == 0 &&
                     counts[1] == 0 &&
                     counts[2] == 0 &&
                     counts[3] == 1 ? 'PASSED' : 'FAILED';
        document.body.appendChild(document.createTextNode(result));
        if (window.testRunner)
            testRunner.notifyDone();
    }));
}
</script>

<iframe onload="mutate(); check(); document.write('<script>check();</script>'); document.close(); check(); finish();">