-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[presentation-api] add several tests for a receiving browsing context #5562
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
[presentation-api] add several tests for a receiving browsing context #5562
Conversation
- Monitoring incoming presentation connections - Closing a PresentationConnection - Terminating a presentation in a receiving browsing context
Notifying @louaybassbouss, @tidoust, and @zqzhang. (Learn how reviewing works.) |
LintPassed |
Firefox (nightly channel)Testing web-platform-tests at revision c236c59 |
Chrome (unstable channel)Testing web-platform-tests at revision c236c59 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tomoyukilabs,
First, thanks a ton for these tests. As usual, reviewing these has proved immensely useful for me as I had to dig into algorithms and wonder about what the spec says (or should say).
I see one issue with termination, and issues due to the use of SHOULD in the spec.
return checkConnectionList(evt.connection, 'connect'); | ||
}; | ||
|
||
let eventNotFired = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what that variable was meant for, but test only sets it, so it can be dropped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but I forgot to remove it. Thanks! I'll drop it in the next update.
connection.terminate(); | ||
|
||
// the following code must not be invoked since the presentation is terminated | ||
stash.send({ type: 'error' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to assume that calling "terminate" will immediately kill the browsing context. I don't think that is true. Scripts may still run at the end of the unload a document algorithm in particular. I do receive the error message when I test this on Chrome and my Chromecast device.
Typically, in a window opened by a script, you may still post a message to the opener after calling window.close()
:
window.close();
window.opener.postMessage('Still there!', '*');
Now, after the call to terminate
, window.closed
should be true (actually, "unload" is not enough, the context should also be "discarded", see w3c/presentation-api#423), so you could write:
if (!window.closed) {
stash.send({ type: 'error' });
}
You could also send an "ok" message if the window is indeed closed, but this time I'm not entirely sure there is a guarantee that the message will reach the stash server before the context gets interrupted for real. That seems to work in practice, but maybe you could write something such as:
stash.send({ type: (window.closed ? 'ok' : 'error') });
}
... and a conditional check on the controller that stops the test immediately on "ok", fails on "error", and admits things are good after 2s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'll change the code into the following:
stash.send({ type: (window.closed ? 'ok' : 'error') });
FYI: As far as I have tested on Firefox Nightly for Android, window.closed
is not set to true
yet as soon as calling "terminate", and it becomes true
when an unload
event is fired. Anyway, I will fix the codes as you mentioned above.
new Promise(resolve => { t.step_timeout(() => { resolve(null); }, 3000); }) | ||
]); | ||
}).then(evt => { | ||
assert_true(!!evt, 'A presentation connection is closed when its controller\'s browsing context is discarded.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note that the Presentation API also has a SHOULD here, which seems to make more sense (it could perhaps take some time for garbage collection to operate, or a user agent might want to hastily stop spending computing resources on a closed context):
[[
When a PresentationConnection object S is discarded (because the document owning it is navigating or is closed) while the presentation connection state of S is connecting or connected, the user agent SHOULD start closing the presentation connection S with wentaway as closeReason and an empty closeMessage.
]]
So failing that particular check is possible in a conforming implementation. And this seems to fail in Chrome, actually (well it fails because of "isTrusted", but if you skip this check, it fails here). From a testing perspective, I guess the best would be to make that check in a separate test flagged as "[Optional]".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll separate it as an optional test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this SHOULD has been changed to MUST in the current spec, I'll cancel the change to "[Optional]".
|
||
const checkEvent = evt => { | ||
assert_true(evt instanceof PresentationConnectionAvailableEvent, 'An event using PresentationConnectionAvailableEvent is fired.'); | ||
assert_true(evt.isTrusted, 'The event is a trusted event.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pinging @mfoltzgoogle in case that is not a known bug: Chrome does not seem to set the "isTrusted" property of the "connectionavailable" event in the receiving browsing context (it is reported as undefined). The test would pass otherwise (same buggy behavior for the "close" event)
return stash.init(); | ||
}).then(() => { | ||
child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*'); | ||
const eventWatcher1 = new EventWatcher(t, connection, 'terminate'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that a conforming implementation may not issue a "terminate" event when the receiving context is the one that calls "terminate", because it is a SHOULD in the Presentation API:
[[
When a receiving user agent is to send a termination confirmation for a presentation P, and that confirmation was received by a controlling user agent, the controlling user agent SHOULD run the following steps
]]
Ideally, that check would be done in a separate test marked as "[Optional]". Or we turn that SHOULD into a MUST in the spec, as I don't understand why it's only a SHOULD for now. I created an issue:
w3c/presentation-api#422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this SHOULD has been changed to MUST, I leave this code as it is.
else if (data.type === 'connect') { | ||
const request = new PresentationRequest(data.url); | ||
request.reconnect(data.id).then(c => { | ||
c.onterminate = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same SHOULD problem as above. There is no real guarantee that a "terminate" signal from the receiving side will not be ignored by the controlling user agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same change from SHOULD to MUST as above.
}).then(evt => { | ||
connection = evt.connection; | ||
watchClose = new EventWatcher(t, connection, 'close'); | ||
return watchClose.wait_for('close'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same SHOULD problem as mentioned elsewhere, see related open issue w3c/presentation-api#423
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same change from SHOULD to MUST as mentioned below.
Regarding the isTrusted property on |
These tests are now available on w3c-test.org |
I have fixed several bugs except ones related to w3c/presentation-api#422 and w3c/presentation-api#423. |
Codecov Report
@@ Coverage Diff @@
## master #5562 +/- ##
=========================================
Coverage ? 87.22%
=========================================
Files ? 24
Lines ? 2418
Branches ? 406
=========================================
Hits ? 2109
Misses ? 239
Partials ? 70 Continue to review full report at Codecov.
|
This PR adds three tests for the following events in a receiving browsing context:
connectionavailable
event fired at PresentationConnectionListclose
event fired at PresentationConnectionNow I'm wondering whether a test for
connect
event at a receiving side is needed or not, since state of a presentation connection at the receiving side is already set toconnected
when it is added to the set of presentation controllers.This change is