Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1046)

Side by Side Diff: Tools/Scripts/webkitpy/w3c/test_converter.py

Issue 1158193002: Enable test_converter.py to import CSS Writing Modes test suites (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 3 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions 6 # modification, are permitted provided that the following conditions
7 # are met: 7 # are met:
8 # 8 #
9 # 1. Redistributions of source code must retain the above 9 # 1. Redistributions of source code must retain the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
11 # disclaimer. 11 # disclaimer.
12 # 2. Redistributions in binary form must reproduce the above 12 # 2. Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following 13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials 14 # disclaimer in the documentation and/or other materials
15 # provided with the distribution. 15 # provided with the distribution.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # SUCH DAMAGE. 28 # SUCH DAMAGE.
29 29
30 import itertools
30 import logging 31 import logging
31 import re 32 import re
32 33
33 from webkitpy.common.host import Host 34 from webkitpy.common.host import Host
34 from webkitpy.common.webkit_finder import WebKitFinder 35 from webkitpy.common.webkit_finder import WebKitFinder
35 from HTMLParser import HTMLParser 36 from HTMLParser import HTMLParser
36 37
37 38
38 _log = logging.getLogger(__name__) 39 _log = logging.getLogger(__name__)
39 40
(...skipping 28 matching lines...) Expand all
68 self.reference_support_info = reference_support_info 69 self.reference_support_info = reference_support_info
69 70
70 resources_path = self.path_from_webkit_root('LayoutTests', 'resources') 71 resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
71 resources_relpath = self._filesystem.relpath(resources_path, new_path) 72 resources_relpath = self._filesystem.relpath(resources_path, new_path)
72 self.resources_relpath = resources_relpath 73 self.resources_relpath = resources_relpath
73 74
74 # These settings might vary between WebKit and Blink 75 # These settings might vary between WebKit and Blink
75 self._css_property_file = self.path_from_webkit_root('Source', 'core', ' css', 'CSSProperties.in') 76 self._css_property_file = self.path_from_webkit_root('Source', 'core', ' css', 'CSSProperties.in')
76 77
77 self.prefixed_properties = self.read_webkit_prefixed_css_property_list() 78 self.prefixed_properties = self.read_webkit_prefixed_css_property_list()
79 self.prefixed_values = {
80 'unicode-bidi': ['isolate', 'isolate-override', 'plaintext']
81 }
82 self.renamed_properties = {
83 'text-combine-upright': '-webkit-text-combine'
84 }
85 self.renamed_values = {
86 'text-combine-upright': {'all': 'horizontal'}
Dirk Pranke 2015/05/27 22:52:59 Is there a reason we can't just add support for th
kojii 2015/05/27 23:47:38 Replied above.
87 }
Dirk Pranke 2015/05/27 22:52:59 this section could use some comments describing sp
kojii 2015/05/27 23:47:38 I'll add and re-upload, but allow me to reply as t
78 88
79 self.prefixed_properties = self.read_webkit_prefixed_css_property_list() 89 prop_regex = '([\s{]|^)(' + "|".join(itertools.chain(
80 prop_regex = '([\s{]|^)(' + "|".join(prop.replace('-webkit-', '') for pr op in self.prefixed_properties) + ')(\s+:|:)' 90 self.renamed_properties.iterkeys(),
91 self.renamed_values.iterkeys(),
92 self.prefixed_values.iterkeys(),
93 (prop.replace('-webkit-', '') for prop in self.prefixed_properties)) ) + ')(\s+:|:[^;]*)'
81 self.prop_re = re.compile(prop_regex) 94 self.prop_re = re.compile(prop_regex)
82 95
83 def output(self): 96 def output(self):
84 return (self.converted_properties, ''.join(self.converted_data)) 97 return (self.converted_properties, ''.join(self.converted_data))
85 98
86 def path_from_webkit_root(self, *comps): 99 def path_from_webkit_root(self, *comps):
87 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps)) 100 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps))
88 101
89 def read_webkit_prefixed_css_property_list(self): 102 def read_webkit_prefixed_css_property_list(self):
90 prefixed_properties = [] 103 prefixed_properties = []
91 unprefixed_properties = set() 104 unprefixed_properties = set()
92 105
93 contents = self._filesystem.read_text_file(self._css_property_file) 106 contents = self._filesystem.read_text_file(self._css_property_file)
94 for line in contents.splitlines(): 107 for line in contents.splitlines():
95 if re.match('^(#|//|$)', line): 108 if re.match('^(#|//|$)', line):
96 # skip comments and preprocessor directives 109 # skip comments and preprocessor directives
97 continue 110 continue
98 prop = line.split()[0] 111 prop = line.split()[0]
99 # Find properties starting with the -webkit- prefix. 112 # Find properties starting with the -webkit- prefix.
100 match = re.match('-webkit-([\w|-]*)', prop) 113 match = re.match('-webkit-([\w|-]*)', prop)
101 if match: 114 if match:
102 prefixed_properties.append(match.group(1)) 115 prefixed_properties.append(match.group(1))
103 else: 116 else:
104 unprefixed_properties.add(prop.strip()) 117 unprefixed_properties.add(prop.strip())
105 118
119 # SVG writing-mode exists, but CSS writing-mode is still prefixed
120 unprefixed_properties.discard('writing-mode')
Dirk Pranke 2015/05/27 22:52:59 I don't think I understand this change; if we stil
kojii 2015/05/27 23:47:38 There are two properties, "writing-mode" and "-web
Dirk Pranke 2015/05/28 01:25:49 Will this likely cause problems if we import some
121
106 # Ignore any prefixed properties for which an unprefixed version is supp orted 122 # Ignore any prefixed properties for which an unprefixed version is supp orted
107 return [prop for prop in prefixed_properties if prop not in unprefixed_p roperties] 123 return set(prop for prop in prefixed_properties if prop not in unprefixe d_properties)
Dirk Pranke 2015/05/27 22:52:59 why did this change to a set() ?
kojii 2015/05/27 23:47:38 Because line #139 uses "in" operator to check if t
Dirk Pranke 2015/05/28 01:25:49 Okay. `in` actually works with both lists and sets
108 124
109 def add_webkit_prefix_to_unprefixed_properties(self, text): 125 def add_webkit_prefix_to_unprefixed_properties(self, text):
110 """ Searches |text| for instances of properties requiring the -webkit- p refix and adds the prefix to them. 126 """ Searches |text| for instances of properties requiring the -webkit- p refix and adds the prefix to them.
111 127
112 Returns the list of converted properties and the modified text.""" 128 Returns the list of converted properties and the modified text."""
113 129
114 converted_properties = set() 130 converted_properties = set()
115 text_chunks = [] 131 text_chunks = []
116 cur_pos = 0 132 cur_pos = 0
117 for m in self.prop_re.finditer(text): 133 for m in self.prop_re.finditer(text):
118 text_chunks.extend([text[cur_pos:m.start()], m.group(1), '-webkit-', m.group(2), m.group(3)]) 134 text_chunks.extend([text[cur_pos:m.start()], m.group(1)])
119 converted_properties.add(m.group(2)) 135 property = m.group(2)
136 oldProperty = self.renamed_properties.get(property)
137 if oldProperty:
138 text_chunks.append(oldProperty)
139 elif property in self.prefixed_properties:
140 text_chunks.extend(['-webkit-', property])
141 else:
142 text_chunks.append(property)
143 text_chunks.append(self.add_webkit_prefix_to_unprefixed_value(proper ty, m.group(3)))
144 converted_properties.add(property)
120 cur_pos = m.end() 145 cur_pos = m.end()
121 text_chunks.append(text[cur_pos:]) 146 text_chunks.append(text[cur_pos:])
122 147
123 for prop in converted_properties: 148 for prop in converted_properties:
124 _log.info(' converting %s', prop) 149 _log.info(' converting %s', prop)
125 150
126 # FIXME: Handle the JS versions of these properties and GetComputedStyle , too. 151 # FIXME: Handle the JS versions of these properties and GetComputedStyle , too.
127 return (converted_properties, ''.join(text_chunks)) 152 return (converted_properties, ''.join(text_chunks))
128 153
154 def add_webkit_prefix_to_unprefixed_value(self, property, text):
155 renamed_values = self.renamed_values.get(property)
156 if renamed_values:
157 text = re.sub("|".join(renamed_values.iterkeys()), lambda m: renamed _values[m.group(0)], text)
158 prefixed_values = self.prefixed_values.get(property)
159 if prefixed_values:
160 text = re.sub("|".join(prefixed_values), lambda m: '-webkit-' + m.gr oup(0), text)
161 return text
162
129 def convert_reference_relpaths(self, text): 163 def convert_reference_relpaths(self, text):
130 """ Searches |text| for instances of files in reference_support_info and updates the relative path to be correct for the new ref file location""" 164 """ Searches |text| for instances of files in reference_support_info and updates the relative path to be correct for the new ref file location"""
131 165
132 converted = text 166 converted = text
133 for path in self.reference_support_info['files']: 167 for path in self.reference_support_info['files']:
134 if text.find(path) != -1: 168 if text.find(path) != -1:
135 # FIXME: This doesn't handle an edge case where simply removing the relative path doesn't work. 169 # FIXME: This doesn't handle an edge case where simply removing the relative path doesn't work.
136 # See crbug.com/421584 for details. 170 # See crbug.com/421584 for details.
137 new_path = re.sub(self.reference_support_info['reference_relpath '], '', path, 1) 171 new_path = re.sub(self.reference_support_info['reference_relpath '], '', path, 1)
138 converted = re.sub(path, new_path, text) 172 converted = re.sub(path, new_path, text)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 self.converted_data.extend(['&#', name, ';']) 246 self.converted_data.extend(['&#', name, ';'])
213 247
214 def handle_comment(self, data): 248 def handle_comment(self, data):
215 self.converted_data.extend(['<!-- ', data, ' -->']) 249 self.converted_data.extend(['<!-- ', data, ' -->'])
216 250
217 def handle_decl(self, decl): 251 def handle_decl(self, decl):
218 self.converted_data.extend(['<!', decl, '>']) 252 self.converted_data.extend(['<!', decl, '>'])
219 253
220 def handle_pi(self, data): 254 def handle_pi(self, data):
221 self.converted_data.extend(['<?', data, '>']) 255 self.converted_data.extend(['<?', data, '>'])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698