Skip to content

Commit

Permalink
Use ad type _ping_ in test-amp-ad to avoid external request (#3748)
Browse files Browse the repository at this point in the history
  • Loading branch information
muxin committed Jun 23, 2016
1 parent d6ed64b commit f8dcebc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
6 changes: 4 additions & 2 deletions 3p/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ window.draw3p = function(opt_configCallback, opt_allowed3pTypes,
updateVisibilityState(window);
nonSensitiveDataPostMessage('render-start');
} catch (e) {
lightweightErrorReport(e);
throw e;
if (!window.context.mode.test) {
lightweightErrorReport(e);
throw e;
}
}
};

Expand Down
43 changes: 17 additions & 26 deletions extensions/amp-ad/0.1/test/test-amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ function tests(name) {
return getAd({
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
src: 'https://testsrc',
'data-aax_size': '300x250',
'data-aax_pubname': 'test123',
'data-aax_src': '302',
// Test precedence
'data-width': '6666',
}, 'https://schema.org').then(ad => {
Expand All @@ -63,12 +60,11 @@ function tests(name) {
const fragment = url.substr(url.indexOf('#') + 1);
const data = JSON.parse(fragment);

expect(data.type).to.equal('a9');
expect(data.type).to.equal('_ping_');
expect(data.src).to.equal('https://testsrc');
expect(data.width).to.equal(300);
expect(data.height).to.equal(250);
expect(data._context.canonicalUrl).to.equal('https://schema.org/');
expect(data.aax_size).to.equal('300x250');

const doc = iframe.ownerDocument;
let fetches = doc.querySelectorAll(
Expand All @@ -77,14 +73,12 @@ function tests(name) {
fetches = doc.querySelectorAll(
'link[rel=preload]');
}
expect(fetches).to.have.length(3);
expect(fetches).to.have.length(2);
expect(fetches[0].href).to.equal(
'http://ads.localhost:' + location.port +
'/base/dist.3p/current/frame.max.html');
expect(fetches[1].href).to.equal(
'https://3p.ampproject.net/$internalRuntimeVersion$/f.js');
expect(fetches[2].href).to.equal(
'https://c.amazon-adsystem.com/aax2/assoc.js');
const preconnects = doc.querySelectorAll(
'link[rel=preconnect]');
expect(preconnects[preconnects.length - 1].href).to.equal(
Expand All @@ -103,7 +97,7 @@ function tests(name) {
return getAd({
width: 100,
height: 100,
type: 'a9',
type: '_ping_',
src: 'testsrc',
resizable: '',
}, 'https://schema.org').then(element => {
Expand Down Expand Up @@ -140,7 +134,7 @@ function tests(name) {
return getAd({
width: 100,
height: 100,
type: 'a9',
type: '_ping_',
src: 'testsrc',
resizable: '',
}, 'https://schema.org').then(element => {
Expand Down Expand Up @@ -173,7 +167,7 @@ function tests(name) {
return getAd({
width: 100,
height: 100,
type: 'a9',
type: '_ping_',
src: 'testsrc',
resizable: '',
}, 'https://schema.org').then(element => {
Expand All @@ -190,7 +184,7 @@ function tests(name) {
return getAd({
width: 100,
height: 100,
type: 'a9',
type: '_ping_',
src: 'testsrc',
resizable: '',
}, 'https://schema.org').then(element => {
Expand All @@ -207,7 +201,7 @@ function tests(name) {
return expect(getAd({
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
}, null)).to.be.rejectedWith(/canonical/);
});

Expand All @@ -222,7 +216,7 @@ function tests(name) {
return expect(getAd({
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', function(ad) {
ad.style.position = 'fixed';
Expand All @@ -234,7 +228,7 @@ function tests(name) {
return expect(getAd({
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', function(ad) {
const s = document.createElement('style');
Expand All @@ -250,7 +244,7 @@ function tests(name) {
return expect(getAd({
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', function(ad) {
const lightbox = document.createElement('amp-lightbox');
Expand All @@ -268,7 +262,7 @@ function tests(name) {
return getAd({
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', ad => {
const fallback = document.createElement('div');
Expand All @@ -290,7 +284,7 @@ function tests(name) {
return getAd({
width: 300,
height: 750,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', ad => {
return ad;
Expand Down Expand Up @@ -318,7 +312,7 @@ function tests(name) {
return getAd({
width: 300,
height: 750,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', ad => {
const placeholder = document.createElement('div');
Expand All @@ -345,7 +339,7 @@ function tests(name) {
return getAd({
width: 300,
height: 750,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', ad => {
const placeholder = document.createElement('div');
Expand Down Expand Up @@ -373,7 +367,7 @@ function tests(name) {
return getAd({
width: 300,
height: 750,
type: 'a9',
type: '_ping_',
src: 'testsrc',
}, 'https://schema.org', ad => {
const placeholder = document.createElement('div');
Expand Down Expand Up @@ -403,11 +397,8 @@ function tests(name) {
const attributes = {
width: 300,
height: 250,
type: 'a9',
type: '_ping_',
src: 'https://testsrc',
'data-aax_size': '300x250',
'data-aax_pubname': 'test123',
'data-aax_src': '302',
// Test precedence
'data-width': '6666',
};
Expand Down

0 comments on commit f8dcebc

Please sign in to comment.