Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerender amp-video poster image. #25456

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions extensions/amp-video/0.1/amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ class AmpVideo extends AMP.BaseElement {
* @override
*/
firstAttachedCallback() {
// Only allow prerender if video sources are cached on CDN. Set this value
// in `firstAttachedCallback` since `buildCallback` is too late and the
// element children may not be available in the constructor.
this.prerenderAllowed_ = this.hasAnyCachedSources_();
// Only allow prerender if video sources are cached on CDN, or if video has
// a poster image. Set this value in `firstAttachedCallback` since
// `buildCallback` is too late and the element children may not be available
// in the constructor.
const posterAttr = this.element.getAttribute('poster');
this.prerenderAllowed_ = !!posterAttr || this.hasAnyCachedSources_();
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
24 changes: 24 additions & 0 deletions extensions/amp-video/0.1/test/test-amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ describes.realWin(
const v = await getVideo({
src: 'video.mp4',
'object-fit': 'cover',
layout: 'responsive',
});
const video = v.querySelector('video');
expect(video.style.objectFit).to.equal('cover');
Expand All @@ -491,6 +492,7 @@ describes.realWin(
const v = await getVideo({
src: 'video.mp4',
'object-fit': 'foo 80%',
layout: 'responsive',
});
const video = v.querySelector('video');
expect(video.style.objectFit).to.be.empty;
Expand All @@ -500,6 +502,7 @@ describes.realWin(
const v = await getVideo({
src: 'video.mp4',
'object-position': '20% 80%',
layout: 'responsive',
});
const video = v.querySelector('video');
expect(video.style.objectPosition).to.equal('20% 80%');
Expand All @@ -509,6 +512,7 @@ describes.realWin(
const v = await getVideo({
src: 'video.mp4',
'object-position': 'url("example.com")',
layout: 'responsive',
});
const video = v.querySelector('video');
expect(video.style.objectPosition).to.be.empty;
Expand Down Expand Up @@ -794,6 +798,26 @@ describes.realWin(
});
});

describe('should prerender poster image', () => {
it('with just cached src', () => {
return new Promise(resolve => {
getVideo(
{
src: 'https://example.com/video.mp4',
poster: 'https://example.com/poster.jpg',
width: 160,
height: 90,
},
null,
element => {
expect(element.implementation_.prerenderAllowed()).to.be.true;
resolve();
}
);
});
});
});

describe.skip('before visible', () => {
it('should move cached src to source during prerender', async () => {
const v = await getVideo({
Expand Down