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

Fix for document salvageable state #20837

Merged
merged 1 commit into from May 28, 2018

Conversation

@gterzian
Copy link
Member

gterzian commented May 20, 2018

I noticed a bug where if the document was un-salavageable due to the presence of beforeunload listeners, this could be overwritten if there were no listeners for unload. This could also have happened if an iframe of the document had no listeners while the parent did.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented May 20, 2018

Heads up! This PR modifies the following files:

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 20, 2018

Opened new PR for upstreamable changes.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 534965b to 7f36eb8 May 20, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 20, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 7f36eb8 to d2109ef May 20, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 20, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@cbrewster cbrewster assigned cbrewster and unassigned emilio May 20, 2018
Copy link
Member

cbrewster left a comment

Ah, woops! This change looks correct.
Is there a way to avoid all of the setTimeouts in the test? Sometimes it can lead to intermittent tests with timing issues.

Also, please mention people in a comment rather than the PR body otherwise the mentioned people will get a notification when bors creates a merge commit.

}), 1000);
}

onload = function() {setTimeout(function() {

This comment has been minimized.

@cbrewster

cbrewster May 20, 2018

Member

Why do we need a setTimeout here?

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from d2109ef to 2e55ad3 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 2e55ad3 to 25819b1 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 25819b1 to 6e73f24 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 6e73f24 to 2cda5fc May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian
Copy link
Member Author

gterzian commented May 21, 2018

Ok, I was able to remove a few unnecessary timeouts. I also added an empty iframe to make sure the fact that the iframe is salvageable doesn't overwrite the unsalvageable state of the parent...

I noticed, as you mentioned, that the timeouts can be somewhat unreliable, so I've set the one timeout that makes the test pass or fail to a wide margin so that even if the server is slowed down and it takes longer to discard the unsalvageable document, this would not result in an intermittent failure.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 2cda5fc to 32cf8ef May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

Copy link
Member

cbrewster left a comment

Tidy:

Checking files for tidiness...
./components/script/dom/document.rs:1668: trailing whitespace
onload = function() {
var iframe = document.getElementsByTagName("iframe")[0]
onload = null;
iframe.src="004-1.html?" + Math.random();

This comment has been minimized.

@cbrewster

cbrewster May 21, 2018

Member

Is there any reason for Math.random()?

onload = function() {
if (!parent.loaded) {
parent.loaded = true;
location="004-2.html?" + Math.random();

This comment has been minimized.

@cbrewster

cbrewster May 21, 2018

Member

Is there any reason for Math.random()?

This comment has been minimized.

@gterzian

gterzian May 21, 2018

Author Member

I think it is to prevent caching.

onbeforeunload = function() {
onbeforeunload = null;
parent.beforeunload_fired = true;
setTimeout(function() {

This comment has been minimized.

@cbrewster

cbrewster May 21, 2018

Member

Can we just call a function on parent here that then calls t.done()?

This comment has been minimized.

@gterzian

gterzian May 21, 2018

Author Member

yes, that is done there https://github.com/servo/servo/pull/20837/files#diff-98df125a78b53a9905ea2e52eb1362d5R4
because here the idea is that the timeout never fires because the document is not salvageable hence will be discarded, and the timeout along with it.
(by the way, I didn't quite "invent" this structure myself, I basically copied the same test applied to unload from https://github.com/servo/servo/blob/affcf81ce6156f0796b5e3a4332780135bbd51dd/tests/wpt/web-platform-tests/html/browsers/browsing-the-web/unloading-documents/unload/007.html. Actually I started with the test, then realized it was impossible to make it pass...)

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 32cf8ef to 42590a2 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 42590a2 to 67c0575 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 67c0575 to 255eb13 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

if !document.salvageable() {
self.salvageable.set(false);
}
if !can_unload {

This comment has been minimized.

@gterzian

gterzian May 21, 2018

Author Member

ended up changing this, because previously I would check document.salvageable() before calling document.prompt_to_unload(true). Who thought checking booleans could be so hard...

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 2663889 to a00051a May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from a00051a to 6385fae May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 6385fae to 42bbe73 May 21, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 21, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian mentioned this pull request May 22, 2018
0 of 6 tasks complete
@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 42bbe73 to fb0639d May 22, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 22, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian
Copy link
Member Author

gterzian commented May 22, 2018

@cbrewster made a change to the tests, which doesn't change the logic, but hopefully takes care of two flies in one hit in the light of whatwg/html#3646 (comment)

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from fb0639d to 29087f4 May 22, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 22, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@gterzian gterzian force-pushed the gterzian:tests_for_has_event_listener branch from 29087f4 to 57c0d82 May 22, 2018
@servo-wpt-sync
Copy link
Collaborator

servo-wpt-sync commented May 22, 2018

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at jdm/web-platform-tests#60.

@cbrewster
Copy link
Member

cbrewster commented May 28, 2018

Thanks!
@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented May 28, 2018

📌 Commit 57c0d82 has been approved by cbrewster

@bors-servo
Copy link
Contributor

bors-servo commented May 28, 2018

Testing commit 57c0d82 with merge 2439ab0...

bors-servo added a commit that referenced this pull request May 28, 2018
…ster

Fix for document salvageable state

I noticed a bug where if the document was un-salavageable due to the presence of `beforeunload` listeners, this could be overwritten if there were no listeners for `unload`. This could also have happened if an iframe of the document had no listeners while the parent did.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20837)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 28, 2018

@bors-servo bors-servo merged commit 57c0d82 into servo:master May 28, 2018
3 of 4 checks passed
3 of 4 checks passed
Taskcluster (pull_request) TaskGroup: Exception
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@gterzian gterzian deleted the gterzian:tests_for_has_event_listener branch May 29, 2018
jdm added a commit to web-platform-tests/wpt that referenced this pull request Jun 7, 2018
@gterzian gterzian mentioned this pull request Jun 13, 2018
0 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.