Skip to content

Commit

Permalink
Add test for Pym.js messages for height and width
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Nov 23, 2019
1 parent 15eb198 commit 6e6ae24
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
58 changes: 58 additions & 0 deletions extensions/amp-iframe/0.1/test/test-amp-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,64 @@ describes.realWin(
ActionTrust.HIGH
);
});

it('should listen for Pym.js height event', function*() {
const ampIframe = createAmpIframe(env, {
src: iframeSrc,
sandbox: 'allow-scripts allow-same-origin',
width: 200,
height: 200,
resizable: '',
});
yield waitForAmpIframeLayoutPromise(doc, ampIframe);
const impl = ampIframe.implementation_;
return new Promise((resolve, unusedReject) => {
impl.updateSize_ = (height, width) => {
resolve({height, width});
};
const iframe = ampIframe.querySelector('iframe');
iframe.contentWindow.postMessage(
{
sentinel: 'amp-test',
type: 'requestPymjsHeight',
height: 234,
},
'*'
);
}).then(res => {
expect(res.height).to.equal(234);
expect(res.width).to.be.an('undefined');
});
});

it('should listen for Pym.js width event', function*() {
const ampIframe = createAmpIframe(env, {
src: iframeSrc,
sandbox: 'allow-scripts allow-same-origin',
width: 200,
height: 200,
resizable: '',
});
yield waitForAmpIframeLayoutPromise(doc, ampIframe);
const impl = ampIframe.implementation_;
return new Promise((resolve, unusedReject) => {
impl.updateSize_ = (height, width) => {
resolve({height, width});
};
const iframe = ampIframe.querySelector('iframe');
iframe.contentWindow.postMessage(
{
sentinel: 'amp-test',
type: 'requestPymjsWidth',
width: 345,
},
'*'
);
}).then(res => {
expect(res.width).to.equal(345);
expect(res.height).to.be.an('undefined');
});
});
});

describe('pause/resume', () => {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/served/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
sentinel: sentinel,
type: 'send-embed-state',
}, '*');
} else if (event.data.type === 'requestPymjsHeight') {
var msg = [ 'pym', 'height', event.data.height ].join( 'xPYMx' );
getAmpWindow(sentinel)./*OK*/postMessage( msg, '*');
} else if (event.data.type === 'requestPymjsWidth') {
var msg = [ 'pym', 'width', event.data.height ].join( 'xPYMx' );
getAmpWindow(sentinel)./*OK*/postMessage( msg, '*');
}
}
});
Expand Down

0 comments on commit 6e6ae24

Please sign in to comment.