import-w3c-test rewrites relative src paths in ref files incorrectly
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 00:13:17 +0000 (00:13 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 00:13:17 +0000 (00:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137586

This patch fixes a bug in test_converter.py where src paths were getting
rewritten as ../../some-path instead of <script src="../../some-path>".
It also adds support for rewriting src paths in style  elements, which was
missing before and it adds tests for this case.

Patch by Rebecca Hauck <rhauck@adobe.com> on 2014-10-15
Reviewed by Bem Jones-Bey.

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

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

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

index 42f77c5..a205c61 100644 (file)
@@ -1,3 +1,21 @@
+2014-10-15  Rebecca Hauck  <rhauck@adobe.com>
+
+        import-w3c-test rewrites relative src paths in ref files incorrectly
+        https://bugs.webkit.org/show_bug.cgi?id=137586
+
+        This patch fixes a bug in test_converter.py where src paths were getting 
+        rewritten as ../../some-path instead of <script src="../../some-path>". 
+        It also adds support for rewriting src paths in style  elements, which was 
+        missing before and it adds tests for this case.
+
+        Reviewed by Bem Jones-Bey.
+
+        * Scripts/webkitpy/w3c/test_converter.py:
+        (_W3CTestConverter.convert_attributes_if_needed):
+        * Scripts/webkitpy/w3c/test_converter_unittest.py:
+        (test_convert_attributes_if_needed):
+        (verify_reference_relative_paths):
+
 2014-10-15  Jake Nielsen  <jacob_nielsen@apple.com>
 
         Add --json flag to test-webkitpy to emit JSON formatted test results
index d463596..480bc74 100644 (file)
@@ -179,11 +179,12 @@ class _W3CTestConverter(HTMLParser):
                 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')
+        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':
-                    converted = self.convert_reference_relpaths(attr_value)
+                    new_path = self.convert_reference_relpaths(attr_value)
+                    converted = re.sub(attr_value, new_path, converted)
 
         self.converted_data.append(converted)
 
index 173bdd6..5e53e82 100644 (file)
@@ -289,6 +289,34 @@ CONTENT OF TEST
         self.verify_prefixed_properties(converted, test_content[0])
         self.verify_prefixed_property_values(converted, test_content[1])
 
+    def test_convert_attributes_if_needed(self):
+        """ Tests convert_attributes_if_needed() using a reference file that has some relative src paths """
+
+        test_html = """<html>
+<head>
+<script src="../../some-script.js"></script>
+<style src="../../../some-style.css"></style>
+</head>
+<body>
+<img src="../../../../some-image.jpg">
+</body>
+</html>
+"""
+        test_reference_support_info = {'reference_relpath': '../', 'files': ['../../some-script.js', '../../../some-style.css', '../../../../some-image.jpg'], 'elements': ['script', 'style', 'img']}
+        converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference_support_info)
+
+        oc = OutputCapture()
+        oc.capture_output()
+        try:
+            converter.feed(test_html)
+            converter.close()
+            converted = converter.output()
+        finally:
+            oc.restore_output()
+
+        self.verify_conversion_happened(converted)
+        self.verify_reference_relative_paths(converted, test_reference_support_info)
+
     def verify_conversion_happened(self, converted):
         self.assertTrue(converted, "conversion didn't happen")
 
@@ -321,6 +349,15 @@ CONTENT OF TEST
         for test_value in test_property_values:
             self.assertTrue((test_value in converted[2]), 'Property value ' + test_value + ' not found in converted doc')
 
+    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)
+            element = reference_support_info['elements'][idx]
+            expected_tag = '<' + element + ' src=\"' + expected_path + '\">'
+            self.assertTrue(expected_tag in converted[2], 'relative path ' + path + ' was not converted correcty')
+            idx += 1
+
     def generate_test_content_properties_and_values(self, full_property_list, fully_property_values_list, num_test_properties_and_values, html):
         """Inserts properties requiring a -webkit- prefix into the content, replacing \'@testXX@\' with a property and \'@propvalueXX@\' with a value."""
         test_content_properties = self.generate_test_content(full_property_list, num_test_properties_and_values, 'test', html)