Skip to content

Commit

Permalink
Added test and finalized message attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
glevitzky committed Nov 3, 2017
1 parent 1fc6c08 commit eb53987
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
Expand Up @@ -1224,27 +1224,28 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
if (!this.win.opener || !/\?.*dfpdeb/.test(this.win.location.href)) {
return;
}
const slotId = this.element.getAttribute('data-slot');
const payload = dict({
'gutData': JSON.stringify(dict({
'events': [{
'timestamp': new Date().getTime(),
'slotid': this.element.getAttribute('data-slot'),
'slotid': slotId,
'messageId': 4,
}],
'slots': [{
'contentUrl': this.getCachedAdUrl() || '',
'id': this.element.getAttribute('data-slot'),
'leafAdUnitName': this.element.getAttribute('data-slot'),
'domId': '',
'lineItemId': this.lineitemId_ || '102158080',
'creativeId': this.creativeId_ || '88085470120',
'id': slotId,
'leafAdUnitName': slotId,
'domId': 'gpt_unit_' + slotId + '_' +
this.element.getAttribute('data-amp-slot-index'),
'lineItemId': this.lineitemId_,
'creativeId': this.creativeId_,
}],
})),
'userAgent': navigator.userAgent,
'referrer': this.win.location.href,
'messageType': 'LOAD',
});
console.log(payload);
this.win.opener.postMessage(payload, '*');
}
}
Expand Down
Expand Up @@ -1064,6 +1064,56 @@ describes.realWin('amp-ad-network-doubleclick-impl', realWinConfig, env => {
['https://partner.googleadservices.com', SAFEFRAME_ORIGIN]);
});
});

describe('Troubleshoot', () => {
beforeEach(() => {
element = doc.createElement('amp-ad');
element.setAttribute('type', 'doubleclick');
element.setAttribute('data-slot', 'slotId');
element.setAttribute('data-amp-slot-index', '0');
doc.body.appendChild(element);
impl = new AmpAdNetworkDoubleclickImpl(element);
impl.lineitemId_ = '123';
impl.creativeId_ = '456';
});

afterEach(() => {
doc.body.removeChild(element);
});

it('should emit post message', () => {
const slotId = 'slotId'
env.win = {
location: {
href: 'http://localhost:8000/foo?dfpdeb',
},
opener: {
postMessage: payload => {
expect(payload).to.be.ok;
expect(payload.userAgent).to.be.ok;
expect(payload.referrer).to.be.ok;
expect(payload.messageType).to.equal('LOAD');

const gutData = JSON.parse(payload.gutData);
expect(gutData).to.be.ok;
expect(gutData.events[0].timestamp).to.be.ok;
expect(gutData.events[0].slotid).to.equal(slotId);
expect(gutData.events[0].messageId).to.equal(4);

expect(gutData.slots[0].contentUrl).to.equal('');
expect(gutData.slots[0].id).to.equal(slotId);
expect(gutData.slots[0].leafAdUnitName).to.equal(slotId);
expect(gutData.slots[0].domId).to.equal(
'gpt_unit_' + slotId + '_0');
expect(gutData.slots[0].lineItemId).to.equal('123');
expect(gutData.slots[0].creativeId).to.equal('456');
},
},
};
impl.win = env.win;
impl.postTroubleshootMessage_();
});
});
});


Expand Down

0 comments on commit eb53987

Please sign in to comment.