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

Adding integration for AMPHTML ads rendered on AMP page (A4A) #19698

Merged
merged 4 commits into from Dec 7, 2018
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
63 changes: 63 additions & 0 deletions build-system/amp4test.js
Expand Up @@ -148,3 +148,66 @@ app.use('/request-bank/:bid/teardown/', (req, res) => {
log('SERVER-LOG [TEARDOWN]');
res.end();
});

/**
* Serves a fake ad for test-amp-ad-fake.js
*/
app.get('/a4a/:bid', (req, res) => {
const sourceOrigin = req.query['__amp_source_origin'];
if (sourceOrigin) {
res.setHeader('AMP-Access-Control-Allow-Source-Origin', sourceOrigin);
}
const {bid} = req.params;
res.send(`
<!doctype html><html amp4ads><head><meta charset=utf-8><meta content=width=device-width,minimum-scale=1,initial-scale=1 name=viewport><script async src=https://cdn.ampproject.org/amp4ads-v0.js></script><script async custom-element=amp-accordion src=https://cdn.ampproject.org/v0/amp-accordion-0.1.js></script><script async custom-element=amp-analytics src=https://cdn.ampproject.org/v0/amp-analytics-0.1.js></script><script async custom-element=amp-anim src=https://cdn.ampproject.org/v0/amp-anim-0.1.js></script><script async custom-element=amp-audio src=https://cdn.ampproject.org/v0/amp-audio-0.1.js></script><script async custom-element=amp-carousel src=https://cdn.ampproject.org/v0/amp-carousel-0.1.js></script><script async custom-element=amp-fit-text src=https://cdn.ampproject.org/v0/amp-fit-text-0.1.js></script><script async custom-element=amp-font src=https://cdn.ampproject.org/v0/amp-font-0.1.js></script><script async custom-element=amp-form src=https://cdn.ampproject.org/v0/amp-form-0.1.js></script><script async custom-element=amp-social-share src=https://cdn.ampproject.org/v0/amp-social-share-0.1.js></script><style amp-custom>body {
background-color: #f4f4f4;
}
</style><style amp4ads-boilerplate>body{visibility:hidden}</style></head>
<body>
<a href=https://ampbyexample.com target=_blank>
<amp-img alt="AMP Ad" height=250 src=//localhost:9876/amp4test/request-bank/${bid}/deposit/image width=300></amp-img>
</a>
<amp-pixel src="//localhost:9876/amp4test/request-bank/${bid}/deposit/pixel/foo?cid=CLIENT_ID(a)"></amp-pixel>
<amp-analytics>
<script type="application/json">
{
"requests": {
"pageview": "//localhost:9876/amp4test/request-bank/${bid}/deposit/analytics/bar"
},
"triggers": {
"pageview": {
"on": "visible",
"request": "pageview",
"extraUrlParams": {
"title": "\${title}",
"ampdocUrl": "\${ampdocUrl}",
"canonicalUrl": "\${canonicalUrl}",
"cid": "\${clientId(a)}",
"img": "\${htmlAttr(amp-img,src)}",
"adNavTiming": "\${adNavTiming(requestStart,requestStart)}",
"adNavType": "\${adNavType}",
"adRedirectCount": "\${adRedirectCount}"
}
}
}
}
</script>
</amp-analytics>
<script amp-ad-metadata type=application/json>
{
"ampRuntimeUtf16CharOffsets" : [ 134, 1129 ],
"customElementExtensions" : [
"amp-analytics"
],
"extensions" : [
{
"custom-element" : "amp-analytics",
"src" : "https://cdn.ampproject.org/v0/amp-analytics-0.1.js"
}
]
}
</script>
</body>
</html>
`);
});
1 change: 1 addition & 0 deletions build-system/tasks/presubmit-checks.js
Expand Up @@ -868,6 +868,7 @@ const forbiddenTermsSrcInclusive = {
'ads/_a4a-config.js',
'build-system/app.js',
'build-system/app-index/template.js',
'build-system/amp4test.js',
'dist.3p/current/integration.js',
'extensions/amp-iframe/0.1/amp-iframe.js',
'src/config.js',
Expand Down
63 changes: 63 additions & 0 deletions test/integration/test-amp-ad-fake.js
@@ -0,0 +1,63 @@
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {RequestBank} from '../../testing/test-helper';
import {parseQueryString} from '../../src/url';

describe.configure().skipIfPropertiesObfuscated().run('A4A', function() {
this.timeout(15000);

describes.integration('AMPHTML ads rendered on AMP page', {
body: `
<amp-ad width="300" height="400"
id="i-amphtml-demo-id"
type="fake"
src="/amp4test/a4a/${RequestBank.getBrowserId()}">
<div placeholder>Loading...</div>
<div fallback>Could not display the fake ad :(</div>
</amp-ad>
`,
extensions: ['amp-ad'],
}, () => {
it('should layout amp-img, amp-pixel, amp-analytics', () => {
// See amp4test.js for creative content
return Promise.all([
RequestBank.withdraw('image'),
RequestBank.withdraw('pixel'),
RequestBank.withdraw('analytics'),
]).then(reqs => {
const imageReq = reqs[0];
const pixelReq = reqs[1];
const analyticsReq = reqs[2];
expect(imageReq.url).to.equal('/');
expect(pixelReq.url).to.equal('/foo?cid=');
expect(analyticsReq.url).to.match(/^\/bar\?/);
const queries =
parseQueryString(analyticsReq.url.substr('/bar'.length));
expect(queries).to.include({
title: 'AMP TEST', // ${title},
cid: '', // ${clientId(a)}
adNavTiming: '0', // ${adNavTiming(requestStart,requestStart)}
adNavType: '0', // ${adNavType}
adRedirectCount: '0', // ${adRedirectCount}
});
expect(queries['ampdocUrl']).to.contain('http://localhost:9876/amp4test/compose-doc?');
expect(queries['canonicalUrl']).to.equal('http://nonblocking.io/');
expect(queries['img']).to.contain('/deposit/image'); // ${htmlAttr(amp-img,src)}
});
});
});
});
4 changes: 4 additions & 0 deletions testing/test-helper.js
Expand Up @@ -149,6 +149,10 @@ const REQUEST_URL = '//localhost:9876/amp4test/request-bank/' + browserId;
*/
export class RequestBank {

static getBrowserId() {
return browserId;
}

/**
* Returns the URL for depositing a request.
*
Expand Down