Skip to content

Fix for document salvageable state - #20837

Merged
bors-servo merged 1 commit into
servo:masterfrom
gterzian:tests_for_has_event_listener
May 28, 2018
Merged

bors-servo merged 1 commit into
servo:masterfrom
gterzian:tests_for_has_event_listener

Conversation

@gterzian

@gterzian gterzian commented May 20, 2018 •

Copy link
Copy Markdown
Member

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
Copy Markdown

Heads up! This PR modifies the following files:

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 20, 2018
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 534965b to 7f36eb8 Compare May 20, 2018 15:56
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 7f36eb8 to d2109ef Compare May 20, 2018 15:58
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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

@cbrewster cbrewster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need a setTimeout here?

@gterzian
gterzian force-pushed the tests_for_has_event_listener branch from d2109ef to 2e55ad3 Compare May 21, 2018 02:18
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 2e55ad3 to 25819b1 Compare May 21, 2018 02:21
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 25819b1 to 6e73f24 Compare May 21, 2018 02:24
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 6e73f24 to 2cda5fc Compare May 21, 2018 02:30
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

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

@gterzian

gterzian commented May 21, 2018 •

Copy link
Copy Markdown
Member Author

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 tests_for_has_event_listener branch from 2cda5fc to 32cf8ef Compare May 21, 2018 02:37
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

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

@cbrewster cbrewster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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();

@cbrewster cbrewster May 21, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any reason for Math.random()?

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any reason for Math.random()?

@gterzian gterzian May 21, 2018 •

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.

I think it is to prevent caching.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@gterzian gterzian May 21, 2018 •

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.

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 tests_for_has_event_listener branch from 32cf8ef to 42590a2 Compare May 21, 2018 04:20
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 42590a2 to 67c0575 Compare May 21, 2018 04:21
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 67c0575 to 255eb13 Compare May 21, 2018 04:22
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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 {

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.

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 tests_for_has_event_listener branch from 2663889 to a00051a Compare May 21, 2018 04:47
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from a00051a to 6385fae Compare May 21, 2018 06:18
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 6385fae to 42bbe73 Compare May 21, 2018 07:09
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 42bbe73 to fb0639d Compare May 22, 2018 09:59
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

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

@gterzian

gterzian commented May 22, 2018 •

Copy link
Copy Markdown
Member Author

@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 tests_for_has_event_listener branch from fb0639d to 29087f4 Compare May 22, 2018 10:08
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

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 tests_for_has_event_listener branch from 29087f4 to 57c0d82 Compare May 22, 2018 10:12
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

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

@cbrewster

Copy link
Copy Markdown
Contributor

Thanks!
@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 57c0d82 has been approved by cbrewster

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 28, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 57c0d82 with merge 2439ab0...

bors-servo pushed 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
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: cbrewster
Pushing 2439ab0 to master...

@bors-servo
bors-servo merged commit 57c0d82 into servo:master May 28, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label May 28, 2018
@gterzian
gterzian deleted the tests_for_has_event_listener branch May 29, 2018 02:59
jdm pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 7, 2018
@gterzian gterzian mentioned this pull request Jun 13, 2018
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants