Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classList to Polymer.dom when ShadyDOM.noPatch is used #5489

Merged
merged 2 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/legacy/polymer.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP
}
});

forwardReadOnlyProperties(Wrapper.prototype, [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some backstory in a comment about why this appears as such a special case?

It's not a made-up Polymer.dom thing, but it also never needed a Shady DOM patch? Why was it on 1.x's Polymer.dom then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'classList'
]);

DomApiImpl = Wrapper;

Object.defineProperties(EventApi.prototype, {
Expand Down
138 changes: 138 additions & 0 deletions test/unit/polymer-dom-nopatch.html
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,144 @@
assert.equal(useNativeCSSProperties, Boolean(!window.ShadyCSS || window.ShadyCSS.nativeCss));
});

});

suite('forwarded native api', function() {

let el;

setup(function() {
el = document.createElement('x-container-slot');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('accessors are available', function() {
const d = dom(el);
assert.isDefined(d.parentNode);
assert.isDefined(d.firstChild);
assert.isDefined(d.lastChild);
assert.isDefined(d.nextSibling);
assert.isDefined(d.previousSibling);
assert.isDefined(d.firstElementChild);
assert.isDefined(d.lastElementChild);
assert.isDefined(d.nextElementSibling);
assert.isDefined(d.previousElementSibling);
assert.isDefined(d.childNodes);
assert.isDefined(d.children);
assert.isDefined(d.classList);
assert.isDefined(d.textContent);
assert.isDefined(d.innerHTML);
});

test('cloneNode', function() {
const clone = dom(el).cloneNode(el);
assert.ok(clone);
assert.equal(clone.localName, 'x-container-slot');
});

test('appendChild', function() {
const d1 = document.createElement('div');
dom(el).appendChild(d1);
assert.equal(dom(el).firstChild, d1);
assert.equal(dom(d1).parentNode, el);
});

test('insertBefore', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).insertBefore(d2, d1);
assert.equal(dom(d2).nextSibling, d1);
});

test('removeChild', function() {
const d1 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).removeChild(d1);
assert.equal(dom(d1).parentNode, null);
});

test('replaceChild', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).replaceChild(d2, d1);
assert.equal(dom(d1).parentNode, null);
assert.equal(dom(el).firstChild, d2);
assert.equal(dom(d2).parentNode, el);
});

test('replaceChild', function() {
dom(el).setAttribute('foo', 'foo');
assert.equal(el.getAttribute('foo'), 'foo');
});

test('replaceChild', function() {
dom(el).setAttribute('foo', 'foo');
dom(el).removeAttribute('foo');
assert.isFalse(el.hasAttribute('foo'));
});

test('querySelector', function() {
const d1 = document.createElement('div');
dom(el).appendChild(d1);
const query = dom(el).querySelector('div');
assert.equal(query, d1);
});

test('querySelectorAll', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).appendChild(d2);
const query = dom(el).querySelectorAll('div');
assert.equal(query[0], d1);
assert.equal(query[1], d2);
assert.equal(query.length, 2);
});

test('tree accessors', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).appendChild(d2);
const pel = dom(el);
const pd1 = dom(d1);
const pd2 = dom(d2);
assert.equal(pd1.parentNode, el);
assert.equal(pel.firstChild, d1);
assert.equal(pel.lastChild, d2);
assert.equal(pel.firstElementChild, d1);
assert.equal(pel.lastElementChild, d2);
assert.equal(pd1.nextSibling, d2);
assert.equal(pd2.previousSibling, d1);
assert.equal(pd1.nextElementSibling, d2);
assert.equal(pd2.previousElementSibling, d1);
assert.equal(pel.childNodes[0], d1);
assert.equal(pel.childNodes[1], d2);
assert.equal(pel.children[0], d1);
assert.equal(pel.children[1], d2);
});

test('innerHTML', function() {
dom(el).innerHTML = '<div></div>';
assert.equal(dom(el).firstChild.localName, 'div');
});

test('textContent', function() {
dom(el).innerHTML = 'hi';
assert.equal(dom(dom(el).firstChild).textContent, 'hi');
});

test('classList', function() {
dom(el).classList.add('foo');
assert.equal(el.className, 'foo');
});

});
</script>

Expand Down
138 changes: 138 additions & 0 deletions test/unit/polymer-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,144 @@
assert.equal(useNativeCSSProperties, Boolean(!window.ShadyCSS || window.ShadyCSS.nativeCss));
});

});

suite('forwarded native api', function() {

let el;

setup(function() {
el = document.createElement('x-container-slot');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('accessors are available', function() {
const d = dom(el);
assert.isDefined(d.parentNode);
assert.isDefined(d.firstChild);
assert.isDefined(d.lastChild);
assert.isDefined(d.nextSibling);
assert.isDefined(d.previousSibling);
assert.isDefined(d.firstElementChild);
assert.isDefined(d.lastElementChild);
assert.isDefined(d.nextElementSibling);
assert.isDefined(d.previousElementSibling);
assert.isDefined(d.childNodes);
assert.isDefined(d.children);
assert.isDefined(d.classList);
assert.isDefined(d.textContent);
assert.isDefined(d.innerHTML);
});

test('cloneNode', function() {
const clone = dom(el).cloneNode(el);
assert.ok(clone);
assert.equal(clone.localName, 'x-container-slot');
});

test('appendChild', function() {
const d1 = document.createElement('div');
dom(el).appendChild(d1);
assert.equal(dom(el).firstChild, d1);
assert.equal(dom(d1).parentNode, el);
});

test('insertBefore', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).insertBefore(d2, d1);
assert.equal(dom(d2).nextSibling, d1);
});

test('removeChild', function() {
const d1 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).removeChild(d1);
assert.equal(dom(d1).parentNode, null);
});

test('replaceChild', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).replaceChild(d2, d1);
assert.equal(dom(d1).parentNode, null);
assert.equal(dom(el).firstChild, d2);
assert.equal(dom(d2).parentNode, el);
});

test('replaceChild', function() {
dom(el).setAttribute('foo', 'foo');
assert.equal(el.getAttribute('foo'), 'foo');
});

test('replaceChild', function() {
dom(el).setAttribute('foo', 'foo');
dom(el).removeAttribute('foo');
assert.isFalse(el.hasAttribute('foo'));
});

test('querySelector', function() {
const d1 = document.createElement('div');
dom(el).appendChild(d1);
const query = dom(el).querySelector('div');
assert.equal(query, d1);
});

test('querySelectorAll', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).appendChild(d2);
const query = dom(el).querySelectorAll('div');
assert.equal(query[0], d1);
assert.equal(query[1], d2);
assert.equal(query.length, 2);
});

test('tree accessors', function() {
const d1 = document.createElement('div');
const d2 = document.createElement('div');
dom(el).appendChild(d1);
dom(el).appendChild(d2);
const pel = dom(el);
const pd1 = dom(d1);
const pd2 = dom(d2);
assert.equal(pd1.parentNode, el);
assert.equal(pel.firstChild, d1);
assert.equal(pel.lastChild, d2);
assert.equal(pel.firstElementChild, d1);
assert.equal(pel.lastElementChild, d2);
assert.equal(pd1.nextSibling, d2);
assert.equal(pd2.previousSibling, d1);
assert.equal(pd1.nextElementSibling, d2);
assert.equal(pd2.previousElementSibling, d1);
assert.equal(pel.childNodes[0], d1);
assert.equal(pel.childNodes[1], d2);
assert.equal(pel.children[0], d1);
assert.equal(pel.children[1], d2);
});

test('innerHTML', function() {
dom(el).innerHTML = '<div></div>';
assert.equal(dom(el).firstChild.localName, 'div');
});

test('textContent', function() {
dom(el).innerHTML = 'hi';
assert.equal(dom(dom(el).firstChild).textContent, 'hi');
});

test('classList', function() {
dom(el).classList.add('foo');
assert.equal(el.className, 'foo');
});

});
</script>

Expand Down