Skip to content

Commit

Permalink
Fixes #27 and adds v1 shady tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Aug 5, 2016
1 parent e7b623f commit 2f0a22a
Show file tree
Hide file tree
Showing 14 changed files with 4,127 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/compat/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@
var list = [];
var c$ = this.childNodes;
for (var i=0, l=c$.length, c; (i<l) && (c=c$[i]); i++) {
if (c.localName === 'content') {
var d$ = c.getDistributedNodes();
var d$ = (c.localName === 'content') ? c.getDistributedNodes() :
(c.localName === 'slot') ? c.assignedNodes({flatten: true}) : null;
if (d$) {
for (var j=0; j < d$.length; j++) {
list.push(d$[j]);
}
Expand Down
19 changes: 4 additions & 15 deletions src/shady/distributor-v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,10 @@

matchesInsertionPoint(node, insertionPoint) {
var slotName = insertionPoint.getAttribute('name');
// no selector matches all nodes (including text)
if (!slotName) {
return true;
}
slotName = slotName.trim();
// same thing if it had only whitespace
if (!slotName) {
return true;
}
// only elements can have attributes
if (!(node instanceof Element)) {
return false;
}
var slot = node.getAttribute('slot');
return (slot && (slot.trim() == slotName));
slotName = slotName ? slotName.trim() : '';
var slot = node.getAttribute && node.getAttribute('slot');
slot = slot ? slot.trim() : '';
return (slot == slotName);
}

distributeNodeInto(child, insertionPoint) {
Expand Down
10 changes: 6 additions & 4 deletions src/shady/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,12 @@
}
this.__eventListenerCount++;
var wrappedFn = function(e) {
e.__target = e.target;
var proto = ShadyDom.patchImpl.prototypeForObject(e);
if (proto) {
e.__proto__ = proto;
if (!e.__target) {
e.__target = e.target;
var proto = ShadyDom.patchImpl.prototypeForObject(e);
if (proto) {
e.__proto__ = proto;
}
}
return fn(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/shady/flush.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
_flushGuard: 0,
_FLUSH_MAX: 100,
// TODO(sorvell): polyfill...
_needsTakeRecords: false /*&& !Polymer.Settings.useNativeCustomElements*/,
_needsTakeRecords: true /*&& !Polymer.Settings.useNativeCustomElements*/,
_debouncers: [],
_staticFlushList: [],
_finishDebouncer: null,
Expand Down Expand Up @@ -55,7 +55,7 @@
// these mutations may be inside shadowRoots.
// again make any pending CE mutations that might trigger debouncer
// additions go...
if (this._needsTakeRecords) {
if (this._needsTakeRecords && window.CustomElements) {
CustomElements.takeRecords();
}
for (var i=0; i < this._staticFlushList.length; i++) {
Expand Down
9 changes: 6 additions & 3 deletions src/templatizer/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,12 @@
_detachInstance: function(idx) {
var inst = this._instances[idx];
if (!inst.isPlaceholder) {
for (var i=0; i<inst._children.length; i++) {
var el = inst._children[i];
inst.root.appendChild(el);
//TODO(sorvell): why is this necessary?
if (inst._children) {
for (var i=0; i<inst._children.length; i++) {
var el = inst._children[i];
inst.root.appendChild(el);
}
}
return inst;
}
Expand Down
3 changes: 3 additions & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
'unit/shady.html',
'unit/shady-content.html',
'unit/shady-dynamic.html',
'unit/shady-v1.html',
'unit/shady-v1-content.html',
'unit/shady-v1-dynamic.html',
'unit/styling-cross-scope-var.html',
'unit/styling-cross-scope-apply.html',
'unit/styling-cross-scope-unknown-host.html',
Expand Down
59 changes: 59 additions & 0 deletions test/smoke/slot-name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!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>
<title>Polymer</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html">
</head>
<body>
<dom-module id="x-example">
<template>
<slot></slot>
<slot name="after"></slot>
</template>

<script>
Polymer({
is: 'x-example'
});
</script>
</dom-module>

<x-example>
<div slot="after">Last</div>
<div>First</div>
</x-example>

<hr>

<dom-module id="x-example2">
<template>
<slot></slot>
<!-- <slot name="after"></slot> -->
</template>

<script>
Polymer({
is: 'x-example2'
});
</script>
</dom-module>

<x-example2>
<div slot="after">Last</div>
<div>First</div>
</x-example2>

</body>
</html>
40 changes: 40 additions & 0 deletions test/smoke/taco.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!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>
<title>Taco</title>
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script>
class Taco extends HTMLElement {
static get observedAttributes() { return ['foo'] }

constructor() {
super();
console.log('constructor');
}

attributeChangedCallback() {
console.log('attributeChangedCallback', this.localName, arguments);
}
}

customElements.define('ta-co', Taco);
</script>
</head>
<body>
<ta-co foo="a"></ta-co>



</body>


</html>
1 change: 0 additions & 1 deletion test/unit/shady-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
Polymer = {shadowDomV0: true};
</script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="../../src/shady/shady.html">
</head>
<body>

Expand Down
23 changes: 12 additions & 11 deletions test/unit/shady-dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
Polymer.shadowDomV0 = true;

</script>
</script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="../../src/shady/shady.html">
</head>
<body>

Expand Down Expand Up @@ -763,11 +761,12 @@
assert(p.querySelectorAll('content').length, 1);
});

test.skip('querySelectorAll with dom-repeat', function() {
test('querySelectorAll with dom-repeat', function() {
var el = document.createElement('polymer-dom-repeat');
document.body.appendChild(el);
CustomElements.takeRecords();
ShadyDom.flush();
assert.equal(el.$.container.querySelectorAll('*').length, 6, 'querySelectorAll finds repeated elements');
assert.equal(el.$.container.querySelectorAll('*').length, 7, 'querySelectorAll finds repeated elements');
document.body.removeChild(el);
});

Expand Down Expand Up @@ -1253,16 +1252,16 @@
assert.notOk(projected);
});

test.skip('event', function() {
test('event', function() {
var rere = testElement.root.querySelector('x-rereproject');
var re = rere.root.querySelector('x-reproject');
var p = re.root.querySelector('x-project');
var eventHandled = 0;
testElement.addEventListener('test-event', function(e) {
eventHandled++;
assert.equal(e.rootTarget, p);
assert.equal(e.localTarget, testElement);
var path = e.path;
assert.equal(e.deepPath()[0], p);
assert.equal(e.target, testElement);
var path = e.deepPath();
// path includes window only on more recent Shadow DOM implementations
// account for that here.
assert.ok(path.length >= 10);
Expand All @@ -1278,7 +1277,7 @@

rere.addEventListener('test-event', function(e) {
eventHandled++;
assert.equal(e.localTarget, rere);
assert.equal(e.target, rere);
});

p.fire('test-event');
Expand Down Expand Up @@ -1387,14 +1386,15 @@
assert.sameMembers(order, [cb1, cbReentrant, cb2, cb3, cb4]);
});

test.skip('event.path correctly calculated for elements with destination insertion points', function(done) {
test('event.deepPath correctly calculated for elements with destination insertion points', function(done) {
var re = document.createElement('x-reproject');
document.body.appendChild(re);
ShadyDom.flush();
var p = re.root.querySelector('x-project');
var child = document.createElement('p');
child.innerHTML = "hello";
// child will be inserted into p after distributeContent is performed.
re.appendChild(child);
document.body.appendChild(re);
ShadyDom.flush();
child.addEventListener('child-event', function(e){
var path = e.path;
Expand All @@ -1404,6 +1404,7 @@
});
var evt = new CustomEvent('child-event');
child.dispatchEvent(evt);
document.body.removeChild(re);
});

});
Expand Down
Loading

0 comments on commit 2f0a22a

Please sign in to comment.