Skip to content

[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

Merged
merged 4 commits into from
Apr 20, 2017

Conversation

tomoyukilabs
Copy link
Member

@tomoyukilabs tomoyukilabs commented Apr 14, 2017

This PR adds three tests for the following events in a receiving browsing context:

  • a connectionavailable event fired at PresentationConnectionList
  • a close event fired at PresentationConnection
  • terminating a presentation in a receiving browsing context

Now 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 to connected when it is added to the set of presentation controllers.


This change is Reviewable

- Monitoring incoming presentation connections
- Closing a PresentationConnection
- Terminating a presentation in a receiving browsing context
@wpt-pr-bot
Copy link
Collaborator

Notifying @louaybassbouss, @tidoust, and @zqzhang. (Learn how reviewing works.)

@ghost
Copy link

ghost commented Apr 14, 2017

View the complete job log.

Lint

Passed

@ghost
Copy link

ghost commented Apr 14, 2017

View the complete job log.

Firefox (nightly channel)

Testing web-platform-tests at revision c236c59
Using browser at version BuildID 20170418100213; SourceStamp bb38d935d699e0529f9e0bb35578d381026415c4
Starting 10 test iterations
No tests run.

@ghost
Copy link

ghost commented Apr 14, 2017

View the complete job log.

Chrome (unstable channel)

Testing web-platform-tests at revision c236c59
Using browser at version 59.0.3071.9 dev
Starting 10 test iterations
No tests run.

Copy link
Contributor

@tidoust tidoust left a 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;
Copy link
Contributor

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.

Copy link
Member Author

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' });
Copy link
Contributor

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.

Copy link
Member Author

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.');
Copy link
Contributor

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]".

Copy link
Member Author

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.

Copy link
Member Author

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.');
Copy link
Contributor

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');
Copy link
Contributor

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

Copy link
Member Author

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 = () => {
Copy link
Contributor

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.

Copy link
Member Author

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');
Copy link
Contributor

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

Copy link
Member Author

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.

@markafoltz
Copy link
Member

Regarding the isTrusted property on connectionavailable and close, I filed https://bugs.chromium.org/p/chromium/issues/detail?id=711687 to investigate.

@ghost
Copy link

ghost commented Apr 17, 2017

These tests are now available on w3c-test.org

@tomoyukilabs
Copy link
Member Author

I have fixed several bugs except ones related to w3c/presentation-api#422 and w3c/presentation-api#423.

@codecov-io
Copy link

codecov-io commented Apr 20, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@9d1ec68). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d1ec68...7bcf19e. Read the comment docs.

@tidoust tidoust merged commit 9fd6466 into web-platform-tests:master Apr 20, 2017
@tomoyukilabs tomoyukilabs deleted the receiver-connection branch April 24, 2017 07:54
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.

5 participants