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

Race between render-start & no-content #4720

Merged
merged 8 commits into from Aug 29, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Aug 26, 2016

Listen to bootstrap-loaded if ad server does not support render-start. Listen to no-content as before.
Listen to both render-start and no-content if ad server supports render-start. Remove listener for the other after receiving one message.
Tests added.
#4022

This is part of the work that improve ad loading behavior #4022

@zhouyx
Copy link
Contributor Author

zhouyx commented Aug 26, 2016

PTAL

@@ -120,21 +116,52 @@ export class AmpAdApiHandler {
}
}, this.is3p_, this.is3p_));

// Install API that listen to ad response
if (waitForRenderStart.indexOf(this.baseInstance_.adType) >= 0) {
this.isSupportRenderStart_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

seems it can be a local variable?

@zhouyx zhouyx force-pushed the race-render-start-no-content branch from 966d24e to aae1360 Compare August 26, 2016 21:23
@zhouyx
Copy link
Contributor Author

zhouyx commented Aug 26, 2016

fixed. Also change the behavior of listenForOnce function to return a promise

@@ -172,6 +175,7 @@ export class AmpAd3PImpl extends AMP.BaseElement {
// We always need the bootstrap.
preloadBootstrap(this.win);
const type = this.element.getAttribute('type');
this.adType = type;
Copy link
Contributor

Choose a reason for hiding this comment

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

We could actually move this up into #buildCallback

unlistenList[i]();
}
msgReceived = true;
resolve({message, data, source, origin});
Copy link
Contributor

Choose a reason for hiding this comment

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

does data already contains message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right! use data.type instead

@zhouyx
Copy link
Contributor Author

zhouyx commented Aug 26, 2016

fixed, PTAL

@@ -13,5 +13,6 @@ npm-debug.log
.tm_properties
.settings
build-system/runner/TESTS-TestSuites.xml
.vscode/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm, how is .gitignore not ignoring itself

resolve();
});
IframeHelper.listenForOncePromise(testIframe,
['no-msg', 'send-intersections', 'send-intersections'])
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, having the duplicated message is not a valid use case. the behavior is in-deterministic and we don't really care, so there's no need to have a test to protect it.

* @param {boolean=} opt_is3P
* @return {!Promise}
* @return {!Promise<Object{data, source, origin}>}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the right syntax is: {!Promise<!{data, source, origin}>}

@lannka
Copy link
Contributor

lannka commented Aug 27, 2016

LGTM

@lannka lannka added LGTM and removed NEEDS REVIEW labels Aug 27, 2016
@zhouyx zhouyx merged commit ce74719 into ampproject:master Aug 29, 2016
@zhouyx zhouyx deleted the race-render-start-no-content branch August 29, 2016 16:42
// If support render-start, create a race between render-start no-content
this.adResponsePromise_ = listenForOncePromise(this.iframe_,
['render-start', 'no-content'], this.is3p_).then(info => {
if (info.data.type == 'render-start') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is data guaranteed to be an object?

Copy link
Contributor Author

@zhouyx zhouyx Aug 29, 2016

Choose a reason for hiding this comment

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

https://github.com/ampproject/amphtml/blob/master/src/iframe-helper.js#L212

Here datamust have a data.type to get the correct listener

also https://github.com/ampproject/amphtml/blob/master/src/iframe-helper.js#L271
here we use data.sentinel directly.

mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
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