Bug 918733 - have overrideMimeType throw INVALID_STATE_ERR if the XHR is in the DONE or LOADING states. r=sicking

This commit is contained in:
Thomas Wisniewski 2016-06-13 21:56:15 -04:00
Родитель 497ef8f99b
Коммит 2e6fa0f5fe
8 изменённых файлов: 81 добавлений и 20 удалений

Просмотреть файл

@ -3119,11 +3119,23 @@ nsXMLHttpRequest::ReadyState()
return DONE;
}
void nsXMLHttpRequest::OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv)
{
if ((mState & XML_HTTP_REQUEST_LOADING) || (mState & XML_HTTP_REQUEST_DONE)) {
ResetResponse();
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mOverrideMimeType = aMimeType;
}
NS_IMETHODIMP
nsXMLHttpRequest::SlowOverrideMimeType(const nsAString& aMimeType)
{
OverrideMimeType(aMimeType);
return NS_OK;
ErrorResult aRv;
OverrideMimeType(aMimeType, aRv);
return aRv.StealNSResult();
}
NS_IMETHODIMP

Просмотреть файл

@ -519,11 +519,7 @@ public:
void GetAllResponseHeaders(nsCString& aResponseHeaders);
bool IsSafeHeader(const nsACString& aHeaderName,
mozilla::NotNull<nsIHttpChannel*> aHttpChannel) const;
void OverrideMimeType(const nsAString& aMimeType)
{
// XXX Should we do some validation here?
mOverrideMimeType = aMimeType;
}
void OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv);
XMLHttpRequestResponseType ResponseType()
{
return XMLHttpRequestResponseType(mResponseType);

Просмотреть файл

@ -277,6 +277,7 @@ support-files =
[test_anonymousContent_api.html]
[test_anonymousContent_append_after_reflow.html]
[test_anonymousContent_canvas.html]
[test_xhr_overridemimetype_throws_on_invalid_state.html]
skip-if = buildapp == 'b2g' # Requires webgl support
[test_anonymousContent_insert.html]
[test_anonymousContent_manipulate_content.html]

Просмотреть файл

@ -0,0 +1,61 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test bug 482935</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href=" /tests/SimpleTest/test.css" />
</head>
<body onload="onWindowLoad()">
<script class="testbody" type="text/javascript">"use strict";
SimpleTest.waitForExplicitFinish();
var url = "file_XHR_pass1.xml";
function onWindowLoad() {
runTest();
}
function runTest() {
var testFunctions = [
function() { testOverMimeTypeThrowsDuringReadyState(3, "application/xml"); },
function() { testOverMimeTypeThrowsDuringReadyState(3, "application/xml;charset=Shift-JIS"); },
function() { testOverMimeTypeThrowsDuringReadyState(4, "application/xml"); },
function() { testOverMimeTypeThrowsDuringReadyState(4, "application/xml;charset=Shift-JIS"); },
];
function nextTest() {
if (testFunctions.length == 0) {
SimpleTest.finish();
return;
}
(testFunctions.shift())();
}
nextTest();
function testOverMimeTypeThrowsDuringReadyState(readyState, mimeType) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === readyState) {
try {
xhr.overrideMimeType(mimeType);
ok(false, "No exception thrown, but expected InvalidStateError" +
" for readyState=" + readyState + ", mimeType=" + mimeType);
} catch(exc) {
is(exc.name, "InvalidStateError", "Expected InvalidStateError, got " + exc.name +
" for readyState=" + readyState + ", mimeType=" + mimeType);
}
}
if (xhr.readyState === 4) {
is(xhr.responseXML, null, "responseXML was not null" +
" for readyState=" + readyState + ", mimeType=" + mimeType);
nextTest();
}
}
xhr.open("GET", url);
xhr.send();
}
}
</script>
</body>
</html>

Просмотреть файл

@ -119,7 +119,7 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
[Throws=Workers]
ByteString getAllResponseHeaders();
[Throws=Workers]
[Throws]
void overrideMimeType(DOMString mime);
[SetterThrows]

Просмотреть файл

@ -848,8 +848,9 @@ private:
virtual nsresult
RunOnMainThread() override
{
mProxy->mXHR->OverrideMimeType(mMimeType);
return NS_OK;
ErrorResult aRv;
mProxy->mXHR->OverrideMimeType(mMimeType, aRv);
return aRv.StealNSResult();
}
};

Просмотреть файл

@ -1,5 +0,0 @@
[overridemimetype-done-state.htm]
type: testharness
[XMLHttpRequest: overrideMimeType() in DONE state]
expected: FAIL

Просмотреть файл

@ -1,5 +0,0 @@
[overridemimetype-loading-state.htm]
type: testharness
[XMLHttpRequest: overrideMimeType() in LOADING state]
expected: FAIL