diff --git a/extensions/amp-script/0.1/amp-script.js b/extensions/amp-script/0.1/amp-script.js index ddc44b930f670..cf226fc8a7ac4 100644 --- a/extensions/amp-script/0.1/amp-script.js +++ b/extensions/amp-script/0.1/amp-script.js @@ -133,6 +133,21 @@ export class AmpScript extends AMP.BaseElement { }); } + /** + * @override + */ + onLayoutMeasure() { + super.onLayoutMeasure(); + const {width, height} = this.getLayoutBox(); + if (width === 0 && height === 0) { + user().warn( + TAG, + 'Skipped initializing amp-script due to zero width and height.', + this.element + ); + } + } + /** * @param {!AmpScriptService} service * @visibleForTesting diff --git a/extensions/amp-script/0.1/test/unit/test-amp-script.js b/extensions/amp-script/0.1/test/unit/test-amp-script.js index cc768fc62b37d..b0943db5e4e85 100644 --- a/extensions/amp-script/0.1/test/unit/test-amp-script.js +++ b/extensions/amp-script/0.1/test/unit/test-amp-script.js @@ -23,6 +23,7 @@ import { } from '../../amp-script'; import {FakeWindow} from '../../../../../testing/fake-dom'; import {Services} from '../../../../../src/services'; +import {user} from '../../../../../src/log'; describes.fakeWin('AmpScript', {amp: {runtimeOn: false}}, env => { let element; @@ -93,6 +94,19 @@ describes.fakeWin('AmpScript', {amp: {runtimeOn: false}}, env => { expect(service.checkSha384).to.be.called; }); + it('should warn if there is zero width/height', () => { + const warnStub = env.sandbox.stub(user(), 'warn'); + env.sandbox.stub(script, 'getLayoutBox').returns({height: 0, width: 0}); + script.onLayoutMeasure(); + + expect(warnStub).calledWith( + 'amp-script', + 'Skipped initializing amp-script due to zero width and height.', + script.element + ); + expect(warnStub).to.have.callCount(1); + }); + it('should fail on invalid sha384(author_js) for cross-origin src', () => { env.sandbox.stub(env.ampdoc, 'getUrl').returns('https://foo.example/'); element.setAttribute('src', 'https://bar.example/bar.js');