Skip to content

Commit

Permalink
Ensure that ios-embed mode is never triggered on a in-a-box iframe (#…
Browse files Browse the repository at this point in the history
…6373)

* Ensure that ios-embed mode is never triggered on a in-a-box iframe

* lints

* lints
  • Loading branch information
Dima Voytenko committed Nov 29, 2016
1 parent 88516c5 commit 058b46f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/service/viewport-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1748,19 +1748,21 @@ const ViewportType = {
* @return {string}
*/
function getViewportType(win, viewer) {
let viewportType = viewer.getParam('viewportType') || ViewportType.NATURAL;
if (platformFor(win).isIos()
&& ((viewportType == ViewportType.NATURAL
&& viewer.isIframed()
// TODO(lannka, #6213): Reimplement binding selection for in-a-box.
&& viewer.isEmbedded())
// Enable iOS Embedded mode so that it's easy to test against a more
// realistic iOS environment.
|| getMode(win).localDev
|| getMode(win).development)) {
viewportType = ViewportType.NATURAL_IOS_EMBED;
}
dev().fine(TAG_, '- viewportType:', viewportType);
const viewportType = viewer.getParam('viewportType') || ViewportType.NATURAL;
if (!platformFor(win).isIos() || viewportType != ViewportType.NATURAL) {
return viewportType;
}
// Enable iOS Embedded mode so that it's easy to test against a more
// realistic iOS environment w/o an iframe.
if (!viewer.isIframed()
&& (getMode(win).localDev || getMode(win).development)) {
return ViewportType.NATURAL_IOS_EMBED;
}
// Override to ios-embed for iframe-viewer mode.
// TODO(lannka, #6213): Reimplement binding selection for in-a-box.
if (viewer.isIframed() && viewer.isEmbedded()) {
return ViewportType.NATURAL_IOS_EMBED;
}
return viewportType;
}

Expand Down
23 changes: 23 additions & 0 deletions test/functional/test-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
stringifyViewportMeta,
updateViewportMetaString,
} from '../../src/service/viewport-impl';
import {getMode} from '../../src/mode';
import {getStyle} from '../../src/style';
import {installPlatformService} from '../../src/service/platform-impl';
import {installTimerService} from '../../src/service/timer-impl';
Expand Down Expand Up @@ -1699,5 +1700,27 @@ describe('createViewport', () => {
expect(viewport.binding_).to
.be.instanceof(ViewportBindingNatural_);
});

it('should bind to "iOS embed" when not iframed but in dev mode', () => {
const ampDoc = installDocService(win, true).getAmpDoc();
getMode(win).development = true;
const viewer = installViewerServiceForDoc(ampDoc);
sandbox.stub(viewer, 'isIframed', () => false);
sandbox.stub(viewer, 'isEmbedded', () => false);
const viewport = installViewportServiceForDoc(ampDoc);
expect(viewport.binding_).to
.be.instanceof(ViewportBindingNaturalIosEmbed_);
});

it('should NOT bind to "iOS embed" when in dev mode, but iframed', () => {
const ampDoc = installDocService(win, true).getAmpDoc();
getMode(win).development = true;
const viewer = installViewerServiceForDoc(ampDoc);
sandbox.stub(viewer, 'isIframed', () => true);
sandbox.stub(viewer, 'isEmbedded', () => false);
const viewport = installViewportServiceForDoc(ampDoc);
expect(viewport.binding_).to
.be.instanceof(ViewportBindingNatural_);
});
});
});

0 comments on commit 058b46f

Please sign in to comment.