From 4cbdef740d95282ded63c6893a793fc19a198595 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Tue, 5 Jan 2016 14:55:06 -0800 Subject: [PATCH] Remove call to `wrap` in deepContains Test Polymer.dom with native shadowroot (chrome only) Fixes #3273 --- src/lib/dom-api.html | 9 ++-- test/runner.html | 10 +++- test/unit/polymer-dom-native-shadow.html | 62 ++++++++++++++++++++++++ test/unit/polymer-dom.js | 25 +++++----- 4 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 test/unit/polymer-dom-native-shadow.html diff --git a/src/lib/dom-api.html b/src/lib/dom-api.html index d14f7f4564..caa0ca2b55 100644 --- a/src/lib/dom-api.html +++ b/src/lib/dom-api.html @@ -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; } @@ -194,7 +193,7 @@ p.oMatchesSelector || p.webkitMatchesSelector; return DomApi; - + })(); - \ No newline at end of file + diff --git a/test/runner.html b/test/runner.html index 654381b6a1..8acdc9b910 100644 --- a/test/runner.html +++ b/test/runner.html @@ -15,7 +15,7 @@ diff --git a/test/unit/polymer-dom-native-shadow.html b/test/unit/polymer-dom-native-shadow.html new file mode 100644 index 0000000000..d7b9d1163c --- /dev/null +++ b/test/unit/polymer-dom-native-shadow.html @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + +
+
+
+
+ + +
Bar
+
Foo
+
+ + +
+
+ + +
+
+ + + + + + + + + +
+ + 1 + 2 +
+ + + + + + + + + diff --git a/test/unit/polymer-dom.js b/test/unit/polymer-dom.js index 1ca84df5f1..c11a6e8dd5 100644 --- a/test/unit/polymer-dom.js +++ b/test/unit/polymer-dom.js @@ -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'); @@ -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'); }); @@ -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() { @@ -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'); @@ -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); @@ -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); @@ -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); @@ -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);