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

Unified Diff: tools/perf/page_sets/update_webrtc_cases

Issue 2761163003: Use local pages for webrtc telemetry tests. (Closed)
Patch Set: Exclude all of webrtc_cases in PRESUBMIT.py and add a comment explaining it is because these are te… Created 3 years, 9 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: tools/perf/page_sets/update_webrtc_cases
diff --git a/tools/perf/page_sets/update_webrtc_cases b/tools/perf/page_sets/update_webrtc_cases
new file mode 100755
index 0000000000000000000000000000000000000000..4bed428fb675994828f1618aee81d090738a2814
--- /dev/null
+++ b/tools/perf/page_sets/update_webrtc_cases
@@ -0,0 +1,155 @@
+#!/usr/bin/env python
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+import urllib2
+
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+DEFAULT_DESTINATION_DIR = os.path.join(SCRIPT_DIR, 'webrtc_cases')
+
+WEBRTC_GITHUB_URL = 'https://github.com/webrtc/'
+TEST_PAGES_LOCATION_BY_REPO = {
+ 'test-pages': {
+ 'dirs': [
+ 'src/canvas-capture',
+ 'src/multiple-peerconnections',
+ ],
+ },
+ 'samples': {
+ 'dirs': [
+ 'src/content/datachannel/datatransfer',
+ 'src/content/getusermedia/resolution',
+ 'src/content/peerconnection/constraints',
+ 'src/content/peerconnection/audio',
+ ],
+ 'files': [
+ 'src/js/common.js',
+ ],
+ },
+ 'adapter': {
+ 'files': [
+ 'release/adapter.js',
+ ],
+ },
+}
+
+ADDED_SCRIPT_TAGS = (
+ '<script src="%s.js"></script>\n'
+ '<script src="adapter.js"></script>\n'
+ '<script src="common.js"></script>\n'
+ '</body></html>'
+)
+
+COPYRIGHT_NOTICE = [
+ 'Copyright 2017 The Chromium Authors. All rights reserved.\n',
+ 'Use of this source code is governed by a BSD-style license that can be\n',
+ 'found in the LICENSE file.\n',
+]
+
+COPYRIGHT_NOTICE_LENGTH = 8
+JS_COPYRIGHT_NOTICE = ' * '.join(['/*\n'] + COPYRIGHT_NOTICE) + ' */\n'
+HTML_COPYRIGHT_NOTICE = ' * '.join(['<!--\n'] + COPYRIGHT_NOTICE) + '-->\n'
+
+STRIPPED_TAGS_RE = ('( *<meta.*?>\n?| *<link.*?>\n?|'
+ ' *<script.*>.*?</script>\n?|</body>.*?</html>)')
+
+
+class TemporaryDirectory(object):
+ def __init__(self):
+ self._closed = False
+ self._name = None
+ self._name = tempfile.mkdtemp()
+ def __enter__(self):
+ return self._name
+ def __exit__(self, exc, value, tb):
+ if self._name and not self._closed:
+ shutil.rmtree(self._name)
+ self._closed = True
+
+
+def CopyJSFile(origin, destination, has_copyright=True):
+ contents = []
+ with open(origin) as input_file:
+ contents = input_file.readlines()
+
+ if has_copyright:
+ contents = contents[COPYRIGHT_NOTICE_LENGTH:]
+ contents = [JS_COPYRIGHT_NOTICE] + contents
+
+ with open(destination, 'w') as output_file:
+ output_file.writelines(contents)
+
+
+def CopyHTMLFile(test_name, origin, destination):
+ contents = ''
+ with open(origin) as input_file:
+ contents = input_file.read()
+
+ contents = re.sub(STRIPPED_TAGS_RE, '', contents,
+ flags=re.MULTILINE|re.DOTALL)
+ contents += ADDED_SCRIPT_TAGS % test_name
+
+ contents = [line + '\n' for line in contents.split('\n')]
+ contents = (contents[:1] + [HTML_COPYRIGHT_NOTICE] +
+ contents[COPYRIGHT_NOTICE_LENGTH:])
+
+ with open(destination, 'w') as output_file:
+ output_file.writelines(contents)
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=(
+ 'Update the WebRTC test pages.\n'
+ 'This script downloads the test pages from the WebRTC GitHub '
+ 'repository and copies them to the DESTINATION directory after '
+ 'processing them as follows: \n'
+ ' * Adds a copyright notice on top of the HTML and JS files.\n'
+ ' * Deletes the <meta> tags.\n'
+ ' * Discards the CSS files and corresponding link tags.\n'
+ ' * Discards the JS files and corresponding script tags except for '
+ 'main.js, adapter.js and common.js.\n'
+ ' * Renames the index.html and main.js files for each test to '
+ 'testname.html and testname.js.'))
+
+ parser.add_argument('-d', '--destination', default=DEFAULT_DESTINATION_DIR,
+ type=str, help='Where to save the WebRTC test pages.')
+
+ args = parser.parse_args()
+
+ if not os.path.isdir(args.destination):
+ os.makedirs(args.destination)
+
+ with TemporaryDirectory() as temp_dir:
+ for repo_name, test_dirs in TEST_PAGES_LOCATION_BY_REPO.items():
+ p = subprocess.Popen(['git', 'clone', WEBRTC_GITHUB_URL + repo_name],
+ cwd=temp_dir)
+ p.wait()
+
+ for test_dir in test_dirs.get('dirs', []):
+ test_dir = os.path.join(temp_dir, repo_name, test_dir)
+ test_name = os.path.basename(test_dir)
+
+ CopyJSFile(os.path.join(test_dir, 'js', 'main.js'),
+ os.path.join(args.destination, test_name + '.js'))
+ CopyHTMLFile(test_name, os.path.join(test_dir, 'index.html'),
+ os.path.join(args.destination, test_name + '.html'))
+
+ for test_file in test_dirs.get('files', []):
+ file_name = os.path.basename(test_file)
+ CopyJSFile(os.path.join(temp_dir, repo_name, test_file),
+ os.path.join(args.destination, file_name), False)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « tools/perf/page_sets/data/webrtc_stresstest_cases_001.wpr.sha1 ('k') | tools/perf/page_sets/webrtc_cases.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698