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

Troubleshoot for AMP pages #11920

Merged
merged 15 commits into from Nov 7, 2017
Merged

Conversation

glevitzky
Copy link
Contributor

@glevitzky glevitzky commented Nov 3, 2017

Introduces mechanism for communicating with DFP Troubleshoot. Specifically, this adds a postMessage that is emitted under certain circumstances (window.opener != null and 'dfpdeb' present in page URL), and contains information about the slot.

* Troubleshoot UI.
*/
postTroubleshootMessage_() {
if (!this.win.opener || !/\?.*dfpdeb/.test(this.win.location.href)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Travis seems to have found a case where this.win.location is undefined

@@ -1064,6 +1064,68 @@ describes.realWin('amp-ad-network-doubleclick-impl', realWinConfig, env => {
['https://partner.googleadservices.com', SAFEFRAME_ORIGIN]);
});
});

describe('Troubleshoot', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

More descriptive name?

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. Note that "Troubleshoot" is a feature name.

});

it('should not emit post message', () => {
env.win = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah...the Travis error is because no location/href 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.

Fixed. Thanks.

* @return {?string}
*/
getCachedAdUrl() {
return this.adUrl_;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need this function. If you are only accessing getCachedAdUrl from within the doubleclick fast fetch class, you can just directly use this.adUrl_

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'd need to make adUrl_ protected, which would require a lot more changes. Unless you have a strong objection, I'd rather expose it through a getter function.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah k, idk why I was thinking you could do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't doubleclick impl know the ad url? After all it constructed it when it overrode getAdUrl. You could instead have a local variable that encapsulates the message to be sent (as a typdef) which you would update (e.g. set content url, creative id, line item id, etc). When in doubt, we should try not to clutter that AmpA4A API unless necessary.

},
};
impl.win = env.win;
impl.postTroubleshootMessage_();
Copy link
Contributor

Choose a reason for hiding this comment

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

this test won't catch if opener.postMessage is never called

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.

* @return {?string}
*/
getCachedAdUrl() {
return this.adUrl_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't doubleclick impl know the ad url? After all it constructed it when it overrode getAdUrl. You could instead have a local variable that encapsulates the message to be sent (as a typdef) which you would update (e.g. set content url, creative id, line item id, etc). When in doubt, we should try not to clutter that AmpA4A API unless necessary.

this.creativeId_ = null;

/** @private {?string} */
this.lineitemId_ = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be this.lineItemId_?

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.

* Troubleshoot UI.
*/
postTroubleshootMessage_() {
if (!this.win.opener || !/\?.*dfpdeb/.test(this.win.location.href)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're looking for query string content, you can use this.win.location.search which includes the '?'... Doesn't actually save you much here but better to be explicit. Also, do you want to handle edge cases like foodfpdeb or dfpdebfoo? If so, should this be: /[?|&]dfpdeb=/

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.

};
const postMessageSpy = sandbox.spy(env.win.opener, 'postMessage');
impl.win = env.win;
return impl.postTroubleshootMessage_().then(() =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this visibleForTesting instead of accessing private function

@ampprojectbot ampprojectbot added this to the Pending Triage milestone Nov 6, 2017
@keithwrightbos keithwrightbos merged commit 7c56d6a into ampproject:master Nov 7, 2017
neko-fire pushed a commit to 3qnexx/amphtml that referenced this pull request Nov 17, 2017
* Init.

* stashing changes.

* Cases slotid correctly.

* Added test and finalized message attributes.

* Removing test code.

* Clean up + negative test.

* Added comments.

* Fixed comments and test.

* Fixing presubmit errors.

* Make more obvious what negative test is testing.

* Gathering all Troubleshoot data into single type/object.

* Fixing docstring.

* Moved troubleshootData initializations earlier into constructor.

* Made postTroubleshootMessage public and visible for testing.

* Moving things back to buildCallback.
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
* Init.

* stashing changes.

* Cases slotid correctly.

* Added test and finalized message attributes.

* Removing test code.

* Clean up + negative test.

* Added comments.

* Fixed comments and test.

* Fixing presubmit errors.

* Make more obvious what negative test is testing.

* Gathering all Troubleshoot data into single type/object.

* Fixing docstring.

* Moved troubleshootData initializations earlier into constructor.

* Made postTroubleshootMessage public and visible for testing.

* Moving things back to buildCallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants