Skip to content

Commit

Permalink
Test layers don't multi-reference children (ampproject#18269)
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell authored and torch2424 committed Oct 10, 2018
1 parent 0ab806d commit f110762
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/service/layers-impl.js
Expand Up @@ -730,7 +730,7 @@ export class LayoutElement {
dev().assert(this.isLayer());
dev().assert(this.contains(child));

// Parents track the children, but not all children are aware of there
// Parents track the children, but not all children are aware of their
// parents. When a child finds its parent, it adds itself to the parent.
// This might lead to a double tracking.
if (!this.children_.includes(child)) {
Expand Down
20 changes: 20 additions & 0 deletions test/functional/test-layers.js
Expand Up @@ -131,6 +131,26 @@ describes.realWin('Layers', {amp: true}, env => {
expect(layer).to.equal(LayoutElement.for(parent));
});

it('does not cause double references in layer tree', () => {
const layers = Services.layersForDoc(root);
const div = createElement();
root.appendChild(div);
layers.add(div);

const layout = LayoutElement.for(div);
const rootLayout = LayoutElement.for(scrollingElement);
expect(layout.getParentLayer()).to.equal(rootLayout);

layout.forgetParentLayer();
expect(layout.getParentLayer()).to.equal(rootLayout);

const spy = sinon.sandbox.spy(div, 'getBoundingClientRect');
rootLayout.dirtyMeasurements();
rootLayout.remeasure();

expect(spy).to.have.callCount(1);
});

describe('inside FIE', () => {
let iframe;
let iframeBody;
Expand Down

0 comments on commit f110762

Please sign in to comment.