diff --git a/build-system/amp4test.js b/build-system/amp4test.js
index 3471f9f8945f..103f7d3d1a5b 100644
--- a/build-system/amp4test.js
+++ b/build-system/amp4test.js
@@ -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(`
+
+
+
+
+
+
+
+
+
+
+
+
+`);
+});
diff --git a/build-system/tasks/presubmit-checks.js b/build-system/tasks/presubmit-checks.js
index bbe6f1e21b7b..5741958b42e0 100644
--- a/build-system/tasks/presubmit-checks.js
+++ b/build-system/tasks/presubmit-checks.js
@@ -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',
diff --git a/test/integration/test-amp-ad-fake.js b/test/integration/test-amp-ad-fake.js
new file mode 100644
index 000000000000..e3f2095e6d1e
--- /dev/null
+++ b/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: `
+
+ Loading...
+ Could not display the fake 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)}
+ });
+ });
+ });
+});
diff --git a/testing/test-helper.js b/testing/test-helper.js
index 99d2a5b911dc..6fd6d192b22c 100644
--- a/testing/test-helper.js
+++ b/testing/test-helper.js
@@ -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.
*