blob: cbceb205f7d16b0c4d00bd0685b17bfe0d06eecb [file] [log] [blame]
<html>
<link rel="import" href="../resources/chai.html" />
<link rel="import" href="../resources/mocha.html" />
<script>
describe('MutationObserver.takeRecords', function() {
it('should allow taking records synchronously or getting a notification', function(done) {
var mutations;
var div;
var subDiv;
var observer;
// Testing takeRecords.
mutations = null;
div = document.createElement('div');
subDiv = div.appendChild(document.createElement('div'));
subDiv.textContent = 'hello, world';
observer = new MutationObserver(function(records) {
mutations = records;
});
observer.observe(div, {attributes: true, characterData: true, subtree: true});
subDiv.setAttribute('foo', 'bar');
subDiv.firstChild.textContent = 'goodbye!';
div.removeChild(subDiv);
mutations = observer.takeRecords();
// ...records are taken synchronously.
assert.equal(mutations.length, 2);
assert.equal(mutations[0].type, "attributes");
assert.equal(mutations[0].target, subDiv);
assert.equal(mutations[0].attributeName, "foo");
assert.equal(mutations[1].type, "characterData");
assert.equal(mutations[1].target, subDiv.firstChild);
subDiv.setAttribute('foo', 'baz');
setTimeout(function() {
// ...takeRecord took records, but did not clear transient observers.
assert.equal(mutations.length, 1);
assert.equal(mutations[0].type, "attributes");
assert.equal(mutations[0].target, subDiv);
assert.equal(mutations[0].attributeName, "foo");
observer.disconnect();
done();
}, 0);
});
});
</script>
</html>