зеркало из https://github.com/mozilla/gecko-dev.git
Back out bug 701787 due to orangeness conflict with tests added in bug 664179.
This commit is contained in:
Родитель
a9ab2bba5b
Коммит
1a1333165e
|
@ -712,25 +712,6 @@ nsXMLHttpRequest::GetChannel(nsIChannel **aChannel)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static void LogMessage(const char* aWarning, nsPIDOMWindow* aWindow)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
if (aWindow) {
|
||||
doc = do_QueryInterface(aWindow->GetExtantDocument());
|
||||
}
|
||||
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
|
||||
aWarning,
|
||||
nsnull,
|
||||
0,
|
||||
nsnull, // Response URL not kept around
|
||||
EmptyString(),
|
||||
0,
|
||||
0,
|
||||
nsIScriptError::warningFlag,
|
||||
"DOM",
|
||||
doc);
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMDocument responseXML; */
|
||||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::GetResponseXML(nsIDOMDocument **aResponseXML)
|
||||
|
@ -747,11 +728,31 @@ nsXMLHttpRequest::GetResponseXML(nsIDOMDocument **aResponseXML)
|
|||
}
|
||||
if (mWarnAboutMultipartHtml) {
|
||||
mWarnAboutMultipartHtml = false;
|
||||
LogMessage("HTMLMultipartXHRWarning", mOwner);
|
||||
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
|
||||
"HTMLMultipartXHRWarning",
|
||||
nsnull,
|
||||
0,
|
||||
nsnull, // Response URL not kept around
|
||||
EmptyString(),
|
||||
0,
|
||||
0,
|
||||
nsIScriptError::warningFlag,
|
||||
"DOM",
|
||||
mOwner->WindowID());
|
||||
}
|
||||
if (mWarnAboutSyncHtml) {
|
||||
mWarnAboutSyncHtml = false;
|
||||
LogMessage("HTMLSyncXHRWarning", mOwner);
|
||||
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
|
||||
"HTMLSyncXHRWarning",
|
||||
nsnull,
|
||||
0,
|
||||
nsnull, // Response URL not kept around
|
||||
EmptyString(),
|
||||
0,
|
||||
0,
|
||||
nsIScriptError::warningFlag,
|
||||
"DOM",
|
||||
mOwner->WindowID());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1008,13 +1009,6 @@ NS_IMETHODIMP nsXMLHttpRequest::SetResponseType(const nsAString& aResponseType)
|
|||
XML_HTTP_REQUEST_HEADERS_RECEIVED)))
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
|
||||
// sync request is not allowed setting responseType in window context
|
||||
if (mOwner &&
|
||||
!(mState & (XML_HTTP_REQUEST_UNSENT | XML_HTTP_REQUEST_ASYNC))) {
|
||||
LogMessage("ResponseTypeSyncXHRWarning", mOwner);
|
||||
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
||||
}
|
||||
|
||||
// Set the responseType attribute's value to the given value.
|
||||
if (aResponseType.IsEmpty()) {
|
||||
mResponseType = XML_HTTP_RESPONSE_TYPE_DEFAULT;
|
||||
|
@ -1536,20 +1530,6 @@ nsXMLHttpRequest::Open(const nsACString& method, const nsACString& url,
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// sync request is not allowed using withCredential or responseType
|
||||
// in window context
|
||||
if (!async && mOwner &&
|
||||
(mState & XML_HTTP_REQUEST_AC_WITH_CREDENTIALS ||
|
||||
mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT)) {
|
||||
if (mState & XML_HTTP_REQUEST_AC_WITH_CREDENTIALS) {
|
||||
LogMessage("WithCredentialsSyncXHRWarning", mOwner);
|
||||
}
|
||||
if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT) {
|
||||
LogMessage("ResponseTypeSyncXHRWarning", mOwner);
|
||||
}
|
||||
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
bool authp = false;
|
||||
|
@ -2951,14 +2931,7 @@ nsXMLHttpRequest::SetWithCredentials(bool aWithCredentials)
|
|||
if (XML_HTTP_REQUEST_SENT & mState) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// sync request is not allowed setting withCredentials in window context
|
||||
if (mOwner &&
|
||||
!(mState & (XML_HTTP_REQUEST_UNSENT | XML_HTTP_REQUEST_ASYNC))) {
|
||||
LogMessage("WithCredentialsSyncXHRWarning", mOwner);
|
||||
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
||||
}
|
||||
|
||||
|
||||
if (aWithCredentials) {
|
||||
mState |= XML_HTTP_REQUEST_AC_WITH_CREDENTIALS;
|
||||
}
|
||||
|
|
|
@ -5,20 +5,15 @@
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body onload="gen.next();">
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="application/javascript;version=1.7">
|
||||
<script class="testbody" type="text/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var gen = runTests();
|
||||
function continueTest() { gen.next(); }
|
||||
|
||||
function runTests() {
|
||||
|
||||
var path = "/tests/content/base/test/";
|
||||
|
||||
var passFiles = [['file_XHR_pass1.xml', 'GET'],
|
||||
|
@ -68,6 +63,7 @@ for (i = 0; i < failFiles.length; ++i) {
|
|||
}
|
||||
}
|
||||
|
||||
// test response (responseType='document')
|
||||
function checkResponseTextAccessThrows(xhr) {
|
||||
var didthrow = false;
|
||||
try { xhr.responseText } catch (e) { didthrow = true; }
|
||||
|
@ -88,35 +84,14 @@ function checkSetResponseTypeThrows(xhr, type) {
|
|||
try { xhr.responseType = type; } catch (e) { didthrow = true; }
|
||||
ok(didthrow, "should have thrown when setting responseType");
|
||||
}
|
||||
function checkOpenThrows(xhr, method, url, async) {
|
||||
var didthrow = false;
|
||||
try { xhr.open(method, url, async); } catch (e) { didthrow = true; }
|
||||
ok(didthrow, "should have thrown when open is called");
|
||||
}
|
||||
|
||||
// test response (sync, responseType is not changeable)
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass2.txt', false);
|
||||
checkSetResponseTypeThrows(xhr, "");
|
||||
checkSetResponseTypeThrows(xhr, "text");
|
||||
checkSetResponseTypeThrows(xhr, "document");
|
||||
checkSetResponseTypeThrows(xhr, "arraybuffer");
|
||||
checkSetResponseTypeThrows(xhr, "blob");
|
||||
checkSetResponseTypeThrows(xhr, "moz-json");
|
||||
xhr.open("GET", 'file_XHR_pass1.xml', false);
|
||||
checkSetResponseTypeThrows(xhr, "moz-chunked-text");
|
||||
checkSetResponseTypeThrows(xhr, "moz-chunked-arraybuffer");
|
||||
xhr.send(null);
|
||||
checkSetResponseTypeThrows(xhr, "document");
|
||||
is(xhr.status, 200, "wrong status");
|
||||
is(xhr.response, "hello pass\n", "wrong response");
|
||||
|
||||
// test response (responseType='document')
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass1.xml');
|
||||
xhr.responseType = 'document';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
checkSetResponseTypeThrows(xhr, "document");
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
|
@ -126,11 +101,9 @@ is((new XMLSerializer()).serializeToString(xhr.response.documentElement),
|
|||
|
||||
// test response (responseType='text')
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass2.txt');
|
||||
xhr.open("GET", 'file_XHR_pass2.txt', false);
|
||||
xhr.responseType = 'text';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
is(xhr.response, "hello pass\n", "wrong response");
|
||||
|
@ -145,11 +118,9 @@ function arraybuffer_equals_to(ab, s) {
|
|||
|
||||
// with a simple text file
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass2.txt');
|
||||
xhr.open("GET", 'file_XHR_pass2.txt', false);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
|
@ -158,11 +129,9 @@ ok(ab != null, "should have a non-null arraybuffer");
|
|||
arraybuffer_equals_to(ab, "hello pass\n");
|
||||
|
||||
// test reusing the same XHR (Bug 680816)
|
||||
xhr.open("GET", 'file_XHR_binary1.bin');
|
||||
xhr.open("GET", 'file_XHR_binary1.bin', false);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
is(xhr.status, 200, "wrong status");
|
||||
ab2 = xhr.response;
|
||||
ok(ab2 != null, "should have a non-null arraybuffer");
|
||||
|
@ -172,11 +141,9 @@ arraybuffer_equals_to(ab2, "\xaa\xee\0\x03\xff\xff\xff\xff\xbb\xbb\xbb\xbb");
|
|||
|
||||
// with a binary file
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_binary1.bin');
|
||||
xhr.open("GET", 'file_XHR_binary1.bin', false);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
xhr.send(null)
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
|
@ -187,12 +154,10 @@ is(xhr.response, xhr.response, "returns the same ArrayBuffer");
|
|||
|
||||
// test response (responseType='moz-json')
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", 'responseIdentical.sjs');
|
||||
xhr.open("POST", 'responseIdentical.sjs', false);
|
||||
xhr.responseType = 'moz-json';
|
||||
jsonObjStr = JSON.stringify({title: "aBook", author: "john"});
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(jsonObjStr);
|
||||
yield;
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
|
@ -201,11 +166,9 @@ is(xhr.response, xhr.response, "returning the same object on each access");
|
|||
|
||||
// with invalid json
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", 'responseIdentical.sjs');
|
||||
xhr.open("POST", 'responseIdentical.sjs', false);
|
||||
xhr.responseType = 'moz-json';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send("{");
|
||||
yield;
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
|
@ -220,11 +183,9 @@ function checkOnloadCount() {
|
|||
|
||||
// with a simple text file
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", 'file_XHR_pass2.txt');
|
||||
xhr.open("GET", 'file_XHR_pass2.txt', false);
|
||||
xhr.responseType = 'blob';
|
||||
xhr.onloadend = continueTest;
|
||||
xhr.send(null);
|
||||
yield;
|
||||
is(xhr.status, 200, "wrong status");
|
||||
checkResponseTextAccessThrows(xhr);
|
||||
checkResponseXMLAccessThrows(xhr);
|
||||
|
@ -320,8 +281,6 @@ client.open("GET", "file_XHR_pass1.xml", true);
|
|||
client.send();
|
||||
client.abort();
|
||||
|
||||
yield;
|
||||
} /* runTests */
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -8,7 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=464848
|
|||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body onload="gen.next();">
|
||||
<body>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=464848">Mozilla Bug 464848</a>
|
||||
<p id="display">
|
||||
|
@ -19,12 +19,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=464848
|
|||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="application/javascript;version=1.8">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var gen = runTests();
|
||||
function continueTest() { gen.next(); }
|
||||
|
||||
function runTests() {
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "file_XHRSendData_doc.xml", false);
|
||||
|
@ -182,16 +176,12 @@ for (var i = 0; i < testDOMFiles.length; i++) {
|
|||
try {
|
||||
for each(test in tests) {
|
||||
xhr = new XMLHttpRequest;
|
||||
xhr.open("POST", "file_XHRSendData.sjs", !!test.resType);
|
||||
xhr.open("POST", "file_XHRSendData.sjs", false);
|
||||
if (test.contentType)
|
||||
xhr.setRequestHeader("Content-Type", test.contentType);
|
||||
if (test.resType) {
|
||||
xhr.responseType = test.resType;
|
||||
xhr.onloadend = continueTest;
|
||||
}
|
||||
xhr.send(test.body);
|
||||
if (test.resType)
|
||||
yield;
|
||||
xhr.responseType = test.resType;
|
||||
xhr.send(test.body);
|
||||
|
||||
if (test.resContentType) {
|
||||
is(xhr.getResponseHeader("Result-Content-Type"), test.resContentType,
|
||||
|
@ -244,10 +234,6 @@ function is_identical_arraybuffer(ab1, ab2) {
|
|||
String.fromCharCode.apply(String, u8v2), "arraybuffer values not equal");
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
yield;
|
||||
} /* runTests */
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -86,14 +86,14 @@ function onWindowLoad() {
|
|||
ok(document.iframeWasLoaded, "Loading resource via src-attribute");
|
||||
|
||||
|
||||
function runTest(test) {
|
||||
for each (test in alltests) {
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
|
||||
var method = "GET";
|
||||
if (test.method != null) { method = test.method; }
|
||||
xhr.open(method, test.url);
|
||||
|
||||
xhr.open(method, test.url, false);
|
||||
|
||||
xhr.withCredentials = test.withCredentials;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
@ -104,20 +104,11 @@ function onWindowLoad() {
|
|||
xhr.send();
|
||||
} catch(e) {
|
||||
}
|
||||
|
||||
xhr.onloadend = function() {
|
||||
var success = eval(xhr.status + test.status_check);
|
||||
ok(success, test.error);
|
||||
|
||||
if (alltests.length == 0) {
|
||||
SimpleTest.finish();
|
||||
} else {
|
||||
runTest(alltests.shift());
|
||||
}
|
||||
};
|
||||
var success = eval(xhr.status + test.status_check);
|
||||
ok(success, test.error);
|
||||
}
|
||||
|
||||
runTest(alltests.shift());
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
// Test setting .responseType and .withCredentials is allowed
|
||||
// in non-window non-Worker context
|
||||
|
||||
function run_test()
|
||||
{
|
||||
var xhr = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].
|
||||
createInstance(Components.interfaces.nsIXMLHttpRequest);
|
||||
xhr.open('GET', 'data:,', false);
|
||||
var exceptionThrown = false;
|
||||
try {
|
||||
xhr.responseType = '';
|
||||
xhr.withCredentials = false;
|
||||
} catch (e) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
do_check_eq(false, exceptionThrown);
|
||||
}
|
|
@ -7,5 +7,4 @@ tail =
|
|||
[test_csputils.js]
|
||||
[test_error_codes.js]
|
||||
[test_thirdpartyutil.js]
|
||||
[test_xhr_standalone.js]
|
||||
[test_xmlserializer.js]
|
||||
|
|
|
@ -130,5 +130,3 @@ AddedWindowedPluginWhileFullScreen=Exited full-screen because windowed plugin wa
|
|||
HTMLMultipartXHRWarning=HTML parsing in XMLHttpRequest is not supported for multipart responses.
|
||||
HTMLSyncXHRWarning=HTML parsing in XMLHttpRequest is not supported in the synchronous mode.
|
||||
InvalidRedirectChannelWarning=Unable to redirect to %S because the channel doesn't implement nsIWritablePropertyBag2.
|
||||
ResponseTypeSyncXHRWarning=Use of XMLHttpRequest's responseType attribute is no longer supported in the synchronous mode in window context.
|
||||
WithCredentialsSyncXHRWarning=Use of XMLHttpRequest's withCredentials attribute is no longer supported in the synchronous mode in window context.
|
||||
|
|
|
@ -2869,6 +2869,7 @@ var gDetailView = {
|
|||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", this._addon.optionsURL, false);
|
||||
xhr.responseType = "document";
|
||||
xhr.send();
|
||||
|
||||
var xml = xhr.responseXML;
|
||||
|
|
Загрузка…
Ссылка в новой задаче