Changeset 174672 in webkit


Ignore:
Timestamp:
Oct 14, 2014, 1:08:05 AM (11 years ago)
Author:
Manuel Rego Casasnovas
Message:

import-w3c-tests doesn't prefix property values
https://bugs.webkit.org/show_bug.cgi?id=137600

Reviewed by Bem Jones-Bey.

Some property values are prefixed in WebKit. Modified the W3C import
script in order to prefix property values and not only properties.
The patch re-uses most of the already existent logic to prefix
properties.

  • Scripts/webkitpy/w3c/test_converter.py: Read prefixed property values

from CSSValueKeywords.in and adapt converter to modify both properties
and property values.
(convert_for_webkit):
(_W3CTestConverter.init):
(_W3CTestConverter.output):
(_W3CTestConverter.read_webkit_prefixed_css_property_list):
(_W3CTestConverter):
(_W3CTestConverter.add_webkit_prefix_to_unprefixed_properties_and_values):
(_W3CTestConverter.add_webkit_prefix_following_regex):
(_W3CTestConverter.convert_reference_relpaths):
(_W3CTestConverter.convert_style_data):
(_W3CTestConverter.convert_attributes_if_needed):
(_W3CTestConverter.add_webkit_prefix_to_unprefixed_properties): Deleted.

  • Scripts/webkitpy/w3c/test_converter_unittest.py: Updated unit test to

include checks for property values too.
(W3CTestConverterTest.test_read_prefixed_property_list):
(verify_no_conversion_happened):
(verify_prefixed_properties):
(verify_prefixed_property_values):
(generate_test_content_properties_and_values):
(generate_test_content):

  • Scripts/webkitpy/w3c/test_importer.py: Modified importer to manage

prefixed property values and inform about them.
(TestImporter.import_tests):
(TestImporter.write_import_log):

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r174667 r174672  
     12014-10-14  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        import-w3c-tests doesn't prefix property values
     4        https://bugs.webkit.org/show_bug.cgi?id=137600
     5
     6        Reviewed by Bem Jones-Bey.
     7
     8        Some property values are prefixed in WebKit. Modified the W3C import
     9        script in order to prefix property values and not only properties.
     10        The patch re-uses most of the already existent logic to prefix
     11        properties.
     12
     13        * Scripts/webkitpy/w3c/test_converter.py: Read prefixed property values
     14        from CSSValueKeywords.in and adapt converter to modify both properties
     15        and property values.
     16        (convert_for_webkit):
     17        (_W3CTestConverter.__init__):
     18        (_W3CTestConverter.output):
     19        (_W3CTestConverter.read_webkit_prefixed_css_property_list):
     20        (_W3CTestConverter):
     21        (_W3CTestConverter.add_webkit_prefix_to_unprefixed_properties_and_values):
     22        (_W3CTestConverter.add_webkit_prefix_following_regex):
     23        (_W3CTestConverter.convert_reference_relpaths):
     24        (_W3CTestConverter.convert_style_data):
     25        (_W3CTestConverter.convert_attributes_if_needed):
     26        (_W3CTestConverter.add_webkit_prefix_to_unprefixed_properties): Deleted.
     27        * Scripts/webkitpy/w3c/test_converter_unittest.py: Updated unit test to
     28        include checks for property values too.
     29        (W3CTestConverterTest.test_read_prefixed_property_list):
     30        (verify_no_conversion_happened):
     31        (verify_prefixed_properties):
     32        (verify_prefixed_property_values):
     33        (generate_test_content_properties_and_values):
     34        (generate_test_content):
     35        * Scripts/webkitpy/w3c/test_importer.py: Modified importer to manage
     36        prefixed property values and inform about them.
     37        (TestImporter.import_tests):
     38        (TestImporter.write_import_log):
     39
    1402014-10-13  Jer Noble  <jer.noble@apple.com>
    241
  • trunk/Tools/Scripts/webkitpy/w3c/test_converter.py

    r173498 r174672  
    4545    converter = _W3CTestConverter(new_path, filename, reference_support_info, host)
    4646    if filename.endswith('.css'):
    47         return converter.add_webkit_prefix_to_unprefixed_properties(contents)
     47        return converter.add_webkit_prefix_to_unprefixed_properties_and_values(contents)
    4848    else:
    4949        converter.feed(contents)
     
    6262        self.converted_data = []
    6363        self.converted_properties = []
     64        self.converted_property_values = []
    6465        self.in_style_tag = False
    6566        self.style_data = []
     
    7374        # These settings might vary between WebKit and Blink
    7475        self._css_property_file = self.path_from_webkit_root('Source', 'WebCore', 'css', 'CSSPropertyNames.in')
     76        self._css_property_value_file = self.path_from_webkit_root('Source', 'WebCore', 'css', 'CSSValueKeywords.in')
    7577        self._css_property_split_string = '='
    7678
    7779        self.test_harness_re = re.compile('/resources/testharness')
    7880
    79         self.prefixed_properties = self.read_webkit_prefixed_css_property_list()
     81        self.prefixed_properties = self.read_webkit_prefixed_css_property_list(self._css_property_file)
    8082        prop_regex = '([\s{]|^)(' + "|".join(prop.replace('-webkit-', '') for prop in self.prefixed_properties) + ')(\s+:|:)'
    8183        self.prop_re = re.compile(prop_regex)
    8284
     85        self.prefixed_property_values = self.read_webkit_prefixed_css_property_list(self._css_property_value_file)
     86        prop_value_regex = '(:\s*|^\s*)(' + "|".join(value.replace('-webkit-', '') for value in self.prefixed_property_values) + ')(\s*;|\s*}|\s*$)'
     87        self.prop_value_re = re.compile(prop_value_regex)
     88
    8389    def output(self):
    84         return (self.converted_properties, ''.join(self.converted_data))
     90        return (self.converted_properties, self.converted_property_values, ''.join(self.converted_data))
    8591
    8692    def path_from_webkit_root(self, *comps):
    8793        return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps))
    8894
    89     def read_webkit_prefixed_css_property_list(self):
     95    def read_webkit_prefixed_css_property_list(self, file_name):
     96        contents = self._filesystem.read_text_file(file_name)
    9097        prefixed_properties = []
    9198        unprefixed_properties = set()
    9299
    93         contents = self._filesystem.read_text_file(self._css_property_file)
    94100        for line in contents.splitlines():
    95101            if re.match('^(#|//)', line):
     
    108114        return [prop for prop in prefixed_properties if prop not in unprefixed_properties]
    109115
    110     def add_webkit_prefix_to_unprefixed_properties(self, text):
    111         """ Searches |text| for instances of properties requiring the -webkit- prefix and adds the prefix to them.
    112 
    113         Returns the list of converted properties and the modified text."""
    114 
    115         converted_properties = set()
     116    def add_webkit_prefix_to_unprefixed_properties_and_values(self, text):
     117        """ Searches |text| for instances of properties and values requiring the -webkit- prefix and adds the prefix to them.
     118
     119        Returns the list of converted properties, values and the modified text."""
     120
     121        converted_properties = self.add_webkit_prefix_following_regex(text, self.prop_re)
     122        converted_property_values = self.add_webkit_prefix_following_regex(converted_properties[1], self.prop_value_re)
     123
     124        # FIXME: Handle the JS versions of these properties and values and GetComputedStyle, too.
     125        return (converted_properties[0], converted_property_values[0], converted_property_values[1])
     126
     127    def add_webkit_prefix_following_regex(self, text, regex):
     128        converted_list = set()
    116129        text_chunks = []
    117130        cur_pos = 0
    118         for m in self.prop_re.finditer(text):
     131        for m in regex.finditer(text):
    119132            text_chunks.extend([text[cur_pos:m.start()], m.group(1), '-webkit-', m.group(2), m.group(3)])
    120             converted_properties.add(m.group(2))
     133            converted_list.add(m.group(2))
    121134            cur_pos = m.end()
    122135        text_chunks.append(text[cur_pos:])
    123136
    124         for prop in converted_properties:
    125             _log.info('  converting %s', prop)
    126 
    127         # FIXME: Handle the JS versions of these properties and GetComputedStyle, too.
    128         return (converted_properties, ''.join(text_chunks))
     137        for item in converted_list:
     138            _log.info('  converting %s', item)
     139
     140        return (converted_list, ''.join(text_chunks))
    129141
    130142    def convert_reference_relpaths(self, text):
     
    141153
    142154    def convert_style_data(self, data):
    143         converted = self.add_webkit_prefix_to_unprefixed_properties(data)
     155        converted = self.add_webkit_prefix_to_unprefixed_properties_and_values(data)
    144156        if converted[0]:
    145157            self.converted_properties.extend(list(converted[0]))
     158        if converted[1]:
     159            self.converted_property_values.extend(list(converted[1]))
    146160
    147161        if self.reference_support_info is None or self.reference_support_info == {}:
    148             return converted[1]
    149 
    150         return self.convert_reference_relpaths(converted[1])
     162            return converted[2]
     163
     164        return self.convert_reference_relpaths(converted[2])
    151165
    152166    def convert_attributes_if_needed(self, tag, attrs):
  • trunk/Tools/Scripts/webkitpy/w3c/test_converter_unittest.py

    r174136 r174672  
    5555        prop_list = converter.prefixed_properties
    5656        self.assertTrue(prop_list, 'No prefixed properties found')
     57        property_values_list = converter.prefixed_property_values
     58        self.assertTrue(property_values_list, 'No prefixed property values found')
    5759
    5860    def test_convert_for_webkit_nothing_to_convert(self):
     
    105107
    106108        self.verify_conversion_happened(converted)
    107         self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1, 1)
     109        self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 1, 1)
    108110        self.verify_prefixed_properties(converted, [])
     111        self.verify_prefixed_property_values(converted, [])
    109112
    110113    def test_convert_for_webkit_properties_only(self):
     
    117120<style type="text/css">
    118121
    119 #block1 { @test0@: propvalue; }
     122#block1 { @test0@: @propvalue0@; }
    120123
    121124</style>
    122125</head>
    123126<body>
    124 <div id="elem1" style="@test1@: propvalue;"></div>
     127<div id="elem1" style="@test1@: @propvalue1@;"></div>
    125128</body>
    126129</html>
     
    128131        fake_dir_path = self.fake_dir_path('harnessandprops')
    129132        converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None)
    130         test_content = self.generate_test_content(converter.prefixed_properties, 1, test_html)
    131 
    132         oc = OutputCapture()
    133         oc.capture_output()
    134         try:
    135             converter.feed(test_content[1])
    136             converter.close()
    137             converted = converter.output()
    138         finally:
    139             oc.restore_output()
    140 
    141         self.verify_conversion_happened(converted)
    142         self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1, 1)
     133        test_content = self.generate_test_content_properties_and_values(converter.prefixed_properties, converter.prefixed_property_values, 1, test_html)
     134
     135        oc = OutputCapture()
     136        oc.capture_output()
     137        try:
     138            converter.feed(test_content[2])
     139            converter.close()
     140            converted = converter.output()
     141        finally:
     142            oc.restore_output()
     143
     144        self.verify_conversion_happened(converted)
     145        self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 1, 1)
    143146        self.verify_prefixed_properties(converted, test_content[0])
     147        self.verify_prefixed_property_values(converted, test_content[1])
    144148
    145149    def test_convert_for_webkit_harness_and_properties(self):
     
    152156<style type="text/css">
    153157
    154 #block1 { @test0@: propvalue; }
    155 #block2 { @test1@: propvalue; }
    156 #block3 { @test2@: propvalue; }
     158#block1 { @test0@: @propvalue0@; }
     159#block2 { @test1@: @propvalue1@; }
     160#block3 { @test2@: @propvalue2@; }
    157161
    158162</style>
    159163</head>
    160164<body>
    161 <div id="elem1" style="@test3@: propvalue;"></div>
     165<div id="elem1" style="@test3@: @propvalue3@;"></div>
    162166</body>
    163167</html>
     
    169173        oc.capture_output()
    170174        try:
    171             test_content = self.generate_test_content(converter.prefixed_properties, 2, test_html)
    172             converter.feed(test_content[1])
    173             converter.close()
    174             converted = converter.output()
    175         finally:
    176             oc.restore_output()
    177 
    178         self.verify_conversion_happened(converted)
    179         self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1, 1)
     175            test_content = self.generate_test_content_properties_and_values(converter.prefixed_properties, converter.prefixed_property_values, 2, test_html)
     176            converter.feed(test_content[2])
     177            converter.close()
     178            converted = converter.output()
     179        finally:
     180            oc.restore_output()
     181
     182        self.verify_conversion_happened(converted)
     183        self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 1, 1)
    180184        self.verify_prefixed_properties(converted, test_content[0])
     185        self.verify_prefixed_property_values(converted, test_content[1])
    181186
    182187    def test_convert_test_harness_paths(self):
     
    202207
    203208        self.verify_conversion_happened(converted)
    204         self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 2, 1)
     209        self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 2, 1)
    205210
    206211    def test_convert_prefixed_properties(self):
     
    220225
    221226.block2 {
    222     @test0@: propvalue;
    223 }
    224 
    225 .block3{@test1@: propvalue;}
    226 
    227 .block4 { @test2@:propvalue; }
    228 
    229 .block5{ @test3@ :propvalue; }
    230 
    231 #block6 {    @test4@   :   propvalue;  }
     227    @test0@: @propvalue0@;
     228}
     229
     230.block3{@test1@: @propvalue1@;}
     231
     232.block4 { @test2@:@propvalue2@; }
     233
     234.block5{ @test3@ :@propvalue3@; }
     235
     236#block6 {    @test4@   :   @propvalue4@   ;  }
    232237
    233238#block7
    234239{
    235     @test5@: propvalue;
    236 }
    237 
    238 #block8 { @test6@: propvalue; }
     240    @test5@: @propvalue5@;
     241}
     242
     243#block8 { @test6@: @propvalue6@ }
    239244
    240245#block9:pseudo
    241246{
    242247
    243     @test7@: propvalue;
     248    @test7@: @propvalue7@;
    244249    @test8@:  propvalue propvalue propvalue;;
     250    propname:
     251@propvalue8@;
    245252}
    246253
     
    248255</head>
    249256<body>
    250     <div id="elem1" style="@test9@: propvalue;"></div>
    251     <div id="elem2" style="propname: propvalue; @test10@ : propvalue; propname:propvalue;"></div>
    252     <div id="elem2" style="@test11@: propvalue; @test12@ : propvalue; @test13@   :propvalue;"></div>
    253     <div id="elem3" style="@test14@:propvalue"></div>
     257    <div id="elem1" style="@test9@: @propvalue9@;"></div>
     258    <div id="elem2" style="propname: propvalue; @test10@ : @propvalue10@; propname:propvalue;"></div>
     259    <div id="elem2" style="@test11@: @propvalue11@; @test12@ : @propvalue12@; @test13@   :   @propvalue13@   ;"></div>
     260    <div id="elem3" style="@test14@:@propvalue14@"></div>
    254261</body>
    255262<style type="text/css"><![CDATA[
    256263
    257 .block10{ @test15@: propvalue; }
    258 .block11{ @test16@: propvalue; }
    259 .block12{ @test17@: propvalue; }
     264.block10{ @test15@: @propvalue15@; }
     265.block11{ @test16@: @propvalue16@; }
     266.block12{ @test17@: @propvalue17@; }
    260267#block13:pseudo
    261268{
    262     @test18@: propvalue;
    263     @test19@: propvalue;
     269    @test18@: @propvalue18@;
     270    @test19@: @propvalue19@;
    264271}
    265272
     
    268275"""
    269276        converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None)
    270         test_content = self.generate_test_content(converter.prefixed_properties, 20, test_html)
    271 
    272         oc = OutputCapture()
    273         oc.capture_output()
    274         try:
    275             converter.feed(test_content[1])
     277        test_content = self.generate_test_content_properties_and_values(converter.prefixed_properties, converter.prefixed_property_values, 20, test_html)
     278
     279        oc = OutputCapture()
     280        oc.capture_output()
     281        try:
     282            converter.feed(test_content[2])
    276283            converter.close()
    277284            converted = converter.output()
     
    281288        self.verify_conversion_happened(converted)
    282289        self.verify_prefixed_properties(converted, test_content[0])
     290        self.verify_prefixed_property_values(converted, test_content[1])
    283291
    284292    def verify_conversion_happened(self, converted):
     
    286294
    287295    def verify_no_conversion_happened(self, converted, original):
    288         self.assertEqual(converted[1], original, 'test should not have been converted')
     296        self.assertEqual(converted[2], original, 'test should not have been converted')
    289297
    290298    def verify_test_harness_paths(self, converter, converted, test_path, num_src_paths, num_href_paths):
     
    307315        self.assertEqual(len(set(converted[0])), len(set(test_properties)), 'Incorrect number of properties converted')
    308316        for test_prop in test_properties:
    309             self.assertTrue((test_prop in converted[1]), 'Property ' + test_prop + ' not found in converted doc')
    310 
    311     def generate_test_content(self, full_property_list, num_test_properties, html):
    312         """Inserts properties requiring a -webkit- prefix into the content, replacing \'@testXX@\' with a property."""
    313         test_properties = []
     317            self.assertTrue((test_prop in converted[2]), 'Property ' + test_prop + ' not found in converted doc')
     318
     319    def verify_prefixed_property_values(self, converted, test_property_values):
     320        self.assertEqual(len(set(converted[1])), len(set(test_property_values)), 'Incorrect number of property values converted ' + str(len(set(converted[1]))) + ' vs ' + str(len(set(test_property_values))))
     321        for test_value in test_property_values:
     322            self.assertTrue((test_value in converted[2]), 'Property value ' + test_value + ' not found in converted doc')
     323
     324    def generate_test_content_properties_and_values(self, full_property_list, fully_property_values_list, num_test_properties_and_values, html):
     325        """Inserts properties requiring a -webkit- prefix into the content, replacing \'@testXX@\' with a property and \'@propvalueXX@\' with a value."""
     326        test_content_properties = self.generate_test_content(full_property_list, num_test_properties_and_values, 'test', html)
     327        test_content_property_values = self.generate_test_content(fully_property_values_list, num_test_properties_and_values, 'propvalue', test_content_properties[1])
     328        return (test_content_properties[0], test_content_property_values[0], test_content_property_values[1])
     329
     330    def generate_test_content(self, full_list, num_test, suffix, html):
     331        test_list = []
    314332        count = 0
    315         while count < num_test_properties:
    316             test_properties.append(full_property_list[count])
     333        while count < num_test:
     334            test_list.append(full_list[count])
    317335            count += 1
    318336
    319         # Replace the tokens in the testhtml with the test properties. Walk backward
    320         # through the list to replace the double-digit tokens first
    321         index = len(test_properties) - 1
     337        # Replace the tokens in the testhtml with the test properties or values.
     338        # Walk backward through the list to replace the double-digit tokens first.
     339        index = len(test_list) - 1
    322340        while index >= 0:
    323341            # Use the unprefixed version
    324             test_prop = test_properties[index].replace('-webkit-', '')
     342            test = test_list[index].replace('-webkit-', '')
    325343            # Replace the token
    326             html = html.replace('@test' + str(index) + '@', test_prop)
     344            html = html.replace('@' + suffix + str(index) + '@', test)
    327345            index -= 1
    328346
    329         return (test_properties, html)
     347        return (test_list, html)
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer.py

    r173876 r174672  
    240240        total_imported_jstests = 0
    241241        total_prefixed_properties = {}
     242        total_prefixed_property_values = {}
    242243
    243244        failed_conversion_files = []
     
    249250
    250251            prefixed_properties = []
     252            prefixed_property_values = []
    251253
    252254            if not dir_to_copy['copy_list']:
     
    313315
    314316                        prefixed_properties.extend(set(converted_file[0]) - set(prefixed_properties))
     317
     318                        for prefixed_value in converted_file[1]:
     319                            total_prefixed_property_values.setdefault(prefixed_value, 0)
     320                            total_prefixed_property_values[prefixed_value] += 1
     321
     322                        prefixed_property_values.extend(set(converted_file[1]) - set(prefixed_property_values))
     323
    315324                        outfile = open(new_filepath, 'wb')
    316                         outfile.write(converted_file[1])
     325                        outfile.write(converted_file[2])
    317326                        outfile.close()
    318327                else:
     
    322331
    323332            self.remove_deleted_files(new_path, copied_files)
    324             self.write_import_log(new_path, copied_files, prefixed_properties)
     333            self.write_import_log(new_path, copied_files, prefixed_properties, prefixed_property_values)
    325334
    326335        _log.info('Import complete')
     
    337346        for prefixed_property in sorted(total_prefixed_properties, key=lambda p: total_prefixed_properties[p]):
    338347            _log.info('  %s: %s', prefixed_property, total_prefixed_properties[prefixed_property])
     348        _log.info('')
     349        _log.info('Property values needing prefixes (by count):')
     350
     351        for prefixed_value in sorted(total_prefixed_property_values, key=lambda p: total_prefixed_property_values[p]):
     352            _log.info('  %s: %s', prefixed_value, total_prefixed_property_values[prefixed_value])
    339353
    340354    def remove_deleted_files(self, import_directory, new_file_list):
     
    362376        import_log.close()
    363377
    364     def write_import_log(self, import_directory, file_list, prop_list):
     378    def write_import_log(self, import_directory, file_list, prop_list, property_values_list):
    365379        """ Writes a w3c-import.log file in each directory with imported files. """
    366380
     
    385399        else:
    386400            import_log.write('None\n')
     401        import_log.write('Property values requiring vendor prefixes:\n')
     402        if property_values_list:
     403            for value in property_values_list:
     404                import_log.write(value + '\n')
     405        else:
     406            import_log.write('None\n')
    387407        import_log.write('------------------------------------------------------------------------\n')
    388408        import_log.write('List of files:\n')
Note: See TracChangeset for help on using the changeset viewer.