Add test for Polymer.dom().getOwnerRoot.

This commit is contained in:
Steve Orvell
2015-04-13 10:06:22 -07:00
parent 90144b1633
commit b9d22e6d26
2 changed files with 43 additions and 20 deletions

View File

@@ -58,24 +58,33 @@
</script>
<dom-module id="x-distribute">
<template>
<div>
<span>Elements without test attribute</span>
<div id="notTestContainer" style="color: white; background-color: green; min-height: 1em;">
<content id="notTestContent" select=":not([test])"></content>
</div>
<span>Elements with test attribute</span>
<div style="color: white; background-color: red; min-height: 1em;">
<div id="testContainer">
<content id="testContent" select="[test]"></content>
</div>
<template>
<div>
<span>Elements without test attribute</span>
<div id="notTestContainer" style="color: white; background-color: green; min-height: 1em;">
<content id="notTestContent" select=":not([test])"></content>
</div>
<span>Elements with test attribute</span>
<div style="color: white; background-color: red; min-height: 1em;">
<div id="testContainer">
<content id="testContent" select="[test]"></content>
</div>
</div>
</template>
</dom-element>
<script>
Polymer({
is: "x-distribute"
});
</script>
</div>
</template>
</dom-element>
<script>
Polymer({
is: "x-distribute"
});
</script>
<dom-module id="x-compose">
<template><x-project id="project"></x-project></template>
</dom-module>
<script>
Polymer({
is: 'x-compose'
});
</script>

View File

@@ -373,4 +373,18 @@ suite('Polymer.dom non-distributed elements', function() {
testWithAttr();
});
});
test('getOwnerRoot', function() {
var test = document.createElement('div');
var c1 = document.createElement('x-compose');
var c2 = document.createElement('x-compose');
Polymer.dom(c1.$.project).appendChild(test);
Polymer.dom.flush();
assert.equal(Polymer.dom(test).getOwnerRoot(), c1.root, 'getOwnerRoot incorrect for child added to element in root');
Polymer.dom(c2.$.project).appendChild(test);
Polymer.dom.flush();
assert.equal(Polymer.dom(test).getOwnerRoot(), c2.root, 'getOwnerRoot not correctly reset when element moved to different root');
Polymer.dom(c1).appendChild(test);
assert.notOk(Polymer.dom(test).getOwnerRoot(), 'getOwnerRoot incorrect for child moved from a root to no root');
});
});