diff --git a/test/fixtures/wpt/fetch/api/idlharness.https.any.js b/test/fixtures/wpt/fetch/api/idlharness.https.any.js new file mode 100644 index 000000000000..7b3c694e16ac --- /dev/null +++ b/test/fixtures/wpt/fetch/api/idlharness.https.any.js @@ -0,0 +1,21 @@ +// META: global=window,worker +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +idl_test( + ['fetch'], + ['referrer-policy', 'html', 'dom'], + idl_array => { + idl_array.add_objects({ + Headers: ["new Headers()"], + Request: ["new Request('about:blank')"], + Response: ["new Response()"], + }); + if (self.GLOBAL.isWindow()) { + idl_array.add_objects({ Window: ['window'] }); + } else if (self.GLOBAL.isWorker()) { + idl_array.add_objects({ WorkerGlobalScope: ['self'] }); + } + } +); diff --git a/test/fixtures/wpt/interfaces/fetch.idl b/test/fixtures/wpt/interfaces/fetch.idl new file mode 100644 index 000000000000..29056f1bf099 --- /dev/null +++ b/test/fixtures/wpt/interfaces/fetch.idl @@ -0,0 +1,133 @@ +// GENERATED CONTENT - DO NOT EDIT +// Content was automatically extracted by Reffy into webref +// (https://github.com/w3c/webref) +// Source: Fetch Standard (https://fetch.spec.whatwg.org/) + +typedef (sequence> or record) HeadersInit; + +[Exposed=(Window,Worker)] +interface Headers { + constructor(optional HeadersInit init); + + undefined append(ByteString name, ByteString value); + undefined delete(ByteString name); + ByteString? get(ByteString name); + sequence getSetCookie(); + boolean has(ByteString name); + undefined set(ByteString name, ByteString value); + iterable; +}; + +typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) XMLHttpRequestBodyInit; + +typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit; +interface mixin Body { + readonly attribute ReadableStream? body; + readonly attribute boolean bodyUsed; + [NewObject] Promise arrayBuffer(); + [NewObject] Promise blob(); + [NewObject] Promise bytes(); + [NewObject] Promise formData(); + [NewObject] Promise json(); + [NewObject] Promise text(); + [NewObject] ReadableStream textStream(); +}; +typedef (Request or USVString) RequestInfo; + +[Exposed=(Window,Worker)] +interface Request { + constructor(RequestInfo input, optional RequestInit init = {}); + + readonly attribute ByteString method; + readonly attribute USVString url; + [SameObject] readonly attribute Headers headers; + + readonly attribute RequestDestination destination; + readonly attribute USVString referrer; + readonly attribute ReferrerPolicy referrerPolicy; + readonly attribute RequestMode mode; + readonly attribute RequestCredentials credentials; + readonly attribute RequestCache cache; + readonly attribute RequestRedirect redirect; + readonly attribute DOMString integrity; + readonly attribute boolean keepalive; + readonly attribute boolean isReloadNavigation; + readonly attribute boolean isHistoryNavigation; + readonly attribute AbortSignal signal; + readonly attribute RequestDuplex duplex; + + [NewObject] Request clone(); +}; +Request includes Body; + +dictionary RequestInit { + ByteString method; + HeadersInit headers; + BodyInit? body; + USVString referrer; + ReferrerPolicy referrerPolicy; + RequestMode mode; + RequestCredentials credentials; + RequestCache cache; + RequestRedirect redirect; + DOMString integrity; + boolean keepalive; + AbortSignal? signal; + RequestDuplex duplex; + RequestPriority priority; + any window; // can only be set to null +}; + +enum RequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "frame", "iframe", "image", "json", "manifest", "object", "paintworklet", "report", "script", "sharedworker", "style", "text", "track", "video", "worker", "xslt" }; +enum RequestMode { "navigate", "same-origin", "no-cors", "cors" }; +enum RequestCredentials { "omit", "same-origin", "include" }; +enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" }; +enum RequestRedirect { "follow", "error", "manual" }; +enum RequestDuplex { "half" }; +enum RequestPriority { "high", "low", "auto" }; + +[Exposed=(Window,Worker)] +interface Response { + constructor(optional BodyInit? body = null, optional ResponseInit init = {}); + + [NewObject] static Response error(); + [NewObject] static Response redirect(USVString url, optional unsigned short status = 302); + [NewObject] static Response json(any data, optional ResponseInit init = {}); + + readonly attribute ResponseType type; + + readonly attribute USVString url; + readonly attribute boolean redirected; + readonly attribute unsigned short status; + readonly attribute boolean ok; + readonly attribute ByteString statusText; + [SameObject] readonly attribute Headers headers; + + [NewObject] Response clone(); +}; +Response includes Body; + +dictionary ResponseInit { + unsigned short status = 200; + ByteString statusText = ""; + HeadersInit headers; +}; + +enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" }; + +partial interface mixin WindowOrWorkerGlobalScope { + [NewObject] Promise fetch(RequestInfo input, optional RequestInit init = {}); +}; + +dictionary DeferredRequestInit : RequestInit { + DOMHighResTimeStamp activateAfter; +}; + +[Exposed=Window] +interface FetchLaterResult { + readonly attribute boolean activated; +}; + +partial interface Window { + [NewObject, SecureContext] FetchLaterResult fetchLater(RequestInfo input, optional DeferredRequestInit init = {}); +}; diff --git a/test/fixtures/wpt/interfaces/referrer-policy.idl b/test/fixtures/wpt/interfaces/referrer-policy.idl new file mode 100644 index 000000000000..0ef9a1fdecc8 --- /dev/null +++ b/test/fixtures/wpt/interfaces/referrer-policy.idl @@ -0,0 +1,16 @@ +// GENERATED CONTENT - DO NOT EDIT +// Content was automatically extracted by Reffy into webref +// (https://github.com/w3c/webref) +// Source: Referrer Policy (https://w3c.github.io/webappsec-referrer-policy/) + +enum ReferrerPolicy { + "", + "no-referrer", + "no-referrer-when-downgrade", + "same-origin", + "origin", + "strict-origin", + "origin-when-cross-origin", + "strict-origin-when-cross-origin", + "unsafe-url" +}; diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index 711d469cc367..e3665894bf81 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -23,6 +23,10 @@ "commit": "1ac8deee082ecfb5d3b6f9c56cf9d1688a2fc218", "path": "encoding" }, + "fetch/api": { + "commit": "3f15e5c09448b8e917c9128d3b07cc78f044c83a", + "path": "fetch/api" + }, "fetch/data-urls/resources": { "commit": "7c79d998ff42e52de90290cb847d1b515b3b58f7", "path": "fetch/data-urls/resources" diff --git a/test/wpt/status/fetch/api.json b/test/wpt/status/fetch/api.json new file mode 100644 index 000000000000..271dd10d8cc1 --- /dev/null +++ b/test/wpt/status/fetch/api.json @@ -0,0 +1,25 @@ +{ + "idlharness.https.any.html": { + "fail": { + "note": "fetchLater() and FetchLaterResult are not implemented", + "expected": [ + "FetchLaterResult interface: existence and properties of interface object", + "FetchLaterResult interface object length", + "FetchLaterResult interface object name", + "FetchLaterResult interface: existence and properties of interface prototype object", + "FetchLaterResult interface: existence and properties of interface prototype object's \"constructor\" property", + "FetchLaterResult interface: existence and properties of interface prototype object's @@unscopables property", + "FetchLaterResult interface: attribute activated", + "Window interface: operation fetchLater(RequestInfo, optional DeferredRequestInit)" + ] + } + }, + "idlharness.https.any.worker.html": { + "fail": { + "note": "fetch is an own property of the worker global, not of WorkerGlobalScope.prototype", + "expected": [ + "WorkerGlobalScope interface: operation fetch(RequestInfo, optional RequestInit)" + ] + } + } +} diff --git a/test/wpt/test-fetch.js b/test/wpt/test-fetch.js new file mode 100644 index 000000000000..5cf803f82980 --- /dev/null +++ b/test/wpt/test-fetch.js @@ -0,0 +1,13 @@ +'use strict'; + +const { WPTRunner } = require('../common/wpt'); + +const runner = new WPTRunner('fetch/api'); + +runner.pretendGlobalThisAs('Window'); +// The window harness does not define GLOBAL.isWorker(). The idlharness +// setup calls it when isWindow() is false. +runner.setInitScript( + 'globalThis.GLOBAL.isWorker = function() { return false; };', +); +runner.runJsTests();