mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1378342 - AbortSignal/AbortController - part 4 - Separate pref for AbortSignal/AbortController, r=bkelly
--HG-- rename : dom/abort/tests/file_abort_controller.html => dom/abort/tests/file_abort_controller_fetch.html rename : dom/abort/tests/test_abort_controller.html => dom/abort/tests/test_abort_controller_fetch.html rename : dom/abort/tests/worker_abort_controller.js => dom/abort/tests/worker_abort_controller_fetch.js
This commit is contained in:
parent
6e67fd43cc
commit
031018437a
@ -40,6 +40,26 @@ AbortController::IsEnabled(JSContext* aCx, JSObject* aGlobal)
|
||||
return workerPrivate->AbortControllerEnabled();
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
AbortController::IsEnabledInFetch(JSContext* aCx, JSObject* aGlobal)
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
return IsEnabled(aCx, aGlobal) &&
|
||||
Preferences::GetBool("dom.abortController.fetch.enabled", false);
|
||||
}
|
||||
|
||||
using namespace workers;
|
||||
|
||||
// Otherwise, check the pref via the WorkerPrivate
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
if (!workerPrivate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return workerPrivate->AbortControllerEnabled() &&
|
||||
workerPrivate->AbortControllerEnabledInFetch();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<AbortController>
|
||||
AbortController::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
|
||||
{
|
||||
|
@ -29,6 +29,9 @@ public:
|
||||
static bool
|
||||
IsEnabled(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
static bool
|
||||
IsEnabledInFetch(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
static already_AddRefed<AbortController>
|
||||
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
|
||||
|
||||
|
@ -41,48 +41,6 @@ function testAbortEvent() {
|
||||
ac.abort();
|
||||
}
|
||||
|
||||
function testAbortedFetch() {
|
||||
var ac = new AbortController();
|
||||
ac.abort();
|
||||
|
||||
fetch('slow.sjs', { signal: ac.signal }).then(() => {
|
||||
ok(false, "Fetch should not return a resolved promise");
|
||||
}, e => {
|
||||
is(e.name, "AbortError", "We have an abort error");
|
||||
}).then(next);
|
||||
}
|
||||
|
||||
function testFetchAndAbort() {
|
||||
var ac = new AbortController();
|
||||
|
||||
var p = fetch('slow.sjs', { signal: ac.signal });
|
||||
ac.abort();
|
||||
|
||||
p.then(() => {
|
||||
ok(false, "Fetch should not return a resolved promise");
|
||||
}, e => {
|
||||
is(e.name, "AbortError", "We have an abort error");
|
||||
}).then(next);
|
||||
}
|
||||
|
||||
function testWorkerAbortedFetch() {
|
||||
var w = new Worker('worker_abort_controller.js');
|
||||
w.onmessage = function(e) {
|
||||
ok(e.data, "Abort + Fetch works in workers");
|
||||
next();
|
||||
}
|
||||
w.postMessage('testWorkerAbortedFetch');
|
||||
}
|
||||
|
||||
function testWorkerFetchAndAbort() {
|
||||
var w = new Worker('worker_abort_controller.js');
|
||||
w.onmessage = function(e) {
|
||||
ok(e.data, "Abort + Fetch works in workers");
|
||||
next();
|
||||
}
|
||||
w.postMessage('testWorkerFetchAndAbort');
|
||||
}
|
||||
|
||||
var steps = [
|
||||
// Simple stuff
|
||||
testWebIDL,
|
||||
@ -90,12 +48,6 @@ var steps = [
|
||||
|
||||
// Event propagation
|
||||
testAbortEvent,
|
||||
|
||||
// fetch + signaling
|
||||
testAbortedFetch,
|
||||
testFetchAndAbort,
|
||||
testWorkerAbortedFetch,
|
||||
testWorkerFetchAndAbort,
|
||||
];
|
||||
|
||||
function next() {
|
||||
|
72
dom/abort/tests/file_abort_controller_fetch.html
Normal file
72
dom/abort/tests/file_abort_controller_fetch.html
Normal file
@ -0,0 +1,72 @@
|
||||
<script>
|
||||
function ok(a, msg) {
|
||||
parent.postMessage({ type: "check", status: !!a, message: msg }, "*");
|
||||
}
|
||||
|
||||
function is(a, b, msg) {
|
||||
ok(a === b, msg);
|
||||
}
|
||||
|
||||
function testAbortedFetch() {
|
||||
var ac = new AbortController();
|
||||
ac.abort();
|
||||
|
||||
fetch('slow.sjs', { signal: ac.signal }).then(() => {
|
||||
ok(false, "Fetch should not return a resolved promise");
|
||||
}, e => {
|
||||
is(e.name, "AbortError", "We have an abort error");
|
||||
}).then(next);
|
||||
}
|
||||
|
||||
function testFetchAndAbort() {
|
||||
var ac = new AbortController();
|
||||
|
||||
var p = fetch('slow.sjs', { signal: ac.signal });
|
||||
ac.abort();
|
||||
|
||||
p.then(() => {
|
||||
ok(false, "Fetch should not return a resolved promise");
|
||||
}, e => {
|
||||
is(e.name, "AbortError", "We have an abort error");
|
||||
}).then(next);
|
||||
}
|
||||
|
||||
function testWorkerAbortedFetch() {
|
||||
var w = new Worker('worker_abort_controller_fetch.js');
|
||||
w.onmessage = function(e) {
|
||||
ok(e.data, "Abort + Fetch works in workers");
|
||||
next();
|
||||
}
|
||||
w.postMessage('testWorkerAbortedFetch');
|
||||
}
|
||||
|
||||
function testWorkerFetchAndAbort() {
|
||||
var w = new Worker('worker_abort_controller_fetch.js');
|
||||
w.onmessage = function(e) {
|
||||
ok(e.data, "Abort + Fetch works in workers");
|
||||
next();
|
||||
}
|
||||
w.postMessage('testWorkerFetchAndAbort');
|
||||
}
|
||||
|
||||
var steps = [
|
||||
// fetch + signaling
|
||||
testAbortedFetch,
|
||||
testFetchAndAbort,
|
||||
testWorkerAbortedFetch,
|
||||
testWorkerFetchAndAbort,
|
||||
];
|
||||
|
||||
function next() {
|
||||
if (!steps.length) {
|
||||
parent.postMessage({ type: "finish" }, "*");
|
||||
return;
|
||||
}
|
||||
|
||||
var step = steps.shift();
|
||||
step();
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
</script>
|
@ -1,6 +1,8 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
file_abort_controller.html
|
||||
worker_abort_controller.js
|
||||
file_abort_controller_fetch.html
|
||||
worker_abort_controller_fetch.js
|
||||
|
||||
[test_abort_controller.html]
|
||||
[test_abort_controller_fetch.html]
|
||||
|
41
dom/abort/tests/test_abort_controller_fetch.html
Normal file
41
dom/abort/tests/test_abort_controller_fetch.html
Normal file
@ -0,0 +1,41 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test AbortController in Fetch API</title>
|
||||
<script type="text/javascript" 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">
|
||||
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.abortController.enabled", true ],
|
||||
["dom.abortController.fetch.enabled", true]]}, () => {
|
||||
let ifr = document.createElement('iframe');
|
||||
ifr.src = "file_abort_controller_fetch.html";
|
||||
document.body.appendChild(ifr);
|
||||
|
||||
onmessage = function(e) {
|
||||
if (e.data.type == "finish") {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.data.type == "check") {
|
||||
ok(e.data.status, e.data.message);
|
||||
return;
|
||||
}
|
||||
|
||||
ok(false, "Something when wrong.");
|
||||
}
|
||||
});
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -48,7 +48,7 @@ dictionary RequestInit {
|
||||
RequestRedirect redirect;
|
||||
DOMString integrity;
|
||||
|
||||
[Func="AbortController::IsEnabled"]
|
||||
[Func="AbortController::IsEnabledInFetch"]
|
||||
AbortSignal signal;
|
||||
|
||||
[Func="FetchObserver::IsEnabled"]
|
||||
|
@ -43,6 +43,7 @@ WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCR
|
||||
WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
|
||||
WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.abortController.enabled", AbortControllerEnabled, ABORTCONTROLLER_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.abortController.fetch.enabled", AbortControllerEnabledInFetch, ABORTCONTROLLER_FETCH_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)
|
||||
WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED)
|
||||
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
|
||||
|
Loading…
Reference in New Issue
Block a user