Skip to content

Commit

Permalink
Merge pull request #3274 from Polymer/deepContains-fix-wrap-call
Browse files Browse the repository at this point in the history
Remove call to `wrap` in deepContains
  • Loading branch information
Steve Orvell committed Jan 5, 2016
2 parents f452a7f + 4cbdef7 commit 3b26f6d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@
return true;
}
var n = node;
// wrap document for SD polyfill
var wrappedDocument = wrap(document);
var doc = node.ownerDocument;
// walk from node to `this` or `document`
while (n && n !== wrappedDocument && n !== this.node) {
while (n && n !== doc && n !== this.node) {
// use logical parentnode, or native ShadowRoot host
n = Polymer.dom(n).parentNode || n.host;
}
Expand Down Expand Up @@ -194,7 +193,7 @@
p.oMatchesSelector || p.webkitMatchesSelector;

return DomApi;

})();

</script>
</script>
10 changes: 8 additions & 2 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</head>
<body>
<script>
WCT.loadSuites([
var suites = [
'unit/base.html',
'unit/micro.html',
'unit/unresolved.html',
Expand Down Expand Up @@ -69,7 +69,13 @@
'unit/dom-bind.html',
'unit/script-after-import-in-head.html',
'unit/globals.html'
]);
];

if (document.body.createShadowRoot) {
var idx = suites.indexOf('unit/polymer-dom-shadow.html');
suites.splice(idx, 0, 'unit/polymer-dom-native-shadow.html');
}
WCT.loadSuites(suites);
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions test/unit/polymer-dom-native-shadow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!doctype html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../web-component-tester/browser.js"></script>
<script>Polymer = {dom: 'shadow'};</script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="polymer-dom-elements.html">
</head>
<body>

<x-test></x-test>

<div class="accessors">
<x-test-no-distribute><div class="child"></div></x-test-no-distribute>
<x-project><div class="child"></div></x-project>
</div>

<x-test-no-distribute id="noDistribute">
<div class="bar">Bar</div>
<div class="foo">Foo</div>
</x-test-no-distribute>

<x-select1>
<div class="select-child"></div>
</x-select1>

<x-select-class1>
<div></div>
</x-select-class1>

<x-select-attr>
<x-attr></x-attr>
</x-select-attr>

<x-compose-select-attr></x-compose-select-attr>

<x-redistribute-a-b></x-redistribute-a-b>

<div id="container">
<x-echo></x-echo>
<span>1</span>
<span>2</span>
</div>

<x-deep-contains></x-deep-contains>

<x-wrapped></x-wrapped>

<script src="polymer-dom.js"></script>

</body>
</html>
25 changes: 13 additions & 12 deletions test/unit/polymer-dom.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
suite('Polymer.dom', function() {

var testElement;
var wrap = window.wrap || function(n){ return n; };

suiteSetup(function() {
testElement = document.querySelector('x-test');
})
});

test('querySelector (local)', function() {
var projected = Polymer.dom(testElement.root).querySelector('#projected');
Expand Down Expand Up @@ -96,17 +97,17 @@ suite('Polymer.dom', function() {
testElement.distributeContent();
Polymer.dom.flush();
assert.deepEqual(Polymer.dom(projected).getDestinationInsertionPoints(), ip$);
var rere = Polymer.dom(testElement.root).querySelector('x-rereproject');
rere = Polymer.dom(testElement.root).querySelector('x-rereproject');
assert.equal(rere.is, 'x-rereproject');
rere.distributeContent();
Polymer.dom.flush();
assert.deepEqual(Polymer.dom(projected).getDestinationInsertionPoints(), ip$);
var re = Polymer.dom(rere.root).querySelector('x-reproject');
re = Polymer.dom(rere.root).querySelector('x-reproject');
assert.equal(re.is, 'x-reproject');
re.distributeContent();
Polymer.dom.flush();
assert.deepEqual(Polymer.dom(projected).getDestinationInsertionPoints(), ip$);
var p = Polymer.dom(re.root).querySelector('x-project');
p = Polymer.dom(re.root).querySelector('x-project');
assert.equal(p.is, 'x-project');
});

Expand Down Expand Up @@ -293,10 +294,10 @@ suite('Polymer.dom', function() {
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on host attribute');
c.foo = true;
Polymer.dom.flush();
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute')
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute');
c.foo = false;
Polymer.dom.flush();
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute')
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute');
});

test('within a host setting hostAttributes/reflecting properties provokes distribution', function() {
Expand All @@ -312,10 +313,10 @@ suite('Polymer.dom', function() {
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on host attribute');
c1.foo = true;
Polymer.dom.flush();
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute')
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute');
c1.foo = false;
Polymer.dom.flush();
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute')
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute');
var c2 = e.$.attr2;
Polymer.dom.flush();
assert.equal(Polymer.dom(c2).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on default value');
Expand Down Expand Up @@ -404,7 +405,7 @@ suite('Polymer.dom', function() {
Polymer.dom(rere.root).appendChild(fragment);
var added = Polymer.dom(rere.root).querySelectorAll('span');
assert.equal(added.length, childCount);
for (var i=0; i < added.length; i++) {
for (i=0; i < added.length; i++) {
Polymer.dom(rere.root).removeChild(added[i]);
}
assert.equal(Polymer.dom(rere.root).querySelectorAll('span').length, 0);
Expand All @@ -426,7 +427,7 @@ suite('Polymer.dom', function() {
var added = Polymer.dom(rere.root).querySelectorAll('span');
assert.equal(added.length, childCount+1);
assert.equal(added[added.length-1], l);
for (var i=0; i < added.length; i++) {
for (i=0; i < added.length; i++) {
Polymer.dom(rere.root).removeChild(added[i]);
}
assert.equal(Polymer.dom(rere.root).querySelectorAll('span').length, 0);
Expand Down Expand Up @@ -694,7 +695,7 @@ suite('Polymer.dom accessors', function() {

test('Polymer.dom node accessors (no distribute)', function() {
var child = Polymer.dom(noDistribute).children[0];
assert.isTrue(child.classList.contains('child'), 'test node could not be found')
assert.isTrue(child.classList.contains('child'), 'test node could not be found');
var before = document.createElement('div');
var after = document.createElement('div');
Polymer.dom(noDistribute).insertBefore(before, child);
Expand All @@ -709,7 +710,7 @@ suite('Polymer.dom accessors', function() {

test('Polymer.dom node accessors (distribute)', function() {
var child = Polymer.dom(distribute).children[0];
assert.isTrue(child.classList.contains('child'), 'test node could not be found')
assert.isTrue(child.classList.contains('child'), 'test node could not be found');
var before = document.createElement('div');
var after = document.createElement('div');
Polymer.dom(distribute).insertBefore(before, child);
Expand Down

0 comments on commit 3b26f6d

Please sign in to comment.