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

Enables 'msz' and 'psz' parameters on doubleclick ad requests. #21159

Merged
merged 16 commits into from Mar 7, 2019

Conversation

glevitzky
Copy link
Contributor

@glevitzky glevitzky commented Feb 27, 2019

Enables 'msz' and 'psz' parameters on doubleclick ad requests.

These parameters, respectively, for a given element, represent the element's size, and the element's parent container's size. These parameters are used in determining flexible ad slot size options. Height is always -1 as height expansion is forbidden in AMP.

@glevitzky glevitzky changed the title Enables 'psz' and 'msz' parameters on doubleclick ad requests. Enables 'msz' and 'psz' parameters on doubleclick ad requests. Feb 27, 2019
return element;
}

it('should return the fixed the width for FIXED layout', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

extraneous "the"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

export function getContainerWidth(win, element) {
let el = element;
let maxDepth = 100;
// Find the first ancestor with a fixed size
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: period at end of sentence

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.

case Layout.FLUID:
// The above layouts determine the width of the element by the
// containing element, or by CSS max-width property.
const maxWidth = parseInt(computedStyle(win, el).maxWidth, 10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is calling computedStyle ok here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no strict rule against it, and I don't think this loop will iterate more than twice in practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked to @glevitzky offline. We already have code calculating computedStyle from every nested parent here. It would be great if we can leverage the logic there later. But I'm fine with us calling computedStyle here if the getContainerWidth is only called once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, we call the method twice, but the second call checks at most one element (different from any of the elements checked in the first call).

// The above layouts determine the width of the element by the
// containing element, or by CSS max-width property.
const maxWidth = parseInt(computedStyle(win, el).maxWidth, 10);
if (maxWidth || maxWidth == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

===? Or is the crazy behavior of == 0 needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If !maxWidth, then maxWidth is NaN, and NaN != 0.

case Layout.FLEX_ITEM:
return 0;
default:
// If no layout is provided, we must use getComputedStyle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this valid AMP? If not, can we complain somehow?

Copy link
Contributor Author

@glevitzky glevitzky Mar 1, 2019

Choose a reason for hiding this comment

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

I think this is valid. I'm thinking of a case of an <amp-ad> being wrapped in a simple <div>, or by <body>.

/** @const @enum{string} */
const FLEXIBLE_AD_SLOTS_BRANCHES = {
EXPERIMENT: '21063174',
CONTROL: '21063173',
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: don't we normally list control first?

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.

`${getContainerWidth(this.win, this.element)}x-1` : null,
'psz': this.sendFlexibleAdSlotParams_ ?
`${getContainerWidth(this.win, this.element.parentElement)}x-1` :
null,
Copy link
Contributor

Choose a reason for hiding this comment

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

comment here that we're intentionally sending ${width}x-1 because height can't change?

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.

return impl.getAdUrl().then(url => {
expect(url).to.not.match(/(\?|&)msz=[0-9]+x-1(&|$)/);
expect(url).to.not.match(/(\?|&)psz=[0-9]+x-1(&|$)/);
expect(url).to.not.match(/(=|%2C)2106317(3|4)(%2C|&|$)/);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and above, can we assert "no msz and psz params" instead of "no valid params"?

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.

return impl.getAdUrl().then(url => {
expect(url).to.match(/(\?|&)msz=[0-9]+x-1(&|$)/);
expect(url).to.match(/(\?|&)psz=[0-9]+x-1(&|$)/);
expect(url).to.match(/(=|%2C)21063174(%2C|&|$)/);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there really no utility function for pulling out a url param?

[optional] would you be up for writing one?

Copy link
Contributor Author

@glevitzky glevitzky Mar 1, 2019

Choose a reason for hiding this comment

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

It would only save us so much, since we'd still have to verify the pulled out param. I can look into it in a follow up, though.

@keithwrightbos keithwrightbos merged commit 1d53d2e into ampproject:master Mar 7, 2019
@glevitzky glevitzky deleted the psz branch March 7, 2019 16:26
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
…oject#21159)

* Initial

* stash

* Remove unrelated test page.

* Move function to utils and some minor clenaup.

* Added tests.

* Fixes & test updates.

* Fix

* Experiment logic.

* Test regexp fix, lint fix, dep-check fix, and check-type fix.

* Remove stray comment.

* Minor tweak + testing non-presence of eid.

* Use assertElement over cast.

* Fix test desc + minor test regexp fix.

* Use url encoded commas in regexp.

* PR feedback.

* Refactor so that getContainerWidth is executed at most once per request.
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Mar 22, 2019
…oject#21159)

* Initial

* stash

* Remove unrelated test page.

* Move function to utils and some minor clenaup.

* Added tests.

* Fixes & test updates.

* Fix

* Experiment logic.

* Test regexp fix, lint fix, dep-check fix, and check-type fix.

* Remove stray comment.

* Minor tweak + testing non-presence of eid.

* Use assertElement over cast.

* Fix test desc + minor test regexp fix.

* Use url encoded commas in regexp.

* PR feedback.

* Refactor so that getContainerWidth is executed at most once per request.
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

6 participants