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

Unified Diff: LayoutTests/imported/web-platform-tests/subresource-integrity/support/generate_javascript.py

Issue 816533002: Import CSSWG Shapes tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: One more test expectations update Created 6 years 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
« no previous file with comments | « LayoutTests/imported/web-platform-tests/subresource-integrity/subresource-integrity.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/imported/web-platform-tests/subresource-integrity/support/generate_javascript.py
diff --git a/LayoutTests/imported/web-platform-tests/subresource-integrity/support/generate_javascript.py b/LayoutTests/imported/web-platform-tests/subresource-integrity/support/generate_javascript.py
new file mode 100644
index 0000000000000000000000000000000000000000..4a757c8df56566b67a6e5a1859b12086ed7ba4c6
--- /dev/null
+++ b/LayoutTests/imported/web-platform-tests/subresource-integrity/support/generate_javascript.py
@@ -0,0 +1,49 @@
+from os import path, listdir
+from hashlib import sha256, md5
+from base64 import urlsafe_b64encode
+import re
+
+JS_DIR = path.normpath(path.join(__file__, "..", ".."))
+
+
+def js_files():
+ '''
+ Yield each file in the javascript directory
+ '''
+ for f in listdir(JS_DIR):
+ if path.isfile(f) and f.endswith(".js"):
+ yield f
+
+
+def format_digest(digest):
+ '''
+ URL-safe base64 encode a binary digest and strip any padding.
+ '''
+ return urlsafe_b64encode(digest).rstrip("=")
+
+
+def sha256_uri(content):
+ '''
+ Generate an encoded sha256 URI.
+ '''
+ return "ni:///sha-256;%s" % format_digest(sha256(content).digest())
+
+
+def md5_uri(content):
+ '''
+ Generate an encoded md5 digest URI.
+ '''
+ return "ni:///md5;%s" % format_digest(md5(content).digest())
+
+
+def main():
+ for file in js_files():
+ base = path.splitext(path.basename(file))[0]
+ var_name = re.sub(r"[^a-z]", "_", base)
+ content = "%s=true;" % var_name
+ with open(file, "w") as f:
+ f.write(content)
+
+
+if __name__ == "__main__":
+ main()
« no previous file with comments | « LayoutTests/imported/web-platform-tests/subresource-integrity/subresource-integrity.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698