Diff
Modified: trunk/Tools/ChangeLog (173497 => 173498)
--- trunk/Tools/ChangeLog 2014-09-10 23:57:34 UTC (rev 173497)
+++ trunk/Tools/ChangeLog 2014-09-11 00:01:47 UTC (rev 173498)
@@ -1,3 +1,30 @@
+2014-09-10 Rebecca Hauck <[email protected]>
+
+ import-w3c-tests doesn't handle relative paths to support files in ref files correctly
+ https://bugs.webkit.org/show_bug.cgi?id=135929
+
+ Reviewed by Bem Jones-Bey.
+
+ The recent refactor of the W3C test repo falsified a bunch of assmumptions that
+ were made when this script was originally written with respect to relative paths
+ in ref files. This patch updates import-w3c-tests to update paths in ref files if
+ they move relative to the test file.
+
+
+ * Scripts/webkitpy/w3c/test_converter.py:
+ (convert_for_webkit):
+ (_W3CTestConverter.__init__):
+ (_W3CTestConverter.convert_reference_relpaths):
+ (_W3CTestConverter.convert_style_data):
+ (_W3CTestConverter.convert_attributes_if_needed):
+ * Scripts/webkitpy/w3c/test_importer.py:
+ (TestImporter.find_importable_tests):
+ (TestImporter.import_tests):
+ * Scripts/webkitpy/w3c/test_parser.py:
+ (TestParser.load_file):
+ (TestParser.analyze_test):
+ (TestParser.support_files):
+
2014-09-10 Michael Catanzaro <[email protected]>
[GTK] allow overwriting destination of download
Modified: trunk/Tools/Scripts/webkitpy/w3c/test_converter.py (173497 => 173498)
--- trunk/Tools/Scripts/webkitpy/w3c/test_converter.py 2014-09-10 23:57:34 UTC (rev 173497)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_converter.py 2014-09-11 00:01:47 UTC (rev 173498)
@@ -37,12 +37,12 @@
_log = logging.getLogger(__name__)
-def convert_for_webkit(new_path, filename, host=Host()):
+def convert_for_webkit(new_path, filename, reference_support_info, host=Host()):
""" Converts a file's |contents| so it will function correctly in its |new_path| in Webkit.
Returns the list of modified properties and the modified text if the file was modifed, None otherwise."""
contents = host.filesystem.read_binary_file(filename)
- converter = _W3CTestConverter(new_path, filename, host)
+ converter = _W3CTestConverter(new_path, filename, reference_support_info, host)
if filename.endswith('.css'):
return converter.add_webkit_prefix_to_unprefixed_properties(contents)
else:
@@ -52,7 +52,7 @@
class _W3CTestConverter(HTMLParser):
- def __init__(self, new_path, filename, host=Host()):
+ def __init__(self, new_path, filename, reference_support_info, host=Host()):
HTMLParser.__init__(self)
self._host = host
@@ -64,6 +64,7 @@
self.in_style_tag = False
self.style_data = []
self.filename = filename
+ self.reference_support_info = reference_support_info
resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
resources_relpath = self._filesystem.relpath(resources_path, new_path)
@@ -126,12 +127,28 @@
# FIXME: Handle the JS versions of these properties and GetComputedStyle, too.
return (converted_properties, ''.join(text_chunks))
+ def convert_reference_relpaths(self, text):
+ """ Searches |text| for instances of files in reference_support_info and updates the relative path to be correct for the new ref file location"""
+ converted = text
+ for path in self.reference_support_info['files']:
+ if text.find(path) != -1:
+ # FIXME: This doesn't handle an edge case where simply removing the relative path doesn't work.
+ # See http://webkit.org/b/135677 for details.
+ new_path = re.sub(self.reference_support_info['reference_relpath'], '', path, 1)
+ converted = re.sub(path, new_path, text)
+
+ return converted
+
def convert_style_data(self, data):
converted = self.add_webkit_prefix_to_unprefixed_properties(data)
if converted[0]:
self.converted_properties.extend(list(converted[0]))
- return converted[1]
+ if self.reference_support_info is None or self.reference_support_info == {}:
+ return converted[1]
+
+ return self.convert_reference_relpaths(converted[1])
+
def convert_attributes_if_needed(self, tag, attrs):
converted = self.get_starttag_text()
if tag in ('script', 'link'):
@@ -148,6 +165,12 @@
new_style = self.convert_style_data(attr[1])
converted = re.sub(attr[1], new_style, converted)
+ src_tags = ('script', 'img', 'frame', 'iframe', 'input', 'layer', 'textarea', 'video', 'audio')
+ if tag in src_tags and self.reference_support_info is not None and self.reference_support_info != {}:
+ for attr_name, attr_value in attrs:
+ if attr_name == 'src':
+ converted = self.convert_reference_relpaths(attr_value)
+
self.converted_data.append(converted)
def handle_starttag(self, tag, attrs):
Modified: trunk/Tools/Scripts/webkitpy/w3c/test_importer.py (173497 => 173498)
--- trunk/Tools/Scripts/webkitpy/w3c/test_importer.py 2014-09-10 23:57:34 UTC (rev 173497)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_importer.py 2014-09-11 00:01:47 UTC (rev 173498)
@@ -207,21 +207,9 @@
ref_file = os.path.splitext(test_basename)[0] + '-expected'
ref_file += os.path.splitext(test_basename)[1]
- copy_list.append({'src': test_info['reference'], 'dest': ref_file})
+ copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
copy_list.append({'src': test_info['test'], 'dest': filename})
- # Update any support files that need to move as well to remain relative to the -expected file.
- if 'refsupport' in test_info.keys():
- for support_file in test_info['refsupport']:
- source_file = os.path.join(os.path.dirname(test_info['reference']), support_file)
- source_file = os.path.normpath(source_file)
-
- # Keep the dest as it was
- to_copy = {'src': source_file, 'dest': support_file}
-
- # Only add it once
- if not(to_copy in copy_list):
- copy_list.append(to_copy)
elif 'jstest' in test_info.keys():
jstests += 1
total_tests += 1
@@ -230,11 +218,6 @@
total_tests += 1
copy_list.append({'src': fullpath, 'dest': filename})
- if not total_tests:
- # We can skip the support directory if no tests were found.
- if 'support' in dirs:
- dirs.remove('support')
-
if copy_list:
# Only add this directory to the list if there's something to import
self.import_list.append({'dirname': root, 'copy_list': copy_list,
@@ -282,6 +265,10 @@
continue
new_filepath = os.path.join(new_path, file_to_copy['dest'])
+ if 'reference_support_info' in file_to_copy.keys() and file_to_copy['reference_support_info'] != {}:
+ reference_support_info = file_to_copy['reference_support_info']
+ else:
+ reference_support_info = None
if not(os.path.exists(os.path.dirname(new_filepath))):
os.makedirs(os.path.dirname(new_filepath))
@@ -300,10 +287,11 @@
mimetype = mimetypes.guess_type(orig_filepath)
if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or 'css' in str(mimetype[0]):
try:
- converted_file = convert_for_webkit(new_path, filename=orig_filepath)
+ converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info)
except:
_log.warn('Failed converting %s', orig_filepath)
failed_conversion_files.append(orig_filepath)
+ converted_file = None
if not converted_file:
shutil.copyfile(orig_filepath, new_filepath) # The file was unmodified.
Modified: trunk/Tools/Scripts/webkitpy/w3c/test_parser.py (173497 => 173498)
--- trunk/Tools/Scripts/webkitpy/w3c/test_parser.py 2014-09-10 23:57:34 UTC (rev 173497)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_parser.py 2014-09-11 00:01:47 UTC (rev 173498)
@@ -49,37 +49,31 @@
self.ref_doc = None
self.load_file(filename)
- def load_file(self, filename):
+ def load_file(self, filename, is_ref=False):
if self.filesystem.isfile(filename):
try:
- self.test_doc = Parser(self.filesystem.read_binary_file(filename))
+ doc = Parser(self.filesystem.read_binary_file(filename))
except:
# FIXME: Figure out what to do if we can't parse the file.
_log.error("Failed to parse %s", filename)
- self.test_doc is None
+ doc = None
else:
if self.filesystem.isdir(filename):
# FIXME: Figure out what is triggering this and what to do about it.
_log.error("Trying to load %s, which is a directory", filename)
- self.test_doc = None
- self.ref_doc = None
+ doc = None
+ if is_ref:
+ self.ref_doc = doc
+ else:
+ self.test_doc = doc
+
def analyze_test(self, test_contents=None, ref_contents=None):
""" Analyzes a file to determine if it's a test, what type of test, and what reference or support files it requires. Returns all of the test info """
test_info = None
- if test_contents is None and self.test_doc is None:
- return test_info
-
- if test_contents is not None:
- self.test_doc = Parser(test_contents)
-
- if ref_contents is not None:
- self.ref_doc = Parser(ref_contents)
-
# First check if it's a reftest
-
matches = self.reference_links_of_type('match') + self.reference_links_of_type('mismatch')
if matches:
if len(matches) > 1:
@@ -95,29 +89,17 @@
return None
if self.ref_doc is None:
- self.ref_doc = self.load_file(ref_file)
+ self.load_file(ref_file, True)
test_info = {'test': self.filename, 'reference': ref_file}
- # If the ref file path is relative, we need to check it for
- # relative paths also because when it lands in WebKit, it will be
- # moved down into the test dir.
- #
- # Note: The test files themselves are not checked for support files
- # outside their directories as the convention in the CSSWG is to
- # put all support files in the same dir or subdir as the test.
- #
- # All non-test files in the test's directory tree are normally
- # copied as part of the import as they are assumed to be required
- # support files.
- #
- # *But*, there is exactly one case in the entire css2.1 suite where
- # a test depends on a file that lives in a different directory,
- # which depends on another file that lives outside of its
- # directory. This code covers that case :)
- if matches[0]['href'].startswith('..'):
- support_files = self.support_files(self.ref_doc)
- test_info['refsupport'] = support_files
+ # If the ref file does not live in the same directory as the test file, check it for support files
+ test_info['reference_support_info'] = {}
+ if self.filesystem.dirname(ref_file) != self.filesystem.dirname(self.filename):
+ reference_support_files = self.support_files(self.ref_doc)
+ if len(reference_support_files) > 0:
+ reference_relpath = self.filesystem.relpath(self.filesystem.dirname(self.filename), self.filesystem.dirname(ref_file)) + self.filesystem.sep
+ test_info['reference_support_info'] = {'reference_relpath': reference_relpath, 'files': reference_support_files}
elif self.is_jstest():
test_info = {'test': self.filename, 'jstest': True}
@@ -156,7 +138,8 @@
paths = src_paths + href_paths + urls
for path in paths:
- if not(path.startswith('http:')) and not(path.startswith('mailto:')):
+ uri_scheme_pattern = re.compile(r"[A-Za-z][A-Za-z+.-]*:")
+ if uri_scheme_pattern.match(path):
support_files.append(path)
return support_files