Commit d4ee2871 authored by kouhei@chromium.org's avatar kouhei@chromium.org

XMLHttpRequest::overrideMimeType should throw InvalidStateError

Before this CL, XMLHttpRequest accepted |overrideMimeType| regardless
of its state. This is not conformant to the current spec:
http://www.w3.org/TR/XMLHttpRequest2/#the-overridemimetype-method

This CL changes it to throw InvalidStateError when the state
is LOADING or DONE, which aligns to the spec.

BUG=402375

Review URL: https://codereview.chromium.org/478223002

git-svn-id: svn://svn.chromium.org/blink/trunk@180440 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 755d9c29
Testing overrideMimeType when readyState is 0
PASS xhr.overrideMimeType('text/plain') did not throw exception.
Testing overrideMimeType when readyState is 1
PASS xhr.overrideMimeType('text/plain') did not throw exception.
Testing overrideMimeType when readyState is 1
PASS xhr.overrideMimeType('text/plain') did not throw exception.
Testing overrideMimeType when readyState is 1
PASS xhr.overrideMimeType('text/plain') did not throw exception.
Testing overrideMimeType when readyState is 2
PASS xhr.overrideMimeType('text/plain') did not throw exception.
Testing overrideMimeType when readyState is 3
PASS xhr.overrideMimeType('text/plain') threw exception InvalidStateError: Failed to execute 'overrideMimeType' on 'XMLHttpRequest': MimeType cannot be overridden when the state is LOADING or DONE..
Testing overrideMimeType when readyState is 4
PASS xhr.overrideMimeType('text/plain') threw exception InvalidStateError: Failed to execute 'overrideMimeType' on 'XMLHttpRequest': MimeType cannot be overridden when the state is LOADING or DONE..
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="/js-test-resources/js-test.js"></script>
<script>
jsTestIsAsync = true;
function testOverrideMimeType(xhr) {
debug("Testing overrideMimeType when readyState is " + xhr.readyState);
var isAllowed = xhr.readyState < XMLHttpRequest.LOADING;
if (isAllowed) {
shouldNotThrow("xhr.overrideMimeType('text/plain')");
} else {
shouldThrow("xhr.overrideMimeType('text/plain')");
}
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
testOverrideMimeType(xhr);
if (xhr.readyState == XMLHttpRequest.DONE)
finishJSTest();
}
testOverrideMimeType(xhr);
xhr.open("GET", "resources/get.txt", true);
testOverrideMimeType(xhr);
xhr.send(null);
testOverrideMimeType(xhr);
</script>
......@@ -1089,12 +1089,14 @@ void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi
dispatchProgressEvent(EventTypeNames::loadend, receivedLength, expectedLength);
}
void XMLHttpRequest::overrideMimeType(const AtomicString& override)
void XMLHttpRequest::overrideMimeType(const AtomicString& mimeType, ExceptionState& exceptionState)
{
// FIXME: This method must throw an InvalidStateError exception when the
// XHR is in the LOADING or DONE state. http://crbug.com/402375
if (m_state == LOADING || m_state == DONE) {
exceptionState.throwDOMException(InvalidStateError, "MimeType cannot be overridden when the state is LOADING or DONE.");
return;
}
m_mimeTypeOverride = override;
m_mimeTypeOverride = mimeType;
}
void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicString& value, ExceptionState& exceptionState)
......
......@@ -113,7 +113,7 @@ public:
void send(ArrayBufferView*, ExceptionState&);
void abort();
void setRequestHeader(const AtomicString& name, const AtomicString& value, ExceptionState&);
void overrideMimeType(const AtomicString& override);
void overrideMimeType(const AtomicString& override, ExceptionState&);
String getAllResponseHeaders() const;
const AtomicString& getResponseHeader(const AtomicString&) const;
ScriptString responseText(ExceptionState&);
......
......@@ -82,5 +82,5 @@ enum XMLHttpRequestResponseType {
readonly attribute DOMString statusText;
// Extension
void overrideMimeType(DOMString override);
[RaisesException] void overrideMimeType(DOMString override);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment