Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Force transfer of amp-consent element to the FixedLayer #36223

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions extensions/amp-consent/0.1/consent-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ export class ConsentUI {
const {classList} = this.parent_;
classList.add('amp-active');
classList.remove('amp-hidden');
// Add to fixed layer
this.baseInstance_.getViewport().addToFixedLayer(this.parent_);

this.baseInstance_
.getViewport()
.addToFixedLayer(this.parent_, /* forceTransfer */ true);
alanorozco marked this conversation as resolved.
Show resolved Hide resolved

if (this.isCreatedIframe_) {
// show() can be called multiple times, but notificationsUiManager
// ensures that only 1 is shown at a time, so no race condition here
Expand Down
18 changes: 12 additions & 6 deletions extensions/amp-consent/0.1/test/test-consent-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describes.realWin(
let ampdoc;
let consentUI;
let mockInstance;
let mockViewport;
let parent;
let ownersStubs;

Expand All @@ -46,18 +47,17 @@ describes.realWin(
postPrompt.setAttribute('id', 'testPost');
parent.appendChild(postPrompt);
doc.body.appendChild(parent);
mockViewport = {
addToFixedLayer: env.sandbox.spy(),
removeFromFixedLayer: () => {},
};
mockInstance = {
getAmpDoc: () => {
return ampdoc;
},
element: parent,
win,
getViewport: () => {
return {
addToFixedLayer: () => {},
removeFromFixedLayer: () => {},
};
},
getViewport: () => mockViewport,
getVsync: () => {
return {
mutate: (callback) => {
Expand Down Expand Up @@ -106,6 +106,12 @@ describes.realWin(
const consentUI = new ConsentUI(mockInstance, config);
const showIframeSpy = env.sandbox.spy(consentUI, 'showIframe_');
consentUI.show(false);
expect(
mockViewport.addToFixedLayer.withArgs(
mockInstance.element,
/* forceTransfer */ true
)
).to.have.been.calledOnce;
consentUI.iframeReady_.resolve();
return whenCalled(showIframeSpy).then(() => Promise.resolve(consentUI));
};
Expand Down