diff --git a/lib/legacy/class.html b/lib/legacy/class.html index 377146df..026fa98e 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -350,11 +350,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN Polymer.LegacyElementMixin(HTMLElement)); // decorate klass with registration info klass.is = info.is; - // if user provided template on info, make sure the static _template - // is set so the static template getter uses it - if (info._template !== undefined) { - klass._template = info._template; - } return klass; }; diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index d17a1513..b2082f29 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -408,14 +408,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN static get template() { if (!this.hasOwnProperty(JSCompiler_renameProperty('_template', this))) { this._template = + // Take any template set on the prototype, including null (for legacy + // support, setting in registered callback, etc.) + this.prototype._template !== undefined ? this.prototype._template : // Look in dom-module associated with this element's is getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is) || // Next look for superclass template (call the super impl this // way so that `this` points to the superclass) - Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template || - // Finally, fall back to any _template set on prototype, e.g. - // via registered callback - this.prototype._template; + Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template; } return this._template; } diff --git a/test/unit/behaviors.html b/test/unit/behaviors.html index 34d94097..30c4804e 100644 --- a/test/unit/behaviors.html +++ b/test/unit/behaviors.html @@ -22,6 +22,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN + + + + @@ -309,6 +360,31 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN + + + + + + + + + + + + + + + + + diff --git a/test/unit/strict-template-policy.html b/test/unit/strict-template-policy.html index 0dfb3291..f55e5a37 100644 --- a/test/unit/strict-template-policy.html +++ b/test/unit/strict-template-policy.html @@ -157,11 +157,27 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ' `' + - '' + - ''; + ''; }, /trusted-element re-registered/); - const el = document.querySelector('trusted-element'); - assert.notOk(el && el.shadowRoot && el.shadowRoot.querySelector('#injected')); + const el = document.createElement('trusted-element'); + document.getElementById('target').appendChild(el); + assert.notOk(el.shadowRoot); + assert.notOk(document.getElementById('injected')); + }); + + test('dom-module after registration, again', function() { + assertThrows(function() { + document.getElementById('target').innerHTML = + '' + + ' `' + + ''; + }, /trusted-element re-registered/); + const el = document.createElement('trusted-element'); + document.getElementById('target').appendChild(el); + assert.notOk(el.shadowRoot); + assert.notOk(document.getElementById('injected')); }); test('dom-module before registration', function() { @@ -179,6 +195,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN let el = document.createElement('has-no-template'); document.getElementById('target').appendChild(el); assert.notOk(el.shadowRoot); + assert.notOk(document.getElementById('injected')); }); test('dom-module after registration (legacy)', function() { @@ -188,11 +205,27 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN ' `' + - '' + - ''; + ''; }, /trusted-element-legacy re-registered/); - const el = document.querySelector('trusted-element-legacy'); - assert.notOk(el && el.shadowRoot && el.shadowRoot.querySelector('#injected')); + const el = document.createElement('trusted-element-legacy'); + document.getElementById('target').appendChild(el); + assert.notOk(el.shadowRoot); + assert.notOk(document.getElementById('injected')); + }); + + test('dom-module after registration, again (legacy)', function() { + assertThrows(function() { + document.getElementById('target').innerHTML = + '' + + ' `' + + ''; + }, /trusted-element-legacy re-registered/); + const el = document.createElement('trusted-element-legacy'); + document.getElementById('target').appendChild(el); + assert.notOk(el.shadowRoot); + assert.notOk(document.getElementById('injected')); }); test('dom-module before registration (legacy)', function() { @@ -208,7 +241,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN }); let el = document.createElement('has-no-template-legacy'); document.getElementById('target').appendChild(el); - assert.notOk(document.querySelector('has-no-template-legacy').shadowRoot); + assert.notOk(el.shadowRoot); + assert.notOk(document.getElementById('injected')); }); test('element without explicit template throws', function() {