From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../tests/element-timing/resources/TAOImage.py | 47 +++++++++++++ .../tests/element-timing/resources/circle-tao.svg | 6 ++ .../resources/circle-tao.svg.headers | 1 + .../tests/element-timing/resources/circle.svg | 6 ++ .../resources/element-timing-helpers.js | 74 +++++++++++++++++++++ .../resources/iframe-stores-entry.html | 12 ++++ .../resources/iframe-with-content.html | 5 ++ .../resources/iframe-with-square-sends-entry.html | 26 ++++++++ .../resources/iframe-with-square.html | 10 +++ .../element-timing/resources/multiple-redirects.py | 59 ++++++++++++++++ .../element-timing/resources/progressive-image.py | 27 ++++++++ .../tests/element-timing/resources/slow-image.py | 19 ++++++ .../tests/element-timing/resources/square100.png | Bin 0 -> 12940 bytes .../tests/element-timing/resources/square20.jpg | Bin 0 -> 529 bytes .../tests/element-timing/resources/square20.png | Bin 0 -> 150 bytes 15 files changed, 292 insertions(+) create mode 100644 testing/web-platform/tests/element-timing/resources/TAOImage.py create mode 100644 testing/web-platform/tests/element-timing/resources/circle-tao.svg create mode 100644 testing/web-platform/tests/element-timing/resources/circle-tao.svg.headers create mode 100644 testing/web-platform/tests/element-timing/resources/circle.svg create mode 100644 testing/web-platform/tests/element-timing/resources/element-timing-helpers.js create mode 100644 testing/web-platform/tests/element-timing/resources/iframe-stores-entry.html create mode 100644 testing/web-platform/tests/element-timing/resources/iframe-with-content.html create mode 100644 testing/web-platform/tests/element-timing/resources/iframe-with-square-sends-entry.html create mode 100644 testing/web-platform/tests/element-timing/resources/iframe-with-square.html create mode 100644 testing/web-platform/tests/element-timing/resources/multiple-redirects.py create mode 100644 testing/web-platform/tests/element-timing/resources/progressive-image.py create mode 100644 testing/web-platform/tests/element-timing/resources/slow-image.py create mode 100644 testing/web-platform/tests/element-timing/resources/square100.png create mode 100644 testing/web-platform/tests/element-timing/resources/square20.jpg create mode 100644 testing/web-platform/tests/element-timing/resources/square20.png (limited to 'testing/web-platform/tests/element-timing/resources') 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 @@ + + + + + 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 @@ + + + + + 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..cd0a023f04 --- /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'); + const rt_entries = performance.getEntriesByName(expectedUrl, 'resource'); + assert_equals(rt_entries.length, 1); + 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); +} + +// 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); + assert_equals(entry.naturalHeight, height); +} + +function checkTextElement(entry, expectedIdentifier, expectedID, beforeRender, + expectedElement) { + checkElementInternal(entry, '', expectedIdentifier, expectedID, beforeRender, + expectedElement); + assert_equals(entry.name, 'text-paint'); + assert_equals(entry.loadTime, 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 @@ + + + +

Text

+ + + 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 @@ + + +

Text

+ + 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 @@ + + + + + + + + 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 @@ + + + + + + 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 Binary files /dev/null and b/testing/web-platform/tests/element-timing/resources/square100.png 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 Binary files /dev/null and b/testing/web-platform/tests/element-timing/resources/square20.jpg 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 Binary files /dev/null and b/testing/web-platform/tests/element-timing/resources/square20.png differ -- cgit v1.2.3