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

data: URL tests #6890

Merged
merged 20 commits into from
Jan 31, 2018
Merged

data: URL tests #6890

merged 20 commits into from
Jan 31, 2018

Conversation

annevk
Copy link
Member

@annevk annevk commented Aug 15, 2017

Tests for whatwg/fetch#579.

@annevk
Copy link
Member Author

annevk commented Aug 15, 2017

This initial commit contains tests for base64 (and makes sure they're shared with atob() so any new tests will cover both).

data: URL-specific tests to follow.

@annevk
Copy link
Member Author

annevk commented Aug 15, 2017

@annevk annevk mentioned this pull request Aug 21, 2017
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

two or three?

@w3c-bots
Copy link

w3c-bots commented Sep 18, 2017

Build PASSED

Started: 2018-01-30 18:19:36
Finished: 2018-01-30 18:29:28

View more information about this build on:

["data:;charset=\"x\",X",
"text/plain;charset=\"x\"",
[88]],
["data:;CHARSET=\"X\",X",
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 this would be the place to test the questions in whatwg/fetch#579 (comment)? Or are such tests already here?

Copy link
Member Author

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",
Copy link
Member Author

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",
Copy link
Contributor

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.

Copy link
Member Author

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=.

@annevk
Copy link
Member Author

annevk commented Jan 5, 2018

@domenic if you have ideas for more comma tests btw let me know.

@sideshowbarker
Copy link
Contributor

w3c-test:mirror

@annevk
Copy link
Member Author

annevk commented Jan 7, 2018

@domenic I think I addressed all your feedback now.

domenic
domenic previously requested changes Jan 8, 2018
[87, 65]],
["data:x;base64;x,WA",
"",
[88]],
Copy link
Member

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).

const expectedBody = expectedMimeType !== null ? tests[i][2] : null;
promise_test(t => {
if(expectedMimeType === "") {
expectedMimeType = "text/plain;charset=US-ASCII";
Copy link
Member

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",
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Member

Choose a reason for hiding this comment

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

Done!

@domenic
Copy link
Member

domenic commented Jan 24, 2018

After updating to whatwg/fetch@cedd3f3 I get the following failure with the tests, which don't seem updated yet:

  • data:; base64,WA expected "text/plain", but implementation produced "text/plain;charset=US-ASCII"

Probably more tests should be added for those spec changes, as just that one seems pretty small.

Copy link
Member

@foolip foolip left a 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!

@foolip
Copy link
Member

foolip commented Jan 24, 2018

Note that the "data:; base64,WA" @domenic found was fixed in 8d4335f

@domenic domenic dismissed their stale review January 25, 2018 06:10

I won't block on the format, but I still am unhappy.

@domenic
Copy link
Member

domenic commented Jan 25, 2018

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.

@foolip
Copy link
Member

foolip commented Jan 25, 2018

If "__default__" is acceptable to @domenic, then that seems like an improvement to me.

@domenic
Copy link
Member

domenic commented Jan 25, 2018

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.

@domenic
Copy link
Member

domenic commented Jan 25, 2018

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 /(.*); *base64$/i instead of /(.*); *[Bb][Aa][Ss][Ee]64$/, I would have gotten this wrong.

@foolip
Copy link
Member

foolip commented Jan 25, 2018

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.

@domenic
Copy link
Member

domenic commented Jan 25, 2018

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.

Are you doing things with the JSON file other than run these tests?

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.

@foolip
Copy link
Member

foolip commented Jan 25, 2018

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.

@annevk
Copy link
Member Author

annevk commented Jan 25, 2018

@domenic Unicode gets percent-encoded, no? I'm happy to expand the empty string btw, once everything else is in order.

@domenic
Copy link
Member

domenic commented Jan 30, 2018

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.

Copy link
Member

@domenic domenic left a 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 :)

@annevk annevk merged commit 7eec2bf into master Jan 31, 2018
@annevk annevk deleted the annevk/data-urls branch January 31, 2018 08:57
annevk added a commit to whatwg/fetch that referenced this pull request Jan 31, 2018
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],
Copy link
Contributor

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?

Copy link
Contributor

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.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah.

rsumner31 added a commit to rsumner31/fetch1 that referenced this pull request Mar 15, 2018
Unfortunately RFC 2397 has some ambiguities and implementations never
really followed it in detail.

Tests: web-platform-tests/wpt#6890.

Fixes #234.
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.

None yet

8 participants