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

Test moving <script>s between documents #5911

Closed
wants to merge 5 commits into from

Conversation

domenic
Copy link
Member

@domenic domenic commented May 12, 2017

This follows the changes in whatwg/html#2673, but also tests the issue at whatwg/html#2137 in favor of the current spec.

@w3c-bots
Copy link

w3c-bots commented May 12, 2017

View the complete job log.

Firefox (nightly)

Testing web-platform-tests at revision 65891e2
Using browser at version BuildID 20170519133342; SourceStamp 8e98dab5054dd093a37ba20c62cf0523e484cfbd
Starting 10 test iterations
All results were stable

All results

1 test ran
/html/semantics/scripting-1/the-script-element/moving-between-documents.html
Subtest Results Messages
OK
text/javascript: moving to another document during parsing, inline script PASS
text/javascript: moving to another document during parsing, external script PASS
text/javascript: moving to another Window's document during fetching FAIL assert_unreached: onerror Reached unreachable code
text/javascript: moving to a document where scripting is disabled during fetching FAIL assert_unreached: onerror Reached unreachable code
module: moving to another document during parsing, inline script PASS
module: moving to another document during parsing, external script PASS
module: moving to another Window's document during fetching PASS
module: moving to a document where scripting is disabled during fetching PASS

@w3c-bots
Copy link

w3c-bots commented May 12, 2017

View the complete job log.

Chrome (unstable)

Testing web-platform-tests at revision 4a26457
Using browser at version 60.0.3100.0 dev
Starting 10 test iterations
All results were stable

All results

1 test ran
/html/semantics/scripting-1/the-script-element/moving-between-documents.html
Subtest Results Messages
OK
text/javascript: moving to another document during parsing, inline script FAIL assert_equals: The script must not have executed in this window expected (undefined) undefined but got (boolean) true
text/javascript: moving to another document during parsing, external script PASS
text/javascript: moving to another Window's document during fetching FAIL assert_unreached: onload Reached unreachable code
text/javascript: moving to a document where scripting is disabled during fetching FAIL assert_unreached: onload Reached unreachable code
module: moving to another document during parsing, inline script PASS
module: moving to another document during parsing, external script FAIL assert_unreached: onload Reached unreachable code
module: moving to another Window's document during fetching PASS
module: moving to a document where scripting is disabled during fetching PASS

@domenic
Copy link
Member Author

domenic commented May 12, 2017

Test result summary for classic scripts, with blank cells meaning browsers match the proposed spec:

Test case EdgeHTML Blink + WebKit Gecko
Moving to another document during parsing, inline script executes executes
Moving to another document during parsing, external script onload + executes
Moving to another Window's document during fetching onload + executes onerror (but does not execute)
Moving to a document where scripting is disabled during fetching onload + executes onerror (but does not execute)

For module scripts, Edge interestingly starts failing the "Moving to a document where scripting is disabled during fetching" case (via onload + executes), but passing the first one.

iframe.contentDocument.close();

assert_false(window.didExecute, "The script must not have executed in this window");
assert_equals(iframe.contentWindow.didExecute, undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the script tested ("s1") is not executed, the test fails on Chromium, because didExecute is false (not undefined).
iframe.contentWindow.didExecute is set to false at Line 32 and is reset to undefined when document.write() is called on Firefox (but not on Chromium) at Line 33.

Minimized case:

<body>
<script>
    const iframe = document.createElement("iframe");
    iframe.onload = () => {
      iframe.contentWindow.didExecute = false;
      iframe.contentDocument.write("<div>");
      console.log(iframe.contentWindow.didExecute);
    };
    document.body.appendChild(iframe);
</script>
</body>

console log: undefined on Firefox and false on Chromium.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, because of the implicit document.open() in document.write(), OK. I've uploaded a patch that just uses undefined vs. true instead of false vs. true which should fix this. Please take a look :)

@domenic domenic force-pushed the scripts-between-documents branch from 861e061 to 0e5ba75 Compare May 20, 2017 00:00
@w3c-bots
Copy link

w3c-bots commented May 20, 2017

View the complete job log.

Sauce (safari)

Testing web-platform-tests at revision 65891e2
Using browser at version 10.0
Starting 10 test iterations
All results were stable

All results

1 test ran
/html/semantics/scripting-1/the-script-element/moving-between-documents.html
Subtest Results Messages
TIMEOUT
text/javascript: moving to another document during parsing, inline script FAIL assert_equals: The script must not have executed in this window expected (undefined) undefined but got (boolean) true
text/javascript: moving to another document during parsing, external script FAIL assert_equals: The script must not have executed in this window expected (undefined) undefined but got (boolean) true
text/javascript: moving to another Window's document during fetching PASS
text/javascript: moving to a document where scripting is disabled during fetching PASS
module: moving to another document during parsing, inline script PASS
module: moving to another document during parsing, external script FAIL assert_unreached: onload Reached unreachable code
module: moving to another Window's document during fetching PASS
module: moving to a document where scripting is disabled during fetching PASS

@w3c-bots
Copy link

w3c-bots commented May 20, 2017

View the complete job log.

Sauce (MicrosoftEdge)

Testing web-platform-tests at revision 4a26457
Using browser at version 14.14393
Starting 10 test iterations

Unstable results

Test Subtest Results Messages
/html/semantics/scripting-1/the-script-element/moving-between-documents.html OK: 9/10, TIMEOUT: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html text/javascript: moving to another document during parsing, inline script FAIL: 9/10, MISSING: 1/10 assert_equals: The script must not have executed in this window expected (undefined) undefined but got (boolean) true
/html/semantics/scripting-1/the-script-element/moving-between-documents.html text/javascript: moving to another document during parsing, external script PASS: 9/10, MISSING: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html text/javascript: moving to another Window's document during fetching PASS: 9/10, MISSING: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html text/javascript: moving to a document where scripting is disabled during fetching PASS: 9/10, MISSING: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html module: moving to another document during parsing, inline script PASS: 9/10, MISSING: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html module: moving to another document during parsing, external script PASS: 9/10, MISSING: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html module: moving to another Window's document during fetching PASS: 9/10, MISSING: 1/10
/html/semantics/scripting-1/the-script-element/moving-between-documents.html module: moving to a document where scripting is disabled during fetching FAIL: 9/10, MISSING: 1/10 assert_unreached: onload Reached unreachable code

All results

1 test ran
/html/semantics/scripting-1/the-script-element/moving-between-documents.html
Subtest Results Messages
OK: 9/10, TIMEOUT: 1/10
text/javascript: moving to another document during parsing, inline script FAIL: 9/10, MISSING: 1/10 assert_equals: The script must not have executed in this window expected (undefined) undefined but got (boolean) true
text/javascript: moving to another document during parsing, external script PASS: 9/10, MISSING: 1/10
text/javascript: moving to another Window's document during fetching PASS: 9/10, MISSING: 1/10
text/javascript: moving to a document where scripting is disabled during fetching PASS: 9/10, MISSING: 1/10
module: moving to another document during parsing, inline script PASS: 9/10, MISSING: 1/10
module: moving to another document during parsing, external script PASS: 9/10, MISSING: 1/10
module: moving to another Window's document during fetching PASS: 9/10, MISSING: 1/10
module: moving to a document where scripting is disabled during fetching FAIL: 9/10, MISSING: 1/10 assert_unreached: onload Reached unreachable code

for (const type of ["text/javascript", "module"]) {
async_test(t => {
t.add_cleanup(() => {
window.didExecute = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also make this remove the iframe? (Same below.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to do so, but why?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it's fine either way. Just seems a little cleaner to only have the results.

assert_equals(iframe.contentWindow.didExecute, undefined,
"The script must not have executed in the iframe window");
t.done();
}, 3000);
Copy link
Member

Choose a reason for hiding this comment

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

Why a timeout here? Since the parser inserts the script element, wouldn't it simply block on it loading if a user agent doesn't implement the spec?

Copy link
Member

Choose a reason for hiding this comment

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

That's also why the belated onload/onerror handlers seem problematic. They probably need to be in the markup, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

They should probably be before setting s.src, it's true.

assert_equals(window.didExecute, undefined, "The script must not have executed in this window");
t.done();
}, 3000);
}, `${type}: moving to a document where scripting is disabled during fetching`);
Copy link
Member

Choose a reason for hiding this comment

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

I think using srcdoc with sandbox might be better or good as an alternative test, since it seems likely browsers would check "browsing-context connected" and not just "connected" (and in fact this is what Chrome, Edge, and Safari seem to do).

Copy link
Member Author

Choose a reason for hiding this comment

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

The definition of scripting-is-disabled means scripting is disabled for browsing-context-less nodes.

There's a separate question as to whether the prepare-a-script algorithm should be using connected vs. BC connected for fetching, but I'd rather keep that separate...

Anyway, happy to also test sandboxed iframes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, on second thought, I'm unsure why we'd have such a test since it would always involve creating a new window (and thus settings object). srcdoc="" does not avoid that, as far as I can tell. So it'd be the same as other iframe tests.

If you disagree I'm happy for your to push an additional test showing me what you mean.

@w3c-bots
Copy link

w3c-bots commented Feb 20, 2018

Build PASSED

Started: 2018-02-21 20:54:30
Finished: 2018-02-21 21:03:12

Failing Jobs

  • safari:11.0

View more information about this build on:

Turns out the timeout is needed at least a bit
aarongable pushed a commit to chromium/chromium that referenced this pull request Oct 10, 2019
Intent to deprecate and remove:
https://groups.google.com/a/chromium.org/d/topic/blink-dev/KyB2mwOmjrk/discussion

This CL also removes crash tests that require executing scripts
moved between documents.
Code paths related to scripts moved between documents will be
covered by e.g.
web-platform-tests/wpt#5911

Bug: 721914
Change-Id: I6acb7182c4a62accd5e5285adb6a77a2cd891465
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1843508
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704503}
@gsnedders gsnedders closed this Jan 24, 2020
@gsnedders gsnedders deleted the scripts-between-documents branch January 24, 2020 18:07
@gsnedders gsnedders restored the scripts-between-documents branch January 24, 2020 18:40
@Hexcles Hexcles reopened this Jan 24, 2020
@domenic
Copy link
Member Author

domenic commented Apr 22, 2020

Superceded by #19632

@domenic domenic closed this Apr 22, 2020
@domenic domenic deleted the scripts-between-documents branch April 22, 2020 03:17
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.

7 participants