diff options
Diffstat (limited to 'testing/web-platform/tests/referrer-policy/generic/subresource')
7 files changed, 0 insertions, 246 deletions
diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/__init__.py b/testing/web-platform/tests/referrer-policy/generic/subresource/__init__.py deleted file mode 100755 index e69de29bb..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/__init__.py +++ /dev/null diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/document.py b/testing/web-platform/tests/referrer-policy/generic/subresource/document.py deleted file mode 100644 index b2d6c4dfa..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/document.py +++ /dev/null @@ -1,12 +0,0 @@ -import os, json, sys -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) - -import subresource - -def generate_payload(server_data): - return subresource.get_template("document.html.template") % server_data - -def main(request, response): - subresource.respond(request, - response, - payload_generator = generate_payload) diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/image.py b/testing/web-platform/tests/referrer-policy/generic/subresource/image.py deleted file mode 100644 index b6306181e..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/image.py +++ /dev/null @@ -1,100 +0,0 @@ -import os, sys, array, json, math, StringIO -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import subresource - -class Image: - """This class partially implements the interface of the PIL.Image.Image. - One day in the future WPT might support the PIL module or another imaging - library, so this hacky BMP implementation will no longer be required. - """ - def __init__(self, width, height): - self.width = width - self.height = height - self.img = bytearray([0 for i in range(3 * width * height)]) - - @staticmethod - def new(mode, size, color=0): - return Image(size[0], size[1]) - - def _int_to_bytes(self, number): - packed_bytes = [0, 0, 0, 0] - for i in range(4): - packed_bytes[i] = number & 0xFF - number >>= 8 - - return packed_bytes - - def putdata(self, color_data): - for y in range(self.height): - for x in range(self.width): - i = x + y * self.width - if i > len(color_data) - 1: - return - - self.img[i * 3: i * 3 + 3] = color_data[i][::-1] - - def save(self, f, type): - assert type == "BMP" - # 54 bytes of preambule + image color data. - filesize = 54 + 3 * self.width * self.height; - # 14 bytes of header. - bmpfileheader = bytearray(['B', 'M'] + self._int_to_bytes(filesize) + - [0, 0, 0, 0, 54, 0, 0, 0]) - # 40 bytes of info. - bmpinfoheader = bytearray([40, 0, 0, 0] + - self._int_to_bytes(self.width) + - self._int_to_bytes(self.height) + - [1, 0, 24] + (25 * [0])) - - padlength = (4 - (self.width * 3) % 4) % 4 - bmppad = bytearray([0, 0, 0]); - padding = bmppad[0 : padlength] - - f.write(bmpfileheader) - f.write(bmpinfoheader) - - for i in range(self.height): - offset = self.width * (self.height - i - 1) * 3 - f.write(self.img[offset : offset + 3 * self.width]) - f.write(padding) - -def encode_string_as_bmp_image(string_data): - data_bytes = array.array("B", string_data) - num_bytes = len(data_bytes) - - # Convert data bytes to color data (RGB). - color_data = [] - num_components = 3 - rgb = [0] * num_components - i = 0 - for byte in data_bytes: - component_index = i % num_components - rgb[component_index] = byte - if component_index == (num_components - 1) or i == (num_bytes - 1): - color_data.append(tuple(rgb)) - rgb = [0] * num_components - i += 1 - - # Render image. - num_pixels = len(color_data) - sqrt = int(math.ceil(math.sqrt(num_pixels))) - img = Image.new("RGB", (sqrt, sqrt), "black") - img.putdata(color_data) - - # Flush image to string. - f = StringIO.StringIO() - img.save(f, "BMP") - f.seek(0) - - return f.read() - -def generate_payload(server_data): - data = ('{"headers": %(headers)s}') % server_data - return encode_string_as_bmp_image(data) - -def main(request, response): - subresource.respond(request, - response, - payload_generator = generate_payload, - content_type = "image/bmp", - access_control_allow_origin = "*") diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/script.py b/testing/web-platform/tests/referrer-policy/generic/subresource/script.py deleted file mode 100644 index efa1a955d..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/script.py +++ /dev/null @@ -1,13 +0,0 @@ -import os, sys, json -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import subresource - -def generate_payload(server_data): - return subresource.get_template("script.js.template") % server_data - -def main(request, response): - subresource.respond(request, - response, - payload_generator = generate_payload, - content_type = "application/javascript") - diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/subresource.py b/testing/web-platform/tests/referrer-policy/generic/subresource/subresource.py deleted file mode 100644 index 7571b32d0..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/subresource.py +++ /dev/null @@ -1,94 +0,0 @@ -import os, sys, json, urlparse, urllib - -def get_template(template_basename): - script_directory = os.path.dirname(os.path.abspath(__file__)) - template_directory = os.path.abspath(os.path.join(script_directory, - "..", - "template")) - template_filename = os.path.join(template_directory, template_basename); - - with open(template_filename, "r") as f: - return f.read() - -# TODO(kristijanburnik): subdomain_prefix is a hardcoded value aligned with -# referrer-policy-test-case.js. The prefix should be configured in one place. -def get_swapped_origin_netloc(netloc, subdomain_prefix = "www1."): - if netloc.startswith(subdomain_prefix): - return netloc[len(subdomain_prefix):] - else: - return subdomain_prefix + netloc - -def create_redirect_url(request, cross_origin = False): - parsed = urlparse.urlsplit(request.url) - destination_netloc = parsed.netloc - if cross_origin: - destination_netloc = get_swapped_origin_netloc(parsed.netloc) - - destination_url = urlparse.urlunsplit(urlparse.SplitResult( - scheme = parsed.scheme, - netloc = destination_netloc, - path = parsed.path, - query = None, - fragment = None)) - - return destination_url - - -def redirect(url, response): - response.add_required_headers = False - response.writer.write_status(301) - response.writer.write_header("access-control-allow-origin", "*") - response.writer.write_header("location", url) - response.writer.end_headers() - response.writer.write("") - - -def preprocess_redirection(request, response): - if "redirection" not in request.GET: - return False - - redirection = request.GET["redirection"] - - if redirection == "no-redirect": - return False - elif redirection == "keep-origin-redirect": - redirect_url = create_redirect_url(request, cross_origin = False) - elif redirection == "swap-origin-redirect": - redirect_url = create_redirect_url(request, cross_origin = True) - else: - raise ValueError("Invalid redirection type '%s'" % redirection) - - redirect(redirect_url, response) - return True - - -def __noop(request, response): - return "" - - -def respond(request, - response, - status_code = 200, - content_type = "text/html", - payload_generator = __noop, - cache_control = "no-cache; must-revalidate", - access_control_allow_origin = "*"): - if preprocess_redirection(request, response): - return - - response.add_required_headers = False - response.writer.write_status(status_code) - - if access_control_allow_origin != None: - response.writer.write_header("access-control-allow-origin", - access_control_allow_origin) - response.writer.write_header("content-type", content_type) - response.writer.write_header("cache-control", cache_control) - response.writer.end_headers() - - server_data = {"headers": json.dumps(request.headers, indent = 4)} - - payload = payload_generator(server_data) - response.writer.write(payload) - - diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/worker.py b/testing/web-platform/tests/referrer-policy/generic/subresource/worker.py deleted file mode 100644 index 895bc0d84..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/worker.py +++ /dev/null @@ -1,12 +0,0 @@ -import os, sys, json -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import subresource - -def generate_payload(server_data): - return subresource.get_template("worker.js.template") % server_data - -def main(request, response): - subresource.respond(request, - response, - payload_generator = generate_payload, - content_type = "application/javascript") diff --git a/testing/web-platform/tests/referrer-policy/generic/subresource/xhr.py b/testing/web-platform/tests/referrer-policy/generic/subresource/xhr.py deleted file mode 100755 index 45f38159c..000000000 --- a/testing/web-platform/tests/referrer-policy/generic/subresource/xhr.py +++ /dev/null @@ -1,15 +0,0 @@ -import os, sys, json -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) -import subresource - -def generate_payload(server_data): - data = ('{"headers": %(headers)s}') % server_data - return data - -def main(request, response): - subresource.respond(request, - response, - payload_generator = generate_payload, - access_control_allow_origin = "*", - content_type = "application/json") - |