From c632455122ff326df6fd14688635b1bce93b27bb Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Mon, 25 Nov 2013 13:59:00 -0500 Subject: [PATCH] Fix outerHTML setter so that mutation observers are notified --- src/wrappers/HTMLElement.js | 4 ++-- test/js/MutationObserver/childList.js | 32 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/wrappers/HTMLElement.js b/src/wrappers/HTMLElement.js index 394dfd7..9d5de61 100644 --- a/src/wrappers/HTMLElement.js +++ b/src/wrappers/HTMLElement.js @@ -137,11 +137,11 @@ return getOuterHTML(this); }, set outerHTML(value) { - // TODO(arv): Mutation observer var p = this.parentNode; if (p) { p.invalidateShadowRenderer(); - this.impl.outerHTML = value; + var df = frag(p, value); + p.replaceChild(df, this); } }, diff --git a/test/js/MutationObserver/childList.js b/test/js/MutationObserver/childList.js index a4117e4..fe54c68 100644 --- a/test/js/MutationObserver/childList.js +++ b/test/js/MutationObserver/childList.js @@ -758,6 +758,38 @@ suite('MutationObserver', function() { }); }); + test('outerHTML', function() { + var a = document.createElement('a'); + a.innerHTML = ''; + var b = a.firstChild; + var c = b.nextSibling; + var d = a.lastChild; + + var sr = a.createShadowRoot(); + a.offsetHeight; + + var observer = new MutationObserver(function() {}); + observer.observe(a, { + childList: true + }); + + c.outerHTML = ''; + assert.equal(a.innerHTML, ''); + var e = b.nextSibling; + var f = e.nextSibling; + + var records = observer.takeRecords(); + assert.equal(records.length, 1); + expectMutationRecord(records[0], { + type: 'childList', + target: a, + addedNodes: [e, f], + removedNodes: [c], + previousSibling: b, + nextSibling: d + }); + }); + }); });