Skip to content

Test how document.fullscreenElement changes when removing elements#6302

Closed
foolip wants to merge 2 commits into
masterfrom
fullscreen-removing-steps
Closed

Test how document.fullscreenElement changes when removing elements#6302
foolip wants to merge 2 commits into
masterfrom
fullscreen-removing-steps

Conversation

@foolip

@foolip foolip commented Jun 21, 2017

Copy link
Copy Markdown
Member

Apart from the event.target tests, these pass in Firefox Nightly.

document.onfullscreenchange = t.step_func_done(function(event)
{
assert_equals(document.fullscreenElement, first);
// When the asynchronous steps of "exit fullscreen" ran, only

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@upsuper, I wrote this tests because this test began failing when working on the top layer rewrite in Chromium, and it turns out that Firefox already behaves this way.

Do the comments here match the reason it behaves like this in Firefox? I think it's quite surprising, but to fix it would require one of these:

  • Making "exit fullscreen" keep track of which element it is exiting for, and doing nothing if it's no longer the fullscreen element in the async part.
  • Change the removing steps so that they don't invoke "exit fullscreen" at all, but instead just resize if necessary and enqueue an event.
  • Others?

WDYT?

// /first/ was in the top layer, and thus we exited fully.
assert_equals(document.fullscreenElement, null);
assert_equals(event.target, document);
assert_equals(event.target, first);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is also rather odd, because first is the fullscreen element when the async steps run, that's where the event will be fired, even though it's only the fullscreen element for a brief period.

@ghost

ghost commented Jun 21, 2017

Copy link
Copy Markdown

View the complete job log.

Firefox (nightly)

Testing web-platform-tests at revision bd32ed1
Using browser at version BuildID 20170612100241; SourceStamp 27cad9749cddf68e11fdd4e5d73dad84a8f8cf23
Starting 10 test iterations
No tests run.

@ghost

ghost commented Jun 21, 2017

Copy link
Copy Markdown

View the complete job log.

Sauce (safari)

Testing web-platform-tests at revision bd32ed1
Using browser at version 10.0
Starting 10 test iterations
No tests run.

@ghost

ghost commented Jun 21, 2017

Copy link
Copy Markdown

View the complete job log.

Chrome (unstable)

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

@ghost

ghost commented Jun 21, 2017

Copy link
Copy Markdown

View the complete job log.

Sauce (MicrosoftEdge)

Testing web-platform-tests at revision bd32ed1
Using browser at version 14.14393
Starting 10 test iterations
No tests run.

first.remove();
// Both /first/ and /last/ were removed from the top layer and
// thus the fullscreen element synchronously becomes null.
assert_equals(document.fullscreenElement, null);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@upsuper, I noticed this test is still wrong. If the fullscreen element is null, as it is in Firefox Nightly here, then no fullscreenchange event should be fired, because of "If doc’s fullscreen element is null, then resolve promise with undefined and terminate these steps."

So we need to change either the spec of Firefox in some way. In your implementation, what is it that causes the event to be fired?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So in Firefox, when any of the fullscreen element is unbound from the tree, we exit fullscreen and queue events synchronously, then force the window to restore asynchronously (as it needs to be).

I guess either way is fine to me, although I'm not very motivated to change code here, because removing fullscreen element should be considered as an error case, so the bottom line is we should exit fullscreen safely, and I don't think we should expect any legitimate content to rely on behavior here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@upsuper, by "exit fullscreen ... synchronously", do you mean that some of the steps of https://fullscreen.spec.whatwg.org/#exit-fullscreen are run? In https://gist.github.com/foolip/47ee26fa3d6463f5ca3edc364d915beb it looks like you fully exit fullscreen even if you were in nested fullscreen, while Chrome (before recent changes), Safari and Edge do not. (@aliams @jernoble in case I'm testing it wrong.)

I could live with what the spec already says, but that would require a change to Gecko. Changing the spec to say something more similar to Gecko would also be fine. Since this isn't a terribly important issue, if nobody feels strongly, then maybe leave the spec alone and make these test changes. @upsuper?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By doing that synchronously, I mean we reset the document state to non-fullscreen immediately (fullscreenElement becomes null, and :fullscreen matches nothing) without waiting for the window to change.

I'm fine with the spec way, but as I mentioned before, since I don't think this is important, I'm not going to change that anytime soonish... If someone submits patch for that, we may accept. But I myself don't have much time working on this recently.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, I think I understand how to spec something similar then. I'll decide what to do before landing the top layer change in Chromium, which is what will affect these tests, or comment back here if I decide on no change. Can you review so the spec and tests come into agreement first?

@upsuper

upsuper commented Jun 30, 2017

Copy link
Copy Markdown
Member

So I had a brief look at the test change (actually I intended to do the review), and it seems to me this test change doesn't match what the spec says currently? IIUC, fullscreenElement can never be changed synchronously per spec.

I guess when you move or remove fullscreen elements, it is probably more sensible to synchronously change fullscreenElement. That may make the spec slightly more complicated, though.

Anyway, we should have test and spec match each other. It seems to me the test change itself isn't consistent at the moment.

@foolip

foolip commented Jul 3, 2017

Copy link
Copy Markdown
Member Author

IIUC, fullscreenElement can never be changed synchronously per spec.

This is actually a bit broken, I think. https://fullscreen.spec.whatwg.org/#unfullscreen-an-element is the only thing that removes fullscreen elements from top layer, which means that they would remain in top layer after being removed from the document.

In HTML things are different. Around https://html.spec.whatwg.org/#pending-dialog-stack we have the "If at any time a dialog element is removed from a Document" which removes dialog elements from the "pending dialog stack", and there's also "When an element is removed from the pending dialog stack, it must be removed from the top layer." This means that dialog elements are synchronously removed from the top layer when removed from the document. whatwg/html#2341 collapses this, making it more explicit.

I think that fullscreen should behave the same way, or rather that there should be one step somewhere that removes any elements from the top layer if it's removed from the document.

@upsuper, what do you think about that, does that match what's actually implemented in Gecko, or do you have different behavior for fullscreen and dialog?

@upsuper

upsuper commented Jul 4, 2017

Copy link
Copy Markdown
Member

Gecko still doesn't have dialog support yet, unfortunately...

Yeah, I think it probably makes more sense to remove element from top layer when it is removed from the document. That should match how fullscreen is implemented in Gecko.

@foolip

foolip commented Jul 7, 2017

Copy link
Copy Markdown
Member Author

Sounds good. I don't know exactly how that'd end up looking spec-side, but I'll make an attempt, and then come back and make sure these tests match.

@foolip

foolip commented Jul 7, 2017

Copy link
Copy Markdown
Member Author

(In August, I'm gone for the rest of July)

@foolip

foolip commented Sep 5, 2017

Copy link
Copy Markdown
Member Author

OK, whatwg/html#2341 is now merged, which should make all of this a bit easier.

@foolip

foolip commented Sep 28, 2017

Copy link
Copy Markdown
Member Author

w3c-test:mirror

@foolip

foolip commented Sep 28, 2017

Copy link
Copy Markdown
Member Author

@sideshowbarker, something has gone wrong with http://w3c-test.org/submissions/6302/, can you investigate?

@ghost

ghost commented Sep 28, 2017

Copy link
Copy Markdown

Build PASSED

Started: 2018-01-31 05:45:24
Finished: 2018-01-31 05:49:59

View more information about this build on:

@foolip

foolip commented Sep 28, 2017

Copy link
Copy Markdown
Member Author

OK, this is now ready for review. @upsuper, can you take another look?

@upsuper upsuper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the delay. (GitHub is really not good at reminding you about what needs to be done...)

It mostly looks fine to me. There is some weirdness for the nested fullscreen case, which, I guess, probably worth some tweaking to the spec.

assert_equals(event.target, document);
// When the asynchronous steps of "exit fullscreen" ran, only
// /first/ was in the top layer, and thus we exited fully.
assert_equals(document.fullscreenElement, null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This sounds a bit counter-intuitive.

Assuming we have three fullscreen elements in the stack, e.g. #first, #second, and #third. Given the description here, I guess when #third is removed from the document, document.fullscreenElement becomes #second synchronously, and then an "exit fullscreen" is triggered from that removal and #second is popped out, and document.fullscreenElement becomes #first? Is my understanding correct?

If it is really hard to handle it intuitively, I'd rather we just fully exit fullscreen when the fullscreen element is removed, which would at least look more consistent and less surprising.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, because we collect documents to unfullscreen twice, and one time is after the original fullscreen element has been removed from top layer, removing an element will effectively exit two levels of fullscreen. This is quite related to whatwg/fullscreen#105.

I think that either fully exiting fullscreen or only calling "collect documents to unfullscreen" once are the most reasonable choices here. WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess I've forgot some of the context of this PR. IIUC, we are discussing about updating the document state (e.g. fullscreen element, selector matching, etc.) synchronously in the removing steps of element, and that isn't part of the current spec at the moment?

If that's correct, I guess doing "fully exit fullscreen" doesn't help either, because that relies on "exit fullscreen a document" as well. It is also not clear to me how having "collect documents to unfullscreen" called once helps either. That function only collects document, and you may still end up popping an additional element in the document (because the original fullscreen element has been remove synchronously). Actually, how would this all ensure that we dispatch the fullscreen event for the element removal...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That wasn't the original context, but yes, now this is supposed to match whatwg/fullscreen#102 which you've already approved :)

What I would suggest here is to merge this and whatwg/fullscreen#102, and then to treat whatwg/fullscreen#105 as a regression from that in need of fixing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right that "fully exit fullscreen" wouldn't fix whatwg/fullscreen#105.

The way that "collect documents to unfullscreen" could help is if we record both what documents to exit and what the fullscreen element is. If, after actually exiting fullscreen, that's no longer the fullscreen element, then we can still fire the fullscreenchange event at the document. Some finesse required, but I have something of this rough shape in an experimental patch for Blink. I'd like to handle it separately though, this set of test changes is mostly independent.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What I would suggest here is to merge this and whatwg/fullscreen#102, and then to treat whatwg/fullscreen#105 as a regression from that in need of fixing.

This makes sense, but... it doesn't really match the spec after whatwg/fullscreen#102 due to whatwg/fullscreen#105. It seems many of the fullscreenchange listener in the tests wouldn't be triggered with whatwg/fullscreen#102.

I guess... we can live with this mismatch between test and spec as far as we can resolve whatwg/fullscreen#105 soonish?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I need to resolve whatwg/fullscreen#105 before I can land the top layer changes at all in Chromium.

Let me walk through the tests to see which ones don't match the spec now but will soon, and I'll rename those to tentative. Writing tests to match the somewhat broken state doesn't seem meaningful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many test which expect to receive fullscreenchange event after removing the last fullscreen element probably don't match the spec. And I agree that writing tests to match a broken spec state doesn't make much sense.

@foolip

foolip commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

GitHub is really not good at reminding you about what needs to be done...

I've had to spend rather a lot of effort on my GitHub filters. Most importantly, I tag anything to mention@noreply.github.com specially.

@foolip

foolip commented Oct 16, 2017

Copy link
Copy Markdown
Member Author

Ping again @upsuper :)

@upsuper

upsuper commented Oct 16, 2017

Copy link
Copy Markdown
Member

Ping again @upsuper :)

Oops, sorry, I somehow missed the reply...

I've had to spend rather a lot of effort on my GitHub filters. Most importantly, I tag anything to mention@noreply.github.com specially.

I have some kind of filter for this, and threads I subscribe to and that people mentions me do have special handling... What I really miss is the needinfo flag on Bugzilla which would put a small red number on top of all pages, until you explicitly clear the flag...

Also test that dialog.remove() doesn't do any of the things one might
reasonably expect, to match the current spec and what's implemented.

Tests for:
whatwg/fullscreen#102
whatwg/html#3064

Drive-by: t.add_cleanup(() => document.exitFullscreen())
@foolip foolip force-pushed the fullscreen-removing-steps branch from 459e875 to 3857892 Compare January 31, 2018 05:44
@foolip

foolip commented Jan 31, 2018

Copy link
Copy Markdown
Member Author

I've rebased and pushed a commit to match the latest spec changes. @upsuper, review of both would be much appreciated.

@dtapuska

Copy link
Copy Markdown
Contributor

@foolip I believe this pull request can be closed as most of these changes landed in 1829a42

@wpt-pr-bot wpt-pr-bot requested review from annevk, domenic, sideshowbarker and zcorpan and removed request for ayg and jernoble August 22, 2018 20:32
@foolip foolip closed this Aug 29, 2018
@foolip foolip deleted the fullscreen-removing-steps branch August 29, 2018 13:13
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.

4 participants