Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/common/large.py

Issue 2015623004: Import wpt@ed94c51f3dfaa5ff4c9c311add1a560408059c51 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/common/large.py
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/common/large.py b/third_party/WebKit/LayoutTests/imported/wpt/common/large.py
new file mode 100644
index 0000000000000000000000000000000000000000..0db4e4bbd1cf08e61e7a74d8919b29395e358d37
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/common/large.py
@@ -0,0 +1,45 @@
+def main(request, response):
+ """Code for generating large responses where the actual response data
+ isn't very important.
+
+ Two request parameters:
+ size (required): An integer number of bytes (no suffix) or kilobytes
+ ("kb" suffix) or megabytes ("Mb" suffix).
+ string (optional): The string to repeat in the response. Defaults to "a".
+
+ Example:
+ /resources/large.py?size=32Mb&string=ab
+ """
+ if not "size" in request.GET:
+ 400, "Need an integer bytes parameter"
+
+ bytes_value = request.GET.first("size")
+
+ chunk_size = 1024
+
+ multipliers = {"kb": 1024,
+ "Mb": 1024*1024}
+
+ suffix = bytes_value[-2:]
+ if suffix in multipliers:
+ multiplier = multipliers[suffix]
+ bytes_value = bytes_value[:-2] * multiplier
+
+ try:
+ num_bytes = int(bytes_value)
+ except ValueError:
+ return 400, "Bytes must be an integer possibly with a kb or Mb suffix"
+
+ string = str(request.GET.first("string", "a"))
+
+ chunk = string * chunk_size
+
+ def content():
+ bytes_sent = 0
+ while bytes_sent < num_bytes:
+ if num_bytes - bytes_sent < len(chunk):
+ yield chunk[num_bytes - bytes_sent]
+ else:
+ yield chunk
+ bytes_sent += len(chunk)
+ return [("Content-Type", "text/plain")], content()

Powered by Google App Engine
This is Rietveld 408576698