forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1640914 [wpt PR 23771] - Python 3: port tests in resource-timing,…
… a=testonly Automatic update from web-platform-tests Python 3: port wptserve file handlers in resource-timing (#23771) -- wpt-commits: 258a3a54cbc88e72d32490328557fc3bf3e19c44 wpt-pr: 23771
- Loading branch information
1 parent
ebc9a64
commit 0cd6ef0
Showing
11 changed files
with
133 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 33 additions & 33 deletions
66
testing/web-platform/tests/resource-timing/resources/TAOResponse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
def main(request, response): | ||
origin = request.headers['origin'] | ||
response.headers.set('Access-Control-Allow-Origin', origin) | ||
origin = request.headers[b'origin'] | ||
response.headers.set(b'Access-Control-Allow-Origin', origin) | ||
|
||
tao = request.GET.first('tao') | ||
tao = request.GET.first(b'tao') | ||
|
||
if tao == 'zero': | ||
if tao == b'zero': | ||
# zero TAO value, fail | ||
pass | ||
elif tao == 'wildcard': | ||
elif tao == b'wildcard': | ||
# wildcard, pass | ||
response.headers.set('Timing-Allow-Origin', '*') | ||
elif tao == 'null': | ||
response.headers.set(b'Timing-Allow-Origin', b'*') | ||
elif tao == b'null': | ||
# null, fail unless it's an opaque origin | ||
response.headers.set('Timing-Allow-Origin', 'null') | ||
elif tao == 'Null': | ||
response.headers.set(b'Timing-Allow-Origin', b'null') | ||
elif tao == b'Null': | ||
# case-insentive null, fail | ||
response.headers.set('Timing-Allow-Origin', 'Null') | ||
elif tao == 'origin': | ||
response.headers.set(b'Timing-Allow-Origin', b'Null') | ||
elif tao == b'origin': | ||
# case-sensitive match for origin, pass | ||
response.headers.set('Timing-Allow-Origin', origin) | ||
elif tao.startswith('origin_port'): | ||
response.headers.set(b'Timing-Allow-Origin', origin) | ||
elif tao.startswith(b'origin_port'): | ||
# case-sensitive match for origin and port, pass | ||
origin_parts = origin.split(':') | ||
host = origin_parts[0] + ':' + origin_parts[1] | ||
port = tao.split('origin_port_')[1] | ||
response.headers.set('Timing-Allow-Origin', host + ':' + port) | ||
elif tao == 'space': | ||
origin_parts = origin.split(b':') | ||
host = origin_parts[0] + b':' + origin_parts[1] | ||
port = tao.split(b'origin_port_')[1] | ||
response.headers.set(b'Timing-Allow-Origin', host + b':' + port) | ||
elif tao == b'space': | ||
# space separated list of origin and wildcard, fail | ||
response.headers.set('Timing-Allow-Origin', (origin + ' *')) | ||
elif tao == 'multi': | ||
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('Timing-Allow-Origin', origin) | ||
response.headers.append('Timing-Allow-Origin', '*') | ||
elif tao == 'multi_wildcard': | ||
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('Timing-Allow-Origin', '*') | ||
response.headers.append('Timing-Allow-Origin', '*') | ||
elif tao == 'match_origin': | ||
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('Timing-Allow-Origin', origin) | ||
response.headers.append('Timing-Allow-Origin', "fake") | ||
elif tao == 'match_wildcard': | ||
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('Timing-Allow-Origin', "fake") | ||
response.headers.append('Timing-Allow-Origin', '*') | ||
elif tao == 'uppercase': | ||
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('Timing-Allow-Origin', origin.upper()) | ||
response.headers.set(b'Timing-Allow-Origin', origin.upper()) | ||
else: | ||
pass |
28 changes: 15 additions & 13 deletions
28
testing/web-platform/tests/resource-timing/resources/cors-ahem.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import os.path | ||
|
||
from wptserve.utils import isomorphic_decode | ||
|
||
def main(request, response): | ||
etag = "123abc" | ||
if etag == request.headers.get("If-None-Match", None): | ||
response.headers.set("X-HTTP-STATUS", 304) | ||
response.status = (304, "Not Modified") | ||
return "" | ||
etag = b"123abc" | ||
if etag == request.headers.get(b"If-None-Match", None): | ||
response.headers.set(b"X-HTTP-STATUS", 304) | ||
response.status = (304, u"Not Modified") | ||
return u"" | ||
|
||
response.headers.set("Cache-Control", "public, max-age=86400") | ||
response.headers.set("Content-Type", "font/truetype") | ||
response.headers.set("Access-Control-Allow-Origin", "*") | ||
response.headers.set("Timing-Allow-Origin", "*") | ||
response.headers.set("ETag", etag) | ||
font = "../../fonts/Ahem.ttf" | ||
path = os.path.join(os.path.dirname(__file__), font) | ||
response.content = open(path, "rb").read() | ||
response.headers.set(b"Cache-Control", b"public, max-age=86400") | ||
response.headers.set(b"Content-Type", b"font/truetype") | ||
response.headers.set(b"Access-Control-Allow-Origin", b"*") | ||
response.headers.set(b"Timing-Allow-Origin", b"*") | ||
response.headers.set(b"ETag", etag) | ||
font = u"../../fonts/Ahem.ttf" | ||
path = os.path.join(os.path.dirname(isomorphic_decode(__file__)), font) | ||
response.content = open(path, u"rb").read() |
4 changes: 2 additions & 2 deletions
4
testing/web-platform/tests/resource-timing/resources/empty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def main(request, response): | ||
response.headers.set("Content-Type", "text/plain") | ||
return "" | ||
response.headers.set(b"Content-Type", b"text/plain") | ||
return u"" |
4 changes: 2 additions & 2 deletions
4
testing/web-platform/tests/resource-timing/resources/eventsource.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def main(request, response): | ||
response.headers.set("Content-Type", "text/event-stream") | ||
return "" | ||
response.headers.set(b"Content-Type", b"text/event-stream") | ||
return u"" |
32 changes: 16 additions & 16 deletions
32
testing/web-platform/tests/resource-timing/resources/fake_responses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# /xhr/resources/conditional.py -- to fake a 304 response | ||
|
||
def main(request, response): | ||
tag = request.GET.first("tag", None) | ||
redirect = request.GET.first("redirect", None) | ||
match = request.headers.get("If-None-Match", None) | ||
date = request.GET.first("date", "") | ||
modified = request.headers.get("If-Modified-Since", None) | ||
response.headers.set("Access-Control-Allow-Origin", "*"); | ||
response.headers.set("Timing-Allow-Origin", "*"); | ||
tag = request.GET.first(b"tag", None) | ||
redirect = request.GET.first(b"redirect", None) | ||
match = request.headers.get(b"If-None-Match", None) | ||
date = request.GET.first(b"date", b"") | ||
modified = request.headers.get(b"If-Modified-Since", None) | ||
response.headers.set(b"Access-Control-Allow-Origin", b"*"); | ||
response.headers.set(b"Timing-Allow-Origin", b"*"); | ||
if tag: | ||
response.headers.set("ETag", '"%s"' % tag) | ||
response.headers.set(b"ETag", b'"%s"' % tag) | ||
elif date: | ||
response.headers.set("Last-Modified", date) | ||
response.headers.set(b"Last-Modified", date) | ||
if redirect: | ||
response.headers.set("Location", redirect) | ||
response.status = (302, "Moved") | ||
return "" | ||
response.headers.set(b"Location", redirect) | ||
response.status = (302, u"Moved") | ||
return u"" | ||
|
||
if ((match is not None and match == tag) or | ||
(modified is not None and modified == date)): | ||
response.status = (304, "SUPERCOOL") | ||
return "" | ||
response.status = (304, u"SUPERCOOL") | ||
return u"" | ||
else: | ||
response.headers.set("Content-Type", "text/plain") | ||
return "MAYBE NOT" | ||
response.headers.set(b"Content-Type", b"text/plain") | ||
return u"MAYBE NOT" |
21 changes: 12 additions & 9 deletions
21
testing/web-platform/tests/resource-timing/resources/gzip_xml.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import gzip as gzip_module | ||
from cStringIO import StringIO | ||
import os | ||
|
||
from six import BytesIO | ||
|
||
from wptserve.utils import isomorphic_decode | ||
|
||
def main(request, response): | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
file_path = os.path.join(dir_path, 'resource_timing_test0.xml') | ||
f = open(file_path, 'r') | ||
dir_path = os.path.dirname(os.path.realpath(isomorphic_decode(__file__))) | ||
file_path = os.path.join(dir_path, u'resource_timing_test0.xml') | ||
f = open(file_path, u'rb') | ||
output = f.read() | ||
|
||
out = StringIO() | ||
out = BytesIO() | ||
with gzip_module.GzipFile(fileobj=out, mode="w") as f: | ||
f.write(output) | ||
f.write(output) | ||
output = out.getvalue() | ||
|
||
headers = [("Content-type", "text/plain"), | ||
("Content-Encoding", "gzip"), | ||
("Content-Length", len(output))] | ||
headers = [(b"Content-type", b"text/plain"), | ||
(b"Content-Encoding", b"gzip"), | ||
(b"Content-Length", len(output))] | ||
|
||
return headers, output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
testing/web-platform/tests/resource-timing/resources/preflight.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
def main(request, response): | ||
response.headers.set("Access-Control-Allow-Origin", "*"); | ||
response.headers.set("Access-Control-Max-Age", "0"); | ||
response.headers.set("Timing-Allow-Origin", "*"); | ||
response.headers.set(b"Access-Control-Allow-Origin", b"*"); | ||
response.headers.set(b"Access-Control-Max-Age", b"0"); | ||
response.headers.set(b"Timing-Allow-Origin", b"*"); | ||
# If this script is accessed with the header X-Require-Preflight then the | ||
# browser will send a preflight request. Otherwise it won't. | ||
if request.method == 'OPTIONS': | ||
response.headers.set("Access-Control-Allow-Headers", "X-Require-Preflight"); | ||
if request.method == u'OPTIONS': | ||
response.headers.set(b"Access-Control-Allow-Headers", b"X-Require-Preflight"); |
4 changes: 2 additions & 2 deletions
4
testing/web-platform/tests/resource-timing/resources/status-code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
def main(request, response): | ||
status = request.GET.first('status') | ||
response.status = (status, ""); | ||
status = request.GET.first(b'status') | ||
response.status = (status, b""); | ||
|