Chromium Code Reviews| Index: third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_manifest.py |
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_manifest.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_manifest.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f715ed4bd0760841c59a1c63aa2fdabbe33984ea |
| --- /dev/null |
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_manifest.py |
| @@ -0,0 +1,103 @@ |
| +# 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. |
| + |
| +"""WPTManifest is responsible to handle MANIFEST.json. |
| +""" |
|
qyearsley
2017/02/09 17:29:48
Minor rephrasing: "WPTManifest is responsible for
tkent
2017/02/10 08:05:02
Copied them. Thanks :)
|
| + |
| +import json |
| +import logging |
| + |
| +from webkitpy.common.webkit_finder import WebKitFinder |
| + |
| +_log = logging.getLogger(__file__) |
| + |
| + |
| +class WPTManifest(object): |
| + |
| + @staticmethod |
| + def generate_manifest(host, dest_path): |
| + """Generates MANIFEST.json on the specified directory.""" |
| + executive = host.executive |
| + finder = WebKitFinder(host.filesystem) |
| + cmd = [finder.path_from_webkit_base('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'wpt', 'wpt', 'manifest'), |
| + '--work', '--tests-root', dest_path] |
| + _log.debug('Running command: %s', ' '.join(cmd)) |
| + proc = executive.popen(cmd, stdout=executive.PIPE, stderr=executive.PIPE, stdin=executive.PIPE, cwd=finder.webkit_base()) |
| + out, err = proc.communicate('') |
| + if proc.returncode: |
| + _log.info('# ret> %d' % proc.returncode) |
| + if out: |
| + _log.info(out) |
| + if err: |
| + _log.info(err) |
| + host.exit(proc.returncode) |
| + return proc.returncode, out |
| + |
| + def __init__(self, json_content): |
| + # TODO(tkent): Create a Manifest object by Manifest.from_json(). |
| + # See ../thirdparty/wpt/wpt/tools/manifest/manifest.py. |
| + self.raw_dict = json.loads(json_content) |
|
qyearsley
2017/02/09 17:29:48
Nit: __init__ could be moved to the top of the cla
tkent
2017/02/10 08:05:02
Done.
|
| + |
| + def _items_for_path(self, path_in_wpt): |
| + """Returns manifest items for the given WPT path, or None if not found. |
| + |
| + The format of a manifest item depends on |
| + https://github.com/w3c/wpt-tools/blob/master/manifest/item.py |
| + and is assumed to be a list of the format [url, extras], |
| + or [url, references, extras] for reftests, or None if not found. |
| + |
| + For most testharness tests, the returned items is expected |
| + to look like this:: [["/some/test/path.html", {}]] |
| + """ |
| + items = self.raw_dict['items'] |
| + if path_in_wpt in items['manual']: |
| + return items['manual'][path_in_wpt] |
| + elif path_in_wpt in items['reftest']: |
| + return items['reftest'][path_in_wpt] |
| + elif path_in_wpt in items['testharness']: |
| + return items['testharness'][path_in_wpt] |
| + return None |
| + |
| + def is_test_file(self, path_in_wpt): |
| + return self._items_for_path(path_in_wpt) is not None |
| + |
| + def file_path_to_url_paths(self, path_in_wpt): |
| + manifest_items = self._items_for_path(path_in_wpt) |
| + assert manifest_items is not None |
| + if len(manifest_items) != 1: |
| + return [] |
| + url = manifest_items[0][0] |
| + if url[1:] != path_in_wpt: |
| + # TODO(tkent): foo.any.js and bar.worker.js should be accessed |
| + # as foo.any.html, foo.any.worker, and bar.worker with WPTServe. |
| + return [] |
| + return [path_in_wpt] |
| + |
| + @staticmethod |
| + def _get_extras_from_item(item): |
| + return item[-1] |
| + |
| + def is_slow_test(self, test_name): |
| + items = self._items_for_path(test_name) |
| + if not items: |
| + return False |
| + extras = WPTManifest._get_extras_from_item(items[0]) |
| + return 'timeout' in extras and extras['timeout'] == 'long' |
| + |
| + def extract_reference_list(self, path_in_wpt): |
| + """Extract reference information of the specified reference test. |
|
qyearsley
2017/02/09 17:29:48
Extract -> Extracts
tkent
2017/02/10 08:05:02
Done.
|
| + |
| + The return value is a list of (match/not-match, reference path in wpt) |
| + like: |
| + [("==", "foo/bar/baz-match.html"), |
| + ("!=", "foo/bar/baz-mismatch.html")] |
| + """ |
| + all_items = self.raw_dict['items'] |
| + if path_in_wpt not in all_items['reftest']: |
| + return [] |
| + reftest_list = [] |
| + for item in all_items['reftest'][path_in_wpt]: |
| + for ref_path_in_wpt, expectation in item[1]: |
| + reftest_list.append((expectation, ref_path_in_wpt)) |
| + return reftest_list |