summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/element-timing/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/element-timing/resources
parentInitial commit. (diff)
downloadfirefox-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/element-timing/resources')
-rw-r--r--testing/web-platform/tests/element-timing/resources/TAOImage.py47
-rw-r--r--testing/web-platform/tests/element-timing/resources/circle-tao.svg6
-rw-r--r--testing/web-platform/tests/element-timing/resources/circle-tao.svg.headers1
-rw-r--r--testing/web-platform/tests/element-timing/resources/circle.svg6
-rw-r--r--testing/web-platform/tests/element-timing/resources/element-timing-helpers.js74
-rw-r--r--testing/web-platform/tests/element-timing/resources/iframe-stores-entry.html12
-rw-r--r--testing/web-platform/tests/element-timing/resources/iframe-with-content.html5
-rw-r--r--testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html26
-rw-r--r--testing/web-platform/tests/element-timing/resources/iframe-with-square.html10
-rw-r--r--testing/web-platform/tests/element-timing/resources/multiple-redirects.py59
-rw-r--r--testing/web-platform/tests/element-timing/resources/progressive-image.py27
-rw-r--r--testing/web-platform/tests/element-timing/resources/slow-image.py19
-rw-r--r--testing/web-platform/tests/element-timing/resources/square100.pngbin0 -> 12940 bytes
-rw-r--r--testing/web-platform/tests/element-timing/resources/square20.jpgbin0 -> 529 bytes
-rw-r--r--testing/web-platform/tests/element-timing/resources/square20.pngbin0 -> 150 bytes
15 files changed, 292 insertions, 0 deletions
diff --git a/testing/web-platform/tests/element-timing/resources/TAOImage.py b/testing/web-platform/tests/element-timing/resources/TAOImage.py
new file mode 100644
index 0000000000..0e1c481489
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/TAOImage.py
@@ -0,0 +1,47 @@
+import os
+
+from wptserve.utils import isomorphic_encode
+
+def main(request, response):
+ origin = request.GET.first(b'origin')
+ if origin:
+ response.headers.set(b'Access-Control-Allow-Origin', origin)
+
+ tao = request.GET.first(b'tao')
+
+ if tao == b'wildcard':
+ # wildcard, pass
+ response.headers.set(b'Timing-Allow-Origin', b'*')
+ elif tao == b'null':
+ # null, fail
+ response.headers.set(b'Timing-Allow-Origin', b'null')
+ elif tao == b'origin':
+ # case-sensitive match for origin, pass
+ response.headers.set(b'Timing-Allow-Origin', origin)
+ elif tao == b'space':
+ # space separated list of origin and wildcard, fail
+ response.headers.set(b'Timing-Allow-Origin', (origin + b' *'))
+ elif tao == b'multi':
+ # more than one TAO values, separated by comma, pass
+ response.headers.set(b'Timing-Allow-Origin', origin)
+ response.headers.append(b'Timing-Allow-Origin', b'*')
+ elif tao == b'multi_wildcard':
+ # multiple wildcards, separated by comma, pass
+ response.headers.set(b'Timing-Allow-Origin', b'*')
+ response.headers.append(b'Timing-Allow-Origin', b'*')
+ elif tao == b'match_origin':
+ # contains a match of origin, separated by comma, pass
+ response.headers.set(b'Timing-Allow-Origin', origin)
+ response.headers.append(b'Timing-Allow-Origin', b"fake")
+ elif tao == b'match_wildcard':
+ # contains a wildcard, separated by comma, pass
+ response.headers.set(b'Timing-Allow-Origin', b"fake")
+ response.headers.append(b'Timing-Allow-Origin', b'*')
+ elif tao == b'uppercase':
+ # non-case-sensitive match for origin, fail
+ response.headers.set(b'Timing-Allow-Origin', origin.upper())
+ else:
+ pass
+ response.headers.set(b"Cache-Control", b"no-cache, must-revalidate");
+ image_path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), b"square100.png");
+ response.content = open(image_path, mode=u'rb').read();
diff --git a/testing/web-platform/tests/element-timing/resources/circle-tao.svg b/testing/web-platform/tests/element-timing/resources/circle-tao.svg
new file mode 100644
index 0000000000..209b9f4e5b
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/circle-tao.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
+ "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
+ <circle cx="50%" cy="50%" r="80" style="fill:blue;" />
+</svg>
diff --git a/testing/web-platform/tests/element-timing/resources/circle-tao.svg.headers b/testing/web-platform/tests/element-timing/resources/circle-tao.svg.headers
new file mode 100644
index 0000000000..7296361df3
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/circle-tao.svg.headers
@@ -0,0 +1 @@
+Timing-Allow-Origin: *
diff --git a/testing/web-platform/tests/element-timing/resources/circle.svg b/testing/web-platform/tests/element-timing/resources/circle.svg
new file mode 100644
index 0000000000..209b9f4e5b
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/circle.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
+ "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
+ <circle cx="50%" cy="50%" r="80" style="fill:blue;" />
+</svg>
diff --git a/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js b/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js
new file mode 100644
index 0000000000..8175b0f385
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/element-timing-helpers.js
@@ -0,0 +1,74 @@
+// Common checks between checkElement() and checkElementWithoutResourceTiming().
+function checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
+ expectedElement) {
+ assert_equals(entry.entryType, 'element', 'entryType does not match');
+ assert_equals(entry.url, expectedUrl, 'url does not match');
+ assert_equals(entry.identifier, expectedIdentifier, 'identifier does not match');
+ if (beforeRender != 0) {
+ // In this case, renderTime is not 0.
+ assert_greater_than(entry.renderTime, 0, 'renderTime should be nonzero');
+ assert_equals(entry.startTime, entry.renderTime, 'startTime should equal renderTime');
+ } else {
+ // In this case, renderTime is 0, so compare to loadTime.
+ assert_equals(entry.renderTime, 0, 'renderTime should be zero');
+ assert_equals(entry.startTime, entry.loadTime, 'startTime should equal loadTime');
+ }
+ assert_equals(entry.duration, 0, 'duration should be 0');
+ assert_equals(entry.id, expectedID, 'id does not match');
+ assert_greater_than_equal(entry.renderTime, beforeRender, 'renderTime greater than beforeRender');
+ assert_greater_than_equal(performance.now(), entry.renderTime, 'renderTime bounded by now()');
+ if (expectedElement !== null) {
+ assert_equals(entry.element, expectedElement, 'element does not match');
+ assert_equals(entry.identifier, expectedElement.elementTiming,
+ 'identifier must be the elementtiming of the element');
+ assert_equals(entry.id, expectedElement.id, 'id must be the id of the element');
+ }
+}
+
+// Checks that this is an ElementTiming entry with url |expectedUrl|. It also
+// does a very basic check on |renderTime|: after |beforeRender| and before now().
+function checkElement(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
+ expectedElement) {
+ checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
+ expectedElement);
+ assert_equals(entry.name, 'image-paint', 'The entry name should be image-paint.');
+ const rt_entries = performance.getEntriesByName(expectedUrl, 'resource');
+ assert_equals(rt_entries.length, 1, 'There should be only 1 resource entry.');
+ assert_greater_than_equal(entry.loadTime, rt_entries[0].responseEnd,
+ 'Image loadTime is after the resource responseEnd');
+}
+
+function checkElementWithoutResourceTiming(entry, expectedUrl, expectedIdentifier,
+ expectedID, beforeRender, expectedElement) {
+ checkElementInternal(entry, expectedUrl, expectedIdentifier, expectedID, beforeRender,
+ expectedElement);
+ assert_equals(entry.name, 'image-paint');
+ // No associated resource from ResourceTiming, so not much to compare loadTime with.
+ assert_greater_than(entry.loadTime, 0, 'The entry loadTime should be greater than 0.');
+}
+
+// Checks that the rect matches the desired values [left right top bottom].
+function checkRect(entry, expected, description="") {
+ assert_equals(entry.intersectionRect.left, expected[0],
+ 'left of rect ' + description);
+ assert_equals(entry.intersectionRect.right, expected[1],
+ 'right of rect ' + description);
+ assert_equals(entry.intersectionRect.top, expected[2],
+ 'top of rect ' + description);
+ assert_equals(entry.intersectionRect.bottom, expected[3],
+ 'bottom of rect ' + description);
+}
+
+// Checks that the intrinsic size matches the desired values.
+function checkNaturalSize(entry, width, height) {
+ assert_equals(entry.naturalWidth, width, 'The entry naturalWidth is not as expected.');
+ assert_equals(entry.naturalHeight, height, 'The entry naturalHeight is not as expected.');
+}
+
+function checkTextElement(entry, expectedIdentifier, expectedID, beforeRender,
+ expectedElement) {
+ checkElementInternal(entry, '', expectedIdentifier, expectedID, beforeRender,
+ expectedElement);
+ assert_equals(entry.name, 'text-paint', 'The entry name should be text-paint.');
+ assert_equals(entry.loadTime, 0, 'The entry loadTime should be 0.');
+}
diff --git a/testing/web-platform/tests/element-timing/resources/iframe-stores-entry.html b/testing/web-platform/tests/element-timing/resources/iframe-stores-entry.html
new file mode 100644
index 0000000000..2fa2476972
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/iframe-stores-entry.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p elementtiming='text'>Text</p>
+<script>
+ const observer = new PerformanceObserver(entryList => {
+ window.parent.triggerTest(entryList.getEntries()[0]);
+ });
+ observer.observe({type: 'element', buffered: true});
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/element-timing/resources/iframe-with-content.html b/testing/web-platform/tests/element-timing/resources/iframe-with-content.html
new file mode 100644
index 0000000000..ab8cdfde01
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/iframe-with-content.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<body>
+<p>Text</p>
+<img src='/images/blue.png'/>
+</body>
diff --git a/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html b/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html
new file mode 100644
index 0000000000..b8af505d32
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html
@@ -0,0 +1,26 @@
+<!DOCType html>
+<html>
+<style>
+body {
+ margin: 0;
+}
+</style>
+<body>
+<script>
+ const observer = new PerformanceObserver(entryList => {
+ top.postMessage({
+ 'length' : entryList.getEntries().length,
+ 'entryType' : entryList.getEntries()[0].entryType,
+ 'rect' : entryList.getEntries()[0].intersectionRect,
+ 'naturalWidth' : entryList.getEntries()[0].naturalWidth,
+ 'naturalHeight' : entryList.getEntries()[0].naturalHeight,
+ 'id': entryList.getEntries()[0].id,
+ // Elements cannot be cloned, so just send the element ID.
+ 'elementId' : entryList.getEntries()[0].element.id,
+ }, '*');
+ });
+ observer.observe({entryTypes: ['element']});
+</script>
+<img src=square100.png id=iframe_img_id elementtiming=my_image/>
+</body>
+</html>
diff --git a/testing/web-platform/tests/element-timing/resources/iframe-with-square.html b/testing/web-platform/tests/element-timing/resources/iframe-with-square.html
new file mode 100644
index 0000000000..0a905d22b9
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/iframe-with-square.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<meta charset=utf-8>
+<body>
+<style>
+body {
+ margin: 0;
+}
+</style>
+<img src='square100.png' elementtiming="my_image">
+</body>
diff --git a/testing/web-platform/tests/element-timing/resources/multiple-redirects.py b/testing/web-platform/tests/element-timing/resources/multiple-redirects.py
new file mode 100644
index 0000000000..3efc634b99
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/multiple-redirects.py
@@ -0,0 +1,59 @@
+from wptserve.utils import isomorphic_encode
+
+def main(request, response):
+ """Handler that causes multiple redirections.
+
+ Mandatory parameters:
+ redirect_count - A number which is at least 1 (number of redirects).
+ final_resource - The location of the last redirect.
+
+ For each number i between 1 and |redirect_count| we have the following optional parameters:
+ tao{{i}} - The Timing-Allow-Origin header of the ith response. Default is no header.
+ origin{{i}} - The origin of the ith redirect (i+1 response). Default is location.origin.
+ Note that the origin of the initial request cannot be controlled here
+ and the Timing-Allow-Origin header of the final response cannot be controlled here.
+
+ Example: redirect_count=2&final_resource=miau.png&tao1=*
+
+ Note: |step| is used internally to track the current redirect number.
+ """
+ step = 1
+ if b"step" in request.GET:
+ try:
+ step = int(request.GET.first(b"step"))
+ except ValueError:
+ pass
+
+ redirect_count = int(request.GET.first(b"redirect_count"))
+ final_resource = request.GET.first(b"final_resource")
+
+ tao_value = None
+ tao = b"tao" + isomorphic_encode(str(step))
+ if tao in request.GET:
+ tao_value = request.GET.first(tao)
+
+ redirect_url = b""
+ origin = b"origin" + isomorphic_encode(str(step))
+ if origin in request.GET:
+ redirect_url = request.GET.first(origin)
+
+ if step == redirect_count:
+ redirect_url += final_resource
+ else:
+ redirect_url += b"/element-timing/resources/multiple-redirects.py?"
+ redirect_url += b"redirect_count=" + isomorphic_encode(str(redirect_count))
+ redirect_url += b"&final_resource=" + final_resource
+ for i in range(1, redirect_count + 1):
+ tao = b"tao" + isomorphic_encode(str(i))
+ if tao in request.GET:
+ redirect_url += b"&" + tao + b"=" + request.GET.first(tao)
+ origin = b"origin" + isomorphic_encode(str(i))
+ if origin in request.GET:
+ redirect_url += b"&" + origin + b"=" + request.GET.first(origin)
+ redirect_url += b"&step=" + isomorphic_encode(str(step + 1))
+
+ if tao_value:
+ response.headers.set(b"timing-allow-origin", tao_value)
+
+ response.status = 302
+ response.headers.set(b"Location", redirect_url)
diff --git a/testing/web-platform/tests/element-timing/resources/progressive-image.py b/testing/web-platform/tests/element-timing/resources/progressive-image.py
new file mode 100644
index 0000000000..84e98c8451
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/progressive-image.py
@@ -0,0 +1,27 @@
+import os.path
+import time
+
+from wptserve.utils import isomorphic_encode
+
+def main(request, response):
+ name = request.GET.first(b"name")
+ sleepTime = float(request.GET.first(b"sleep")) / 1E3
+ numInitial = int(request.GET.first(b"numInitial"))
+
+ path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), name)
+ body = open(path, u"rb").read()
+
+ response.headers.set(b"Content-Type", b"image")
+ response.headers.set(b"Content-Length", len(body))
+ response.headers.set(b"Cache-control", b"no-cache, must-revalidate")
+ response.write_status_headers()
+
+ # Read from the beginning, |numInitial| bytes.
+ first = body[:numInitial]
+ response.writer.write_content(first)
+
+ time.sleep(sleepTime)
+
+ # Read the remainder after having slept.
+ second = body[numInitial:]
+ response.writer.write_content(second)
diff --git a/testing/web-platform/tests/element-timing/resources/slow-image.py b/testing/web-platform/tests/element-timing/resources/slow-image.py
new file mode 100644
index 0000000000..10172fd35a
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/slow-image.py
@@ -0,0 +1,19 @@
+import os.path
+import time
+
+from wptserve.utils import isomorphic_encode
+
+def main(request, response):
+ name = request.GET.first(b"name")
+ sleepTime = float(request.GET.first(b"sleep")) / 1E3
+
+ time.sleep(sleepTime)
+
+ path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), name)
+ body = open(path, u"rb").read()
+
+ response.headers.set(b"Content-Type", b"image")
+ response.headers.set(b"Content-Length", len(body))
+ response.headers.set(b"Cache-control", b"no-cache, must-revalidate")
+
+ response.content = body;
diff --git a/testing/web-platform/tests/element-timing/resources/square100.png b/testing/web-platform/tests/element-timing/resources/square100.png
new file mode 100644
index 0000000000..567babb96d
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/square100.png
Binary files differ
diff --git a/testing/web-platform/tests/element-timing/resources/square20.jpg b/testing/web-platform/tests/element-timing/resources/square20.jpg
new file mode 100644
index 0000000000..83ed4914bb
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/square20.jpg
Binary files differ
diff --git a/testing/web-platform/tests/element-timing/resources/square20.png b/testing/web-platform/tests/element-timing/resources/square20.png
new file mode 100644
index 0000000000..4d51ac4b46
--- /dev/null
+++ b/testing/web-platform/tests/element-timing/resources/square20.png
Binary files differ