зеркало из https://github.com/mozilla/gecko-dev.git
Bug 884693 - Do not log console warnings for XHR parse failures if HTTP status is 204 or 304. r=smaug
This commit is contained in:
Родитель
db1ebdc0cf
Коммит
3c6249dd4b
|
@ -250,6 +250,9 @@ public:
|
|||
virtual void SetSuppressParserErrorElement(bool aSuppress) {}
|
||||
virtual bool SuppressParserErrorElement() { return false; }
|
||||
|
||||
virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) {}
|
||||
virtual bool SuppressParserErrorConsoleMessages() { return false; }
|
||||
|
||||
/**
|
||||
* Signal that the document title may have changed
|
||||
* (see nsDocument::GetTitle).
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
function handleRequest(request, response)
|
||||
{
|
||||
let [status, statusText, body] = request.queryString.split("&");
|
||||
response.setStatusLine(request.httpVersion, status, statusText);
|
||||
response.setHeader("Content-Type", "text/xml", false);
|
||||
response.setHeader("Content-Length", "" + body.length, false);
|
||||
response.write(body);
|
||||
}
|
|
@ -58,6 +58,7 @@ skip-if = buildapp == 'mulet'
|
|||
[test_bug800386.xul]
|
||||
[test_bug814638.xul]
|
||||
[test_bug816340.xul]
|
||||
[test_bug884693.xul]
|
||||
[test_bug914381.html]
|
||||
[test_bug990812.xul]
|
||||
[test_bug1063837.xul]
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=884693
|
||||
-->
|
||||
<window title="Mozilla Bug 884693"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=884693"
|
||||
target="_blank">Mozilla Bug 884693</a>
|
||||
</body>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
const SERVER_URL = "http://mochi.test:8888/tests/dom/base/test/chrome/bug884693.sjs";
|
||||
const INVALID_XML = "InvalidXML";
|
||||
|
||||
var { classes: Cc, interfaces: Ci } = Components;
|
||||
|
||||
let consoleService = Cc["@mozilla.org/consoleservice;1"].
|
||||
getService(Ci.nsIConsoleService)
|
||||
|
||||
function runTest(status, statusText, body, expectedResponse, expectedMessages)
|
||||
{
|
||||
return new Promise((resolve, reject) => {
|
||||
consoleService.reset();
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.onload = () => {
|
||||
is(xhr.responseText, expectedResponse, "Correct responseText returned");
|
||||
|
||||
let messages = consoleService.getMessageArray() || [];
|
||||
is(messages.length, expectedMessages.length, "Got expected message count");
|
||||
messages = messages.map(m => m.message).join(",");
|
||||
for(let message of expectedMessages) {
|
||||
ok(messages.indexOf(message) >= 0, "Got expected message: " + message);
|
||||
}
|
||||
|
||||
resolve();
|
||||
};
|
||||
|
||||
xhr.onerror = e => {
|
||||
reject(e);
|
||||
};
|
||||
|
||||
xhr.open("GET", `${SERVER_URL}?${status}&${statusText}&${body}`);
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest(204, "No content", "", "", []).
|
||||
then(() => { return runTest(204, "No content", INVALID_XML, "", []); }).
|
||||
then(() => { return runTest(304, "Not modified", "", "", []); }).
|
||||
then(() => { return runTest(304, "Not modified", INVALID_XML, "", []); }).
|
||||
then(() => { return runTest(200, "OK", "", "", ["no root element found"]); }).
|
||||
then(() => { return runTest(200, "OK", INVALID_XML, INVALID_XML, ["syntax error"]); }).
|
||||
then(SimpleTest.finish);
|
||||
|
||||
]]></script>
|
||||
</window>
|
|
@ -36,6 +36,7 @@ TEST_DIRS += [
|
|||
|
||||
TEST_HARNESS_FILES.testing.mochitest.tests.dom.base.test.chrome += [
|
||||
'chrome/bug421622-referer.sjs',
|
||||
'chrome/bug884693.sjs',
|
||||
'chrome/nochrome_bug765993.html',
|
||||
'chrome/nochrome_bug765993.js',
|
||||
'chrome/nochrome_bug765993.js^headers^',
|
||||
|
|
|
@ -2000,6 +2000,15 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
|
|||
mRequestObserver->OnStopRequest(request, ctxt, status);
|
||||
}
|
||||
|
||||
// suppress parsing failure messages to console for status 204/304 (see bug 884693).
|
||||
if (mResponseXML) {
|
||||
uint32_t responseStatus;
|
||||
if (NS_SUCCEEDED(GetStatus(&responseStatus)) &&
|
||||
(responseStatus == 204 || responseStatus == 304)) {
|
||||
mResponseXML->SetSuppressParserErrorConsoleMessages(true);
|
||||
}
|
||||
}
|
||||
|
||||
// make sure to notify the listener if we were aborted
|
||||
// XXX in fact, why don't we do the cleanup below in this case??
|
||||
// State::unsent is for abort calls. See OnStartRequest above.
|
||||
|
|
|
@ -499,6 +499,18 @@ XMLDocument::SuppressParserErrorElement()
|
|||
return mSuppressParserErrorElement;
|
||||
}
|
||||
|
||||
void
|
||||
XMLDocument::SetSuppressParserErrorConsoleMessages(bool aSuppress)
|
||||
{
|
||||
mSuppressParserErrorConsoleMessages = aSuppress;
|
||||
}
|
||||
|
||||
bool
|
||||
XMLDocument::SuppressParserErrorConsoleMessages()
|
||||
{
|
||||
return mSuppressParserErrorConsoleMessages;
|
||||
}
|
||||
|
||||
nsresult
|
||||
XMLDocument::StartDocumentLoad(const char* aCommand,
|
||||
nsIChannel* aChannel,
|
||||
|
|
|
@ -32,6 +32,9 @@ public:
|
|||
virtual void SetSuppressParserErrorElement(bool aSuppress) override;
|
||||
virtual bool SuppressParserErrorElement() override;
|
||||
|
||||
virtual void SetSuppressParserErrorConsoleMessages(bool aSuppress) override;
|
||||
virtual bool SuppressParserErrorConsoleMessages() override;
|
||||
|
||||
virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* channel,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsISupports* aContainer,
|
||||
|
@ -92,6 +95,9 @@ protected:
|
|||
// If true, do not output <parsererror> elements. Per spec, XMLHttpRequest
|
||||
// shouldn't output them, whereas DOMParser/others should (see bug 918703).
|
||||
bool mSuppressParserErrorElement;
|
||||
|
||||
// If true, do not log parsing errors to the web console (see bug 884693).
|
||||
bool mSuppressParserErrorConsoleMessages;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -969,6 +969,11 @@ nsExpatDriver::HandleError()
|
|||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mOriginalSink->GetTarget());
|
||||
if (doc && doc->SuppressParserErrorConsoleMessages()) {
|
||||
shouldReportError = false;
|
||||
}
|
||||
|
||||
if (shouldReportError) {
|
||||
nsCOMPtr<nsIConsoleService> cs
|
||||
(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
||||
|
|
Загрузка…
Ссылка в новой задаче