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

Do not initiate amp-ad Fast Fetch if height/width of slot is 0 #7498

Merged
merged 6 commits into from Feb 13, 2017
Merged

Do not initiate amp-ad Fast Fetch if height/width of slot is 0 #7498

merged 6 commits into from Feb 13, 2017

Conversation

keithwrightbos
Copy link
Contributor

See #7491

Copy link

@tdrl tdrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. I think we should split out test cases, though.

@@ -404,10 +404,16 @@ export class AmpA4A extends AMP.BaseElement {
// onLayoutMeasure gets called multiple times.
return;
}
this.layoutMeasureExecuted_ = true;
const slotRect = this.getIntersectionElementLayoutBox();
if (slotRect.height == 0 || slotRect.width == 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be an explicit check for display:none here? Or is that subsumed by the dimension checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied over the method the scheduler is using to decide whether to call layoutCallback to ensure parity with Delayed Fetch (see https://github.com/ampproject/amphtml/blob/master/src/service/resource.js#L614)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe the thing to do is to call isDisplayed directly, rather than duplicating the code? Also, I worry that that logic is special-purpose and isn't intended to cover CSS styling display:none.

it('should not send request if display none', () => {
a4aElement.style.display = 'none';
return fixture.addElement(a4aElement).then(element => {
expect(xhrMock.called).to.be.false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this expect(xhrMock).to.not.be.called?

@@ -709,6 +714,21 @@ describe('amp-a4a', () => {
expect(a4a.onLayoutMeasure.bind(a4a)).to.throw(/fixed/);
});
});
it('does not initial promise chain if display none', () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: initialize?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -139,6 +140,10 @@ describe('amp-a4a', () => {
return ampdocService.getAmpDoc(element);
};
element.isBuilt = () => {return true;};
element.getLayoutBox = () => {
const visible = element.style.display != 'none';
return layoutRectLtwh(0, 0, visible ? 200 : 0, visible ? 50 : 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entangles checking display:none with dimension checks. Can we have separate tests for the different cases? (Just paranoia: I want to be sure that chain is blocked regardless of whether web designer sets styling or dimensions.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@keithwrightbos
Copy link
Contributor Author

@tdrl back to you! Thanks

@tdrl tdrl added the Type: Bug label Feb 13, 2017
'type': 'adsense',
});
element.getAmpDoc = () => {
const ampdocService = ampdocServiceFor(doc.defaultView);
return ampdocService.getAmpDoc(element);
};
element.isBuilt = () => {return true;};
element.getLayoutBox = () => {
const visible = element.style.display != 'none';
return layoutRectLtwh(0, 0, visible ? 200 : 0, visible ? opt_height : 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you still have the same issue here, don't you? If the 'does not initialize promise chain if display none' test passes, you're not sure whether it's because you are detecting display:none or because you're detecting the width == 0. Would it work to just get rid of this override of getLayoutBox and test height, width, and display:none directly, in independent tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the way we're initializing this test, it will fail without explicitly adding getLayoutBox (presumably this is why other getters have been attached to element). Perhaps we need to rework the tests but I would rather not delay this PR.

In any event, I reworked so that rect is passed as optional item but in the end display none was not actually being tested. Instead I reworked to verify behavior with 0 height or width.

xhrMock.onFirstCall().returns(Promise.resolve(mockResponse));
return createAdTestingIframePromise().then(fixture => {
const doc = fixture.doc;
const a4aElement = createA4aElement(doc, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, but there should probably be a separate test that checks width == 0 as well. (Sorry to be a PITA about tests, but it continues to be one of our weak spots. :-( )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@keithwrightbos
Copy link
Contributor Author

@tdrl PTAL

Copy link

@tdrl tdrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lannka lannka merged commit ecee9ac into ampproject:master Feb 13, 2017
@keithwrightbos keithwrightbos deleted the a4a_display_none branch February 13, 2017 20:57
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Feb 14, 2017
…oject#7498)

* add height/width 0 check to onLayoutMeasure

* Re-execute check on later onLayoutMeasure calls

* code cleanup

* PR review

* PR review
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
…oject#7498)

* add height/width 0 check to onLayoutMeasure

* Re-execute check on later onLayoutMeasure calls

* code cleanup

* PR review

* PR review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants