Bug 471920 - 'Workers: 404 errors when creating a new worker silently fails'. r+sr=jst, a=blocking1.9+

This commit is contained in:
Ben Turner 2009-01-04 13:41:03 -08:00
Родитель 3c9f784789
Коммит c5ffe7109b
3 изменённых файлов: 62 добавлений и 3 удалений

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

@ -39,7 +39,9 @@
#include "nsDOMWorkerScriptLoader.h"
// Interfaces
#include "nsIChannel.h"
#include "nsIContentPolicy.h"
#include "nsIHttpChannel.h"
#include "nsIIOService.h"
#include "nsIRequest.h"
#include "nsIScriptSecurityManager.h"
@ -231,6 +233,7 @@ nsDOMWorkerScriptLoader::VerifyScripts(JSContext* aCx)
message = "Malformed script URI: %s";
break;
case NS_ERROR_FILE_NOT_FOUND:
case NS_ERROR_NOT_AVAILABLE:
message = "Script file not found: %s";
break;
default:
@ -552,15 +555,15 @@ nsDOMWorkerScriptLoader::OnStreamCompleteInternal(nsIStreamLoader* aLoader,
#ifdef DEBUG
// Make sure we're seeing the channel that we expect.
nsCOMPtr<nsIRequest> request;
nsresult rvDebug = aLoader->GetRequest(getter_AddRefs(request));
nsCOMPtr<nsIRequest> requestDebug;
nsresult rvDebug = aLoader->GetRequest(getter_AddRefs(requestDebug));
// When we cancel sometimes we get null here. That should be ok, but only if
// we're canceled.
NS_ASSERTION(NS_SUCCEEDED(rvDebug) || mCanceled, "GetRequest failed!");
if (NS_SUCCEEDED(rvDebug)) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
nsCOMPtr<nsIChannel> channel(do_QueryInterface(requestDebug));
NS_ASSERTION(channel, "QI failed!");
nsCOMPtr<nsISupports> thisChannel(do_QueryInterface(channel));
@ -584,6 +587,23 @@ nsDOMWorkerScriptLoader::OnStreamCompleteInternal(nsIStreamLoader* aLoader,
return rv = NS_ERROR_UNEXPECTED;
}
// Make sure we're not seeing the result of a 404 or something by checking the
// 'requestSucceeded' attribute on the http channel.
nsCOMPtr<nsIRequest> request;
rv = aLoader->GetRequest(getter_AddRefs(request));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
if (httpChannel) {
PRBool requestSucceeded;
rv = httpChannel->GetRequestSucceeded(&requestSucceeded);
NS_ENSURE_SUCCESS(rv, rv);
if (!requestSucceeded) {
return rv = NS_ERROR_NOT_AVAILABLE;
}
}
nsIDocument* parentDoc = mWorker->Pool()->ParentDocument();
NS_ASSERTION(parentDoc, "Null parent document?!");

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

@ -47,6 +47,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_404.html \
test_errorPropagation.html \
errorPropagation_worker1.js \
errorPropagation_worker2.js \

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

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<!--
Tests of DOM Worker Threads
-->
<head>
<title>Test for DOM Worker Threads</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var worker = new Worker("nonexistent_worker.js");
worker.onmessage = function(event) {
ok(false, "Shouldn't ever get a message!");
SimpleTest.finish();
}
worker.onerror = function(event) {
is(event.target, worker);
is(event.message, "Script file not found: nonexistent_worker.js");
event.preventDefault();
SimpleTest.finish();
};
worker.postMessage("dummy");
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>