diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/html/semantics/links/downloading-resources/header-origin.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/links/downloading-resources/header-origin.js')
-rw-r--r-- | testing/web-platform/tests/html/semantics/links/downloading-resources/header-origin.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/links/downloading-resources/header-origin.js b/testing/web-platform/tests/html/semantics/links/downloading-resources/header-origin.js new file mode 100644 index 0000000000..acc62ef93b --- /dev/null +++ b/testing/web-platform/tests/html/semantics/links/downloading-resources/header-origin.js @@ -0,0 +1,40 @@ +const RESOURCES_DIR = "/html/semantics/links/downloading-resources/resources/"; + +function testOriginHeader(expectedOrigin) { + var id = self.token(); + let testUrl = RESOURCES_DIR + "inspect-header.py?header=origin&cmd=put&id=" + id; + + promise_test(function(test) { + const anchor = document.getElementById("a"); + anchor.setAttribute("ping", testUrl); + anchor.click(); + return pollResult(id) .then(result => { + assert_equals(result, expectedOrigin, "Correct origin header result"); + }); + }, "Test origin header " + RESOURCES_DIR); +} + +// Sending a ping is an asynchronous and non-blocking request to a web server. +// We may have to create a poll loop to get result from server +function pollResult(id) { + let checkUrl = RESOURCES_DIR + "inspect-header.py?header=origin&cmd=get&id=" + id; + + return new Promise(resolve => { + function checkResult() { + fetch(checkUrl).then( + function(response) { + assert_equals(response.status, 200, "Inspect header response's status is 200"); + let result = response.headers.get("x-request-origin"); + + if (result != undefined) { + resolve(result); + } else { + step_timeout(checkResult.bind(this), 100); + } + }); + } + + checkResult(); + }); + +} |