summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/responsexml-document-properties.htm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/xhr/responsexml-document-properties.htm
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/xhr/responsexml-document-properties.htm')
-rw-r--r--testing/web-platform/tests/xhr/responsexml-document-properties.htm123
1 files changed, 123 insertions, 0 deletions
diff --git a/testing/web-platform/tests/xhr/responsexml-document-properties.htm b/testing/web-platform/tests/xhr/responsexml-document-properties.htm
new file mode 100644
index 0000000000..a9f14f8212
--- /dev/null
+++ b/testing/web-platform/tests/xhr/responsexml-document-properties.htm
@@ -0,0 +1,123 @@
+<!doctype html>
+<html>
+ <head>
+ <title>XMLHttpRequest: responseXML document properties</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ </head>
+ <body>
+ <div id="log"></div>
+ <script>
+ var timePreXHR = Math.floor(new Date().getTime(new Date().getTime() - 3000) / 1000); // three seconds ago, in case there's clock drift
+ var client = new XMLHttpRequest()
+ client.open("GET", "resources/well-formed.xml", false)
+ client.send(null)
+ var responseURLObject = new URL('resources/well-formed.xml', location.href);
+ var responseURL = responseURLObject.href
+ var responseDomain = responseURLObject.hostname
+ var expected = {
+ domain:responseDomain,
+ URL:responseURL,
+ documentURI:responseURL,
+ baseURI:responseURL,
+ referrer:'',
+ title:'',
+ contentType:'application/xml',
+ readyState:'complete',
+ location:null,
+ defaultView:null,
+ body:null,
+ doctype:null,
+ all:HTMLAllCollection,
+ cookie:''
+ }
+
+ for (var name in expected) {
+ runTest(name, expected[name])
+ }
+
+ function runTest(name, value){
+ test(function(){
+ if (name == "all") {
+ assert_equals(Object.getPrototypeOf(client.responseXML[name]), value.prototype)
+ } else {
+ assert_equals(client.responseXML[name], value)
+ }
+ }, name)
+ }
+
+ // Parse a "lastModified" value and convert it to a Date.
+ // See https://html.spec.whatwg.org/multipage/dom.html#dom-document-lastmodified
+ function parseLastModified(value) {
+ const [undefined, month, day, year, hours, minutes, seconds] =
+ /^(\d\d)\/(\d\d)\/(\d+) (\d\d):(\d\d):(\d\d)$/.exec(value);
+ return new Date(year, month - 1, day, hours, minutes, seconds);
+ }
+
+ async_test(t => {
+ const client = new XMLHttpRequest();
+ client.open("GET", "resources/redirect.py?location=well-formed.xml");
+ client.send();
+ client.onload = t.step_func_done(() => {
+ assert_equals(client.responseXML.URL, responseURL);
+ assert_equals(client.responseXML.baseURI, responseURL);
+ });
+ }, "Test document URL properties after redirect");
+
+ async_test(t => {
+ const client = new XMLHttpRequest();
+ client.open("GET", "resources/redirect.py?location=base.xml");
+ client.send();
+ client.onload = t.step_func_done(() => {
+ const localResponseURL = new URL('resources/base.xml', location.href).href;
+ assert_equals(client.responseXML.URL, localResponseURL);
+ assert_equals(client.responseXML.baseURI, 'https://example.com/');
+ client.responseXML.documentElement.remove();
+ assert_equals(client.responseXML.baseURI, localResponseURL);
+ const newBase = document.createElement("base"),
+ newBaseURL = "https://elsewhere.example/";
+ newBase.href = "https://elsewhere.example/";
+ client.responseXML.appendChild(newBase);
+ assert_equals(client.responseXML.baseURI, newBaseURL);
+ newBase.remove();
+ document.head.appendChild(newBase);
+ assert_equals(client.responseXML.baseURI, localResponseURL);
+ newBase.remove();
+ });
+ }, "Test document URL properties of document with <base> after redirect");
+
+ test(function() {
+ var lastModified = Math.floor(parseLastModified(client.responseXML.lastModified).getTime() / 1000);
+ var now = Math.floor(new Date().getTime(new Date().getTime() + 3000) / 1000); // three seconds from now, in case there's clock drift
+ assert_greater_than_equal(lastModified, timePreXHR);
+ assert_less_than_equal(lastModified, now);
+ }, 'lastModified set to time of response if no HTTP header provided')
+
+ test(function() {
+ var client2 = new XMLHttpRequest()
+ client2.open("GET", "resources/last-modified.py", false)
+ client2.send(null)
+ assert_equals((new Date(client2.getResponseHeader('Last-Modified'))).getTime(), (parseLastModified(client2.responseXML.lastModified)).getTime())
+ }, 'lastModified set to related HTTP header if provided')
+
+ test(function() {
+ client.responseXML.cookie = "thisshouldbeignored"
+ assert_equals(client.responseXML.cookie, "")
+ }, 'cookie (after setting it)')
+
+ var objectProps = [
+ "styleSheets",
+ "implementation",
+ "images",
+ "forms",
+ "links",
+ ];
+
+ for (let prop of objectProps) {
+ test(function() {
+ assert_equals(typeof(client.responseXML[prop]), "object")
+ }, prop + " should be an object")
+ }
+ </script>
+ </body>
+</html>