Skip to content

Commit

Permalink
Allowlist amp-carousel 0.2 goToSlide for email (#37045)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsu committed Nov 30, 2021
1 parent 27e204e commit 8dcbf47
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions extensions/amp-carousel/0.2/amp-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class AmpCarousel extends AMP.BaseElement {
},
ActionTrust_Enum.LOW
);
/** If the element is in an email document, allow its `goToSlide` action. */
this.action_.addToAllowlist('AMP-CAROUSEL', 'goToSlide', ['email']);
}

/** @param {!AmpElement} element */
Expand Down
65 changes: 65 additions & 0 deletions extensions/amp-carousel/0.2/test/test-type-slides.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import '../amp-carousel';
import * as Listen from '#utils/event-helper';
import {ActionService} from '#service/action-impl';
import {ActionTrust_Enum} from '#core/constants/action-constants';
import {CarouselEvents} from '../../../amp-base-carousel/0.1/carousel-events';
import {Services} from '#service';
import {getDetail, listenOncePromise} from '#utils/event-helper';
import {user} from '#utils/log';
import {whenUpgradedToCustomElement} from '#core/dom/amp-element-helpers';

/**
* @fileoverview Some simple tests for amp-carousel. Most of the functionality
Expand Down Expand Up @@ -379,6 +382,68 @@ describes.realWin(
}
expect.fail();
});

it('should be allowlisted in email', async () => {
env.win.document.documentElement.setAttribute('amp4email', '');
const action = new ActionService(env.ampdoc, env.win.document);
env.sandbox.stub(Services, 'actionServiceForDoc').returns(action);
const carousel = await getCarousel({loop: false});
env.sandbox.spy(carousel, 'enqueAction');
env.sandbox.stub(carousel, 'getDefaultActionAlias');
await whenUpgradedToCustomElement(carousel);
await carousel.whenBuilt();

action.execute(
carousel,
'goToSlide',
{},
'source',
'caller',
'event',
ActionTrust_Enum.HIGH
);

expect(carousel.enqueAction).to.be.calledWith(
env.sandbox.match({
actionEventType: '?',
args: {},
caller: 'caller',
event: 'event',
method: 'goToSlide',
node: carousel,
source: 'source',
trust: ActionTrust_Enum.HIGH,
})
);
});
});

describe('toggleAutoplay action', () => {
it('should not be allowlisted in email', async () => {
env.win.document.documentElement.setAttribute('amp4email', '');
const action = new ActionService(env.ampdoc, env.win.document);
env.sandbox.stub(Services, 'actionServiceForDoc').returns(action);
const carousel = await getCarousel({loop: false});
const userErrorStub = env.sandbox.stub(user(), 'error');
env.sandbox.stub(carousel, 'getDefaultActionAlias');
await whenUpgradedToCustomElement(carousel);
await carousel.whenBuilt();

action.execute(
carousel,
'toggleAutoplay',
{},
'source',
'caller',
'event',
ActionTrust_Enum.HIGH
);

expect(userErrorStub).to.be.calledOnce;
expect(userErrorStub.args[0][1]).to.match(
/"AMP-CAROUSEL.toggleAutoplay" is not allowlisted/
);
});
});

describe('layout direction', () => {
Expand Down

0 comments on commit 8dcbf47

Please sign in to comment.