Skip to content

Commit

Permalink
Amp-a4a: detachedCallback destroy creative frame (ampproject#18344)
Browse files Browse the repository at this point in the history
* initial commit

* handle presubmit error
  • Loading branch information
keithwrightbos authored and Enriqe committed Nov 28, 2018
1 parent bfaff25 commit 311452e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extensions/amp-a4a/0.1/amp-a4a.js
Expand Up @@ -1084,6 +1084,12 @@ export class AmpA4A extends AMP.BaseElement {
this.postAdResponseExperimentFeatures = {};
}

/** @override */
detachedCallback() {
super.detachedCallback();
this.destroyFrame(true);
}

/**
* Attempts to remove the current frame and free any associated resources.
* This function will no-op if this ad slot is currently in the process of
Expand Down
12 changes: 12 additions & 0 deletions extensions/amp-a4a/0.1/test/test-amp-a4a.js
Expand Up @@ -410,6 +410,18 @@ describe('amp-a4a', () => {
});
});

it('detachedCallback should destroy FIE and detach frame', () => {
const fieDestroySpy =
sandbox./*OK*/spy(FriendlyIframeEmbed.prototype, 'destroy');
a4a.buildCallback();
a4a.onLayoutMeasure();
return a4a.layoutCallback().then(() => {
a4a.detachedCallback();
expect(fieDestroySpy).to.be.called;
expect(a4aElement.querySelector('iframe')).to.not.be.ok;
});
});

it('for A4A FIE should wait for initial layout', () => {
let iniLoadResolver;
const iniLoadPromise = new Promise(resolve => {
Expand Down

0 comments on commit 311452e

Please sign in to comment.