Backed out changeset e8d3827f914c (bug 883784) for mochitest assertions.

CLOSED TREE
This commit is contained in:
Ryan VanderMeulen 2013-06-20 18:36:34 -04:00
Родитель 284b554ae9
Коммит 074edb77b2
6 изменённых файлов: 17 добавлений и 172 удалений

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

@ -131,27 +131,17 @@ public:
{
AssertIsOnMainThread();
nsCOMPtr<nsIPrincipal> principal;
nsIDocument* doc = nullptr;
nsCOMPtr<nsPIDOMWindow> window = mWorkerPrivate->GetWindow();
if (window) {
doc = window->GetExtantDoc();
if (!doc) {
SetDOMStringToNull(mURL);
return;
}
principal = doc->NodePrincipal();
} else {
MOZ_ASSERT(mWorkerPrivate->IsChromeWorker());
principal = mWorkerPrivate->GetPrincipal();
nsIDocument* doc = window->GetExtantDoc();
if (!doc) {
SetDOMStringToNull(mURL);
return;
}
nsCString url;
nsresult rv = nsHostObjectProtocolHandler::AddDataEntry(
NS_LITERAL_CSTRING(BLOBURI_SCHEME),
mBlob, principal, url);
mBlob, doc->NodePrincipal(), url);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to add data entry for the blob!");
@ -159,12 +149,7 @@ public:
return;
}
if (doc) {
doc->RegisterHostObjectUri(url);
} else {
mWorkerPrivate->RegisterHostObjectURI(url);
}
doc->RegisterHostObjectUri(url);
mURL = NS_ConvertUTF8toUTF16(url);
}
};
@ -187,41 +172,24 @@ public:
{
AssertIsOnMainThread();
nsCOMPtr<nsIPrincipal> principal;
nsIDocument* doc = nullptr;
nsCOMPtr<nsPIDOMWindow> window = mWorkerPrivate->GetWindow();
if (window) {
doc = window->GetExtantDoc();
if (!doc) {
return;
}
principal = doc->NodePrincipal();
} else {
MOZ_ASSERT(mWorkerPrivate->IsChromeWorker());
principal = mWorkerPrivate->GetPrincipal();
nsIDocument* doc = window->GetExtantDoc();
if (!doc) {
return;
}
NS_ConvertUTF16toUTF8 url(mURL);
nsIPrincipal* urlPrincipal =
nsIPrincipal* principal =
nsHostObjectProtocolHandler::GetDataEntryPrincipal(url);
bool subsumes;
if (urlPrincipal &&
NS_SUCCEEDED(principal->Subsumes(urlPrincipal, &subsumes)) &&
if (principal &&
NS_SUCCEEDED(doc->NodePrincipal()->Subsumes(principal, &subsumes)) &&
subsumes) {
if (doc) {
doc->UnregisterHostObjectUri(url);
}
doc->UnregisterHostObjectUri(url);
nsHostObjectProtocolHandler::RemoveDataEntry(url);
}
if (!window) {
mWorkerPrivate->UnregisterHostObjectURI(url);
}
}
};

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

@ -26,7 +26,6 @@
#include "nsIXPConnect.h"
#include "nsIXPCScriptNotify.h"
#include "nsPrintfCString.h"
#include "nsHostObjectProtocolHandler.h"
#include <algorithm>
#include "jsfriendapi.h"
@ -530,23 +529,18 @@ class MainThreadReleaseRunnable : public nsRunnable
{
nsCOMPtr<nsIThread> mThread;
nsTArray<nsCOMPtr<nsISupports> > mDoomed;
nsTArray<nsCString> mHostObjectURIs;
public:
MainThreadReleaseRunnable(nsCOMPtr<nsIThread>& aThread,
nsTArray<nsCOMPtr<nsISupports> >& aDoomed,
nsTArray<nsCString>& aHostObjectURIs)
nsTArray<nsCOMPtr<nsISupports> >& aDoomed)
{
mThread.swap(aThread);
mDoomed.SwapElements(aDoomed);
mHostObjectURIs.SwapElements(aHostObjectURIs);
}
MainThreadReleaseRunnable(nsTArray<nsCOMPtr<nsISupports> >& aDoomed,
nsTArray<nsCString>& aHostObjectURIs)
MainThreadReleaseRunnable(nsTArray<nsCOMPtr<nsISupports> >& aDoomed)
{
mDoomed.SwapElements(aDoomed);
mHostObjectURIs.SwapElements(aHostObjectURIs);
}
NS_IMETHOD
@ -561,10 +555,6 @@ public:
runtime->NoteIdleThread(mThread);
}
for (uint32_t i = 0, len = mHostObjectURIs.Length(); i < len; ++i) {
nsHostObjectProtocolHandler::RemoveDataEntry(mHostObjectURIs[i]);
}
return NS_OK;
}
};
@ -602,11 +592,8 @@ public:
nsTArray<nsCOMPtr<nsISupports> > doomed;
mFinishedWorker->ForgetMainThreadObjects(doomed);
nsTArray<nsCString> hostObjectURIs;
mFinishedWorker->StealHostObjectURIs(hostObjectURIs);
nsRefPtr<MainThreadReleaseRunnable> runnable =
new MainThreadReleaseRunnable(mThread, doomed, hostObjectURIs);
new MainThreadReleaseRunnable(mThread, doomed);
if (NS_FAILED(NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL))) {
NS_WARNING("Failed to dispatch, going to leak!");
}
@ -654,11 +641,8 @@ public:
nsTArray<nsCOMPtr<nsISupports> > doomed;
mFinishedWorker->ForgetMainThreadObjects(doomed);
nsTArray<nsCString> hostObjectURIs;
mFinishedWorker->StealHostObjectURIs(hostObjectURIs);
nsRefPtr<MainThreadReleaseRunnable> runnable =
new MainThreadReleaseRunnable(doomed, hostObjectURIs);
new MainThreadReleaseRunnable(doomed);
if (NS_FAILED(NS_DispatchToCurrentThread(runnable))) {
NS_WARNING("Failed to dispatch, going to leak!");
}
@ -4311,30 +4295,6 @@ WorkerPrivate::AssertIsOnWorkerThread() const
}
#endif
template <class Derived>
void
WorkerPrivateParent<Derived>::RegisterHostObjectURI(const nsACString& aURI)
{
AssertIsOnMainThread();
mHostObjectURIs.AppendElement(aURI);
}
template <class Derived>
void
WorkerPrivateParent<Derived>::UnregisterHostObjectURI(const nsACString& aURI)
{
AssertIsOnMainThread();
mHostObjectURIs.RemoveElement(aURI);
}
template <class Derived>
void
WorkerPrivateParent<Derived>::StealHostObjectURIs(nsTArray<nsCString>& aArray)
{
AssertIsOnMainThread();
aArray.SwapElements(mHostObjectURIs);
}
WorkerCrossThreadDispatcher*
WorkerPrivate::GetCrossThreadDispatcher()
{

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

@ -277,9 +277,6 @@ private:
// Only used for top level workers.
nsTArray<nsRefPtr<WorkerRunnable> > mQueuedRunnables;
// Only for ChromeWorkers without window and only touched on the main thread.
nsTArray<nsCString> mHostObjectURIs;
// Protected by mMutex.
JSSettings mJSSettings;
@ -618,10 +615,6 @@ public:
AssertInnerWindowIsCorrect() const
{ }
#endif
void RegisterHostObjectURI(const nsACString& aURI);
void UnregisterHostObjectURI(const nsACString& aURI);
void StealHostObjectURIs(nsTArray<nsCString>& aArray);
};
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>

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

@ -148,9 +148,6 @@ MOCHITEST_CHROME_FILES = \
test_workersDisabled.xul \
workersDisabled_worker.js \
dom_worker_helper.js \
test_bug883784.xul \
test_bug883784.jsm \
url_worker.js \
$(NULL)
libs:: $(_SUBDIRMOCHITEST_FILES)

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

@ -1,37 +0,0 @@
this.EXPORTED_SYMBOLS = ["Test"];
this.Test = {
start: function(ok, is, finish) {
this.worker = new ChromeWorker("url_worker.js");
this.worker.onmessage = function(event) {
if (event.data.type == 'finish') {
finish();
} else if (event.data.type == 'status') {
ok(event.data.status, event.data.msg);
} else if (event.data.type == 'url') {
var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Components.interfaces.nsIXMLHttpRequest);
xhr.open('GET', event.data.url, false);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
ok(true, "Blob readable!");
}
}
xhr.send();
}
};
var self = this;
this.worker.onerror = function(event) {
is(event.target, worker);
ok(false, "Worker had an error: " + event.data);
self.worker.terminate();
finish();
};
this.worker.postMessage(true);
},
worker: null
};

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

@ -1,36 +0,0 @@
<?xml version="1.0"?>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<window title="DOM Worker Threads Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="test();">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript" src="dom_worker_helper.js"/>
<script type="application/javascript">
<![CDATA[
function test()
{
waitForWorkerFinish();
Components.utils.import("chrome://mochitests/content/chrome/dom/workers/test/test_bug883784.jsm");
Test.start(ok, is, finish);
}
]]>
</script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display:none;"></div>
<pre id="test"></pre>
</body>
<label id="test-result"/>
</window>