Bug 1588248 - XHR.send() on workers must throw an InvalidStateError if called during another xhr.send(), r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D49968

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-10-22 05:19:46 +00:00
Родитель e5b77e11f4
Коммит a9bf7f7b5d
4 изменённых файлов: 46 добавлений и 1 удалений

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

@ -1948,7 +1948,7 @@ void XMLHttpRequestWorker::Send(
return;
}
if (!mProxy) {
if (!mProxy || mStateData.mFlagSend) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}

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

@ -111,3 +111,5 @@ skip-if = toolkit == "android" && debug && !is_fennec
[test_nestedSyncXHR.html]
[test_event_listener_leaks.html]
skip-if = (os == "win" && processor == "aarch64") #bug 1535784
[test_worker_xhr_doubleSend.html]
support-files = xhr_worker_doubleSend.js

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

@ -0,0 +1,32 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for DOM Worker Threads XHR - double send</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
var worker = new Worker("xhr_worker_doubleSend.js");
var gotUploadLoad = false, gotLoadend = false;
worker.onmessage = function(event) {
is(event.target, worker, "Target is the worker");
is(event.data, "OK", "All good!");
SimpleTest.finish();
};
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

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

@ -0,0 +1,11 @@
var xhr = new XMLHttpRequest();
xhr.open("POST", "worker_testXHR.txt");
xhr.send();
try {
xhr.send();
postMessage("KO double send should fail");
} catch (e) {
postMessage(
e.name === "InvalidStateError" ? "OK" : "KO InvalidStateError expected"
);
}