WPT test importer fails to update references in <link> tags
authorclopez@igalia.com <clopez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 May 2020 11:17:57 +0000 (11:17 +0000)
committerclopez@igalia.com <clopez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 May 2020 11:17:57 +0000 (11:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211762

Reviewed by Youenn Fablet.

When importing WPT test references, ensure relative paths are also
updated for the href attribute in <link> tags.
Also fix a bug that was causing wrong updates on the paths due to
the characters in reference_relpath not escaped when performing
the regex substitution in convert_reference_relpaths(). For example:
"resources/script.js" was changed to "resourcscript.js" when reference_relpath was '../'

Improve also the unit test case to check for the fixes in this patch.

* Scripts/webkitpy/w3c/test_converter.py:
(_W3CTestConverter.convert_reference_relpaths):
(_W3CTestConverter.convert_attributes_if_needed):
* Scripts/webkitpy/w3c/test_converter_unittest.py:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261552 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/w3c/test_converter.py
Tools/Scripts/webkitpy/w3c/test_converter_unittest.py

index 012d4fb..b9fa3be 100644 (file)
@@ -1,3 +1,24 @@
+2020-05-12  Carlos Alberto Lopez Perez  <clopez@igalia.com>
+
+        WPT test importer fails to update references in <link> tags
+        https://bugs.webkit.org/show_bug.cgi?id=211762
+
+        Reviewed by Youenn Fablet.
+
+        When importing WPT test references, ensure relative paths are also
+        updated for the href attribute in <link> tags.
+        Also fix a bug that was causing wrong updates on the paths due to
+        the characters in reference_relpath not escaped when performing
+        the regex substitution in convert_reference_relpaths(). For example:
+        "resources/script.js" was changed to "resourcscript.js" when reference_relpath was '../'
+
+        Improve also the unit test case to check for the fixes in this patch.
+
+        * Scripts/webkitpy/w3c/test_converter.py:
+        (_W3CTestConverter.convert_reference_relpaths):
+        (_W3CTestConverter.convert_attributes_if_needed):
+        * Scripts/webkitpy/w3c/test_converter_unittest.py:
+
 2020-05-12  Philippe Normand  <pnormand@igalia.com>
 
         [Flatpak SDK] Include clang++ and g++ in toolchains
index d4e05e4..7cbc8fe 100644 (file)
@@ -186,8 +186,8 @@ class _W3CTestConverter(HTMLParser):
             if converted.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, converted)
+                new_path = re.sub(re.escape(self.reference_support_info['reference_relpath']), '', path, 1)
+                converted = re.sub(re.escape(path), new_path, converted)
 
         return converted
 
@@ -219,13 +219,19 @@ class _W3CTestConverter(HTMLParser):
                 new_style = self.convert_style_data(attr[1])
                 converted = re.sub(re.escape(attr[1]), new_style, converted)
 
+        # Convert relative paths
         src_tags = ('script', 'style', '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':
-                    new_path = self.convert_reference_relpaths(attr_value)
-                    converted = re.sub(re.escape(attr_value), new_path, converted)
-
+        if self.reference_support_info is not None and self.reference_support_info != {}:
+            if tag in src_tags:
+                for attr_name, attr_value in attrs:
+                    if attr_name == 'src':
+                        new_path = self.convert_reference_relpaths(attr_value)
+                        converted = re.sub(re.escape(attr_value), new_path, converted)
+            if tag == 'link':
+                for attr_name, attr_value in attrs:
+                    if attr_name == 'href':
+                        new_path = self.convert_reference_relpaths(attr_value)
+                        converted = re.sub(re.escape(attr_value), new_path, converted)
         self.converted_data.append(converted)
 
     def add_webkit_test_runner_options_if_needed(self):
index b9cbd1b..b772d6e 100644 (file)
@@ -296,6 +296,8 @@ CONTENT OF TEST
 
         test_html = """<html>
 <head>
+<link href="../support/base-style.css">
+<video src="resources/video.mkv"></video>
 <script src="../../some-script.js"></script>
 <style src="../../../some-style.css"></style>
 </head>
@@ -304,7 +306,8 @@ CONTENT OF TEST
 </body>
 </html>
 """
-        test_reference_support_info = {'reference_relpath': '../', 'files': ['../../some-script.js', '../../../some-style.css', '../../../../some-image.jpg'], 'elements': ['script', 'style', 'img']}
+        test_reference_support_info = {'reference_relpath': '../', 'files': ['../../some-script.js', '../../../some-style.css', '../../../../some-image.jpg', '../support/base-style.css', 'resources/video.mkv'],
+                                       'elements': ['script', 'style', 'img', 'link', 'video']}
         converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference_support_info)
 
         oc = OutputCapture()
@@ -410,9 +413,10 @@ CONTENT OF TEST
     def verify_reference_relative_paths(self, converted, reference_support_info):
         idx = 0
         for path in reference_support_info['files']:
-            expected_path = re.sub(reference_support_info['reference_relpath'], '', path, 1)
+            expected_path = re.sub(re.escape(reference_support_info['reference_relpath']), '', path, 1)
             element = reference_support_info['elements'][idx]
-            expected_tag = '<' + element + ' src=\"' + expected_path + '\">'
+            element_src = 'href' if element == 'link' else 'src'
+            expected_tag = '<' + element + ' ' + element_src + '=\"' + expected_path + '\">'
             self.assertTrue(expected_tag in converted[2], 'relative path ' + path + ' was not converted correcty')
             idx += 1