diff --git a/lib/legacy/class.html b/lib/legacy/class.html index 377146df72..026fa98eef 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -350,11 +350,6 @@ 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 d17a151342..b2082f292a 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -408,14 +408,14 @@ 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 34d94097eb..30c4804eeb 100644 --- a/test/unit/behaviors.html +++ b/test/unit/behaviors.html @@ -22,6 +22,12 @@ + + + + @@ -309,6 +360,31 @@ + + + + + + + + + + + + + + + + + diff --git a/test/unit/strict-template-policy.html b/test/unit/strict-template-policy.html index 0dfb32915d..f55e5a3750 100644 --- a/test/unit/strict-template-policy.html +++ b/test/unit/strict-template-policy.html @@ -157,11 +157,27 @@ ' `' + - '' + - ''; + ''; }, /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 @@ 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 @@ ' `' + - '' + - ''; + ''; }, /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 @@ }); 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() {