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

♿ Add title to amp-a4a iframe #28835

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions extensions/amp-a4a/0.1/amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ export class AmpA4A extends AMP.BaseElement {
'allowfullscreen': '',
'allowtransparency': '',
'scrolling': 'no',
'title': this.getIframeTitle(),
})
));
this.applyFillContent(this.iframe);
Expand Down Expand Up @@ -1622,6 +1623,7 @@ export class AmpA4A extends AMP.BaseElement {
dict({
'height': this.creativeSize_.height,
'width': this.creativeSize_.width,
'title': this.getIframeTitle(),
})
);

Expand Down Expand Up @@ -2036,6 +2038,14 @@ export class AmpA4A extends AMP.BaseElement {
isVerifiedAmpCreative() {
return this.isVerifiedAmpCreative_;
}

/**
* Returns the amp-ad title attribute or a fallback string.
* @return {string} iframe title attribute
*/
getIframeTitle() {
return this.element.getAttribute('title') || '3rd party ad content';
}
}

/**
Expand Down
57 changes: 57 additions & 0 deletions extensions/amp-a4a/0.1/test/test-amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,63 @@ describe('amp-a4a', () => {
expect(child.getAttribute('height')).to.equal('50');
});

it('should set a default title on the iframe', async () => {
// Make sure there's no signature, so that we go down the 3p iframe path.
delete adResponse.headers['AMP-Fast-Fetch-Signature'];
delete adResponse.headers[AMP_SIGNATURE_HEADER];
adResponse.headers['X-CreativeSize'] = '320x50';
const fixture = await createIframePromise();
setupForAdTesting(fixture);
fetchMock.getOnce(
TEST_URL + '&__amp_source_origin=about%3Asrcdoc',
() => adResponse,
{name: 'ad'}
);
const {doc} = fixture;
const a4aElement = createA4aElement(doc);
a4aElement.setAttribute('width', 480);
a4aElement.setAttribute('height', 75);
a4aElement.setAttribute('type', 'doubleclick');
const a4a = new MockA4AImpl(a4aElement);
doc.body.appendChild(a4aElement);
a4a.buildCallback();
a4a.onLayoutMeasure();
const renderPromise = a4a.layoutCallback();
await renderPromise;
const child = a4aElement.querySelector('iframe[name]');
expect(child).to.be.ok;
expect(child.getAttribute('title')).to.equal('3rd party ad content');
});

it('should use the amp-ad title on the iframe if set', async () => {
// Make sure there's no signature, so that we go down the 3p iframe path.
delete adResponse.headers['AMP-Fast-Fetch-Signature'];
delete adResponse.headers[AMP_SIGNATURE_HEADER];
adResponse.headers['X-CreativeSize'] = '320x50';
const fixture = await createIframePromise();
setupForAdTesting(fixture);
fetchMock.getOnce(
TEST_URL + '&__amp_source_origin=about%3Asrcdoc',
() => adResponse,
{name: 'ad'}
);
const {doc} = fixture;
const a4aElement = createA4aElement(doc);
a4aElement.setAttribute('width', 480);
a4aElement.setAttribute('height', 75);
a4aElement.setAttribute('type', 'doubleclick');
a4aElement.setAttribute('title', 'Custom title');
const a4a = new MockA4AImpl(a4aElement);
doc.body.appendChild(a4aElement);
a4a.buildCallback();
a4a.onLayoutMeasure();
const renderPromise = a4a.layoutCallback();
await renderPromise;
const child = a4aElement.querySelector('iframe[name]');
expect(child).to.be.ok;
expect(child.getAttribute('title')).to.equal('Custom title');
});

describe('#onLayoutMeasure', () => {
it('resumeCallback calls onLayoutMeasure', async () => {
// Force non-FIE
Expand Down