-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
data: URL tests #6890
data: URL tests #6890
Conversation
This initial commit contains tests for base64 (and makes sure they're shared with data: URL-specific tests to follow. |
fetch/data-urls/README.md
Outdated
@@ -0,0 +1,11 @@ | |||
== data: URLs == | |||
|
|||
`resources/data-urls.json` contains `data:` URL tests. The tests are encoded as a JSON array. Each value in the array is an array of two are three values. The first value describes the input, the second value describes the expected MIME type, null if the input is expected to fail somehow, or the empty string if the expected value is `text/plain;charset=US-ASCII`. The third value, if present, describes the expected body as an array of integers representing bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two or three?
7fd5ded
to
bc79c1a
Compare
Build PASSEDStarted: 2018-01-30 18:19:36 View more information about this build on: |
["data:;charset=\"x\",X", | ||
"text/plain;charset=\"x\"", | ||
[88]], | ||
["data:;CHARSET=\"X\",X", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this would be the place to test the questions in whatwg/fetch#579 (comment)? Or are such tests already here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, a little above this one. Line 163, 166, and various tests around those too.
"text/plain;charset=x", | ||
[88]], | ||
["data:;charset= x,X", | ||
"text/plain;charset=x", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pass condition should change to preserve the space before the lowercase x.
["data:;charset= x,X", | ||
"text/plain;charset=x", | ||
[88]], | ||
["data:;charset=,X", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty string is not a valid token and hence this will result in text/plain;charset=US-ASCII, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll result in text/plain
. We only use the fallback if MIME type parsing returns missing or failure which it won't for text/plain;charset=
.
55e3b06
to
6509b9c
Compare
@domenic if you have ideas for more comma tests btw let me know. |
w3c-test:mirror |
@domenic I think I addressed all your feedback now. |
[87, 65]], | ||
["data:x;base64;x,WA", | ||
"", | ||
[88]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my tests this should be [87, 65] like the above (doesn't end in ;base64
).
fetch/data-urls/processing.any.js
Outdated
const expectedBody = expectedMimeType !== null ? tests[i][2] : null; | ||
promise_test(t => { | ||
if(expectedMimeType === "") { | ||
expectedMimeType = "text/plain;charset=US-ASCII"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still really, really confusing looking at the test files and seeing empty string as the expected MIME type. It'd be quite nice if this was fixed.
If nothing else, maybe replace it with "__default__"
or something, with a comment at the top explaining the substitution.
["data:%00,%FF", | ||
"", | ||
[255]], | ||
["data:text/html ,X", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given whatwg/fetch#579 (comment) I think this would be a good place to have a negative test for the odd thing that Safari now has, for example with "data:text / html,X", and asserting that it's treated as an invalid MIME type. Should I just push that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
After updating to whatwg/fetch@cedd3f3 I get the following failure with the tests, which don't seem updated yet:
Probably more tests should be added for those spec changes, as just that one seems pretty small. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the promised test, have reviewed the recent additions, and can't think of anything more. Great stuff!
I won't block on the format, but I still am unhappy.
These tests appear to all match the spec, as tested by a JS implementation of it. I still am pretty frustrated that my feedback on using the actual MIME type instead of a magic empty string is not being taken into account in the data file; I find this kind of mix of useful, readable, expected results with magic sentinels that cause a translation layer to be invoked frustrating. I think it would be nice to listen to your test consumers, and optimize for reading and consumption (which happen many times) more than writing (which happens once). But I won't block merging based on that. I just want to issue a final plea. |
If |
It's not as good as the actual result, as it still requires a translation layer, but at least it's less likely to be interpreted as a literal empty string. |
Some additional fun tests might be for things that Unicode-compare equal to base64, but don't ASCII-compare equal to it. I'm not sure what those would be exactly, but if I'd written |
Is having null as a sentinel also a problem, or just changing one string to another string? Are you doing things with the JSON file other than run these tests? Just expanding to the real value would be fine by me I guess, when there are failures the values will already have been expanded so maybe it'll be easier to find in the JSON file then. |
A sentinel for failure (viz. null) makes sense; you actually need to have your test harness behave differently. A sentinel that is just replacing one string with another means you can't do string comparison, or read the expected results in the JSON file, but instead have to transform the test JSON file into an actually-expected-results.json before doing the comparisons.
Well, I'm trying to read it to figure out what the results should be, while debugging test failures. Having to mentally translate empty string to mean... what was the exact string? I guess I'll go look at README.md... is a definite burden. |
I see, that sounds like a real burden worth avoiding. I originally somewhat uncharitably took the argument to be a principled one about minimizing computation in tests, even when it does make things clearer, as I think it did for me as a reviewer. |
@domenic Unicode gets percent-encoded, no? I'm happy to expand the empty string btw, once everything else is in order. |
Confirmed the new EOF cases close that coverage gap. I guess there is no way to trigger Unicode-but-not-ASCII case insensitive equality, you're right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing out the MIME type :)
Unfortunately RFC 2397 has some ambiguities and implementations never really followed it in detail. Tests: web-platform-tests/wpt#6890. Fixes #234.
"text/plain;charset=US-ASCII", | ||
[88]], | ||
["data://test:test/,X", | ||
null], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this test case fail? Is it the URL parser that returns an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This URL loads an X
document in Firefox and Chromium. (It doesn’t in Edge, but Edge appears to reject any data:
URL with a MIME type parsing error.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.
Unfortunately RFC 2397 has some ambiguities and implementations never really followed it in detail. Tests: web-platform-tests/wpt#6890. Fixes #234.
Tests for whatwg/fetch#579.