-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add more XMLHttpRequest overrideMimeType() tests #8449
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,60 +6,51 @@ | |
<div id="log"></div> | ||
<script> | ||
async_test(t => { | ||
const client = new XMLHttpRequest() | ||
const client = new XMLHttpRequest(); | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.getResponseHeader("Content-Type"), "") | ||
assert_equals(client.response.type, "text/xml") | ||
}) | ||
client.open("GET", "resources/status.py") | ||
client.responseType = "blob" | ||
client.send() | ||
}, "Use text/xml as fallback MIME type") | ||
assert_equals(client.getResponseHeader("Content-Type"), ""); | ||
assert_equals(client.response.type, "text/xml"); | ||
}); | ||
client.open("GET", "resources/status.py"); | ||
client.responseType = "blob"; | ||
client.send(); | ||
}, "Use text/xml as fallback MIME type"); | ||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest() | ||
const client = new XMLHttpRequest(); | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.getResponseHeader("Content-Type"), "") | ||
assert_equals(client.response.type, "text/xml") | ||
assert_equals(client.getResponseHeader("Content-Type"), ""); | ||
assert_equals(client.response.type, "text/xml"); | ||
}) | ||
client.open("GET", "resources/status.py?content=thisshouldnotmakeadifferencebutdoes") | ||
client.responseType = "blob" | ||
client.send() | ||
}, "Use text/xml as fallback MIME type, 2") | ||
client.open("GET", "resources/status.py?content=thisshouldnotmakeadifferencebutdoes"); | ||
client.responseType = "blob"; | ||
client.send(); | ||
}, "Use text/xml as fallback MIME type, 2"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why the above two tests are in a file related to overrideMimeType()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No good reason. |
||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest() | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.getResponseHeader("Content-Type"), "") | ||
assert_equals(client.response.type, "application/octet-stream") | ||
}) | ||
client.open("GET", "resources/status.py") | ||
client.responseType = "blob" | ||
client.overrideMimeType("bogus") | ||
client.send() | ||
}, "Bogus MIME type should end up as application/octet-stream") | ||
promise_test(() => { | ||
// Don't load generated-mime-types.json as sending them all over the network would be prohibitive | ||
return fetch("../mimesniff/mime-types/resources/mime-types.json").then(res => res.json()).then(runTests); | ||
}, "Loading data…"); | ||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest() | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.getResponseHeader("Content-Type"), "") | ||
assert_equals(client.response.type, "application/octet-stream") | ||
}) | ||
client.open("GET", "resources/status.py") | ||
client.responseType = "blob" | ||
client.overrideMimeType("text/xml;charset=†") | ||
client.send() | ||
}, "Bogus MIME type should end up as application/octet-stream, 2") | ||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest() | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.getResponseHeader("Content-Type"), "") | ||
assert_equals(client.response.type, "hi/x") | ||
}) | ||
client.open("GET", "resources/status.py") | ||
client.responseType = "blob" | ||
client.overrideMimeType("HI/x;test=test") | ||
client.send() | ||
}, "Valid MIME types need to be normalized") | ||
function runTests(tests) { | ||
let index = 0; | ||
tests.forEach((val) => { | ||
if(typeof val === "string") { | ||
return; | ||
} | ||
index++; | ||
async_test(t => { | ||
const client = new XMLHttpRequest(), | ||
expectedOutput = val.output !== null ? val.output : "application/octet-stream"; | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.getResponseHeader("Content-Type"), ""); | ||
assert_equals(client.response.type, expectedOutput); | ||
}); | ||
client.open("GET", "resources/status.py"); | ||
client.responseType = "blob"; | ||
client.overrideMimeType(val.input); | ||
client.send(); | ||
}, index + ") MIME types need to be parsed and serialized: " + val.input); | ||
}); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const testURL = "resources/status.py?type=" + encodeURIComponent("text/plain;charset=windows-1252") + "&content=%C2%F0"; | ||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest(); | ||
let secondTime = false; | ||
client.onload = t.step_func(() => { | ||
if(!secondTime) { | ||
assert_equals(client.responseText, "\uFFFD"); | ||
secondTime = true; | ||
client.open("GET", testURL); | ||
client.send(); | ||
} else { | ||
assert_equals(client.responseText, "Âð"); | ||
t.done(); | ||
} | ||
}); | ||
client.open("GET", testURL); | ||
client.overrideMimeType("text/plain;charset=UTF-8") | ||
client.send(); | ||
}, "overrideMimeType() state needs to be reset across requests"); | ||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest(); | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.responseText, "Âð") | ||
}); | ||
client.open("GET", testURL); | ||
client.overrideMimeType("text/xml"); | ||
client.send(); | ||
}, "If charset is not overridden by overrideMimeType() the original continues to be used"); | ||
|
||
async_test(t => { | ||
const client = new XMLHttpRequest(); | ||
client.onload = t.step_func_done(() => { | ||
assert_equals(client.responseText, "\uFFFD") | ||
}); | ||
client.open("GET", testURL); | ||
client.overrideMimeType("text/plain;charset=342"); | ||
client.send(); | ||
}, "Charset can be overridden by overrideMimeType() with a bogus charset"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is extraordinarily hard to review because almost every line has changed, but I guess only because of semicolons? Please split up the commits at least next time.
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.
Sorry, I figured it wouldn't be much of an issue given how GitHub highlights stuff.