Skip to content

Commit

Permalink
Test layers don't multi-reference children
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Sep 21, 2018
1 parent 542ab96 commit 12e71ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/service/layers-impl.js
Expand Up @@ -721,10 +721,10 @@ 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_.indexOf(child) === -1) {
if (!this.children_.includes(child)) {
this.children_.push(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 12e71ea

Please sign in to comment.