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

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

Issue 15366004: update w3c import script to actually work :). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Tools/Scripts/webkitpy/w3c/test_importer.py » ('j') | 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
(...skipping 22 matching lines...) Expand all
33 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup, Tag 33 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup, Tag
34 34
35 35
36 class W3CTestConverter(object): 36 class W3CTestConverter(object):
37 37
38 def __init__(self): 38 def __init__(self):
39 self._host = Host() 39 self._host = Host()
40 self._filesystem = self._host.filesystem 40 self._filesystem = self._host.filesystem
41 self._host.initialize_scm() 41 self._host.initialize_scm()
42 self._webkit_root = self._host.scm().checkout_root 42 self._webkit_root = self._host.scm().checkout_root
43
44 # These settings might vary between WebKit and Blink
45 self._css_property_file = self.path_from_webkit_root('Source', 'core', ' css', 'CSSPropertyNames.in')
46 self._css_property_split_string = 'alias_for='
47
43 self.prefixed_properties = self.read_webkit_prefixed_css_property_list() 48 self.prefixed_properties = self.read_webkit_prefixed_css_property_list()
44 49
45 def path_from_webkit_root(self, *comps): 50 def path_from_webkit_root(self, *comps):
46 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps)) 51 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps))
47 52
48 def read_webkit_prefixed_css_property_list(self): 53 def read_webkit_prefixed_css_property_list(self):
49 prefixed_properties = [] 54 prefixed_properties = []
50 55
51 contents = self._filesystem.read_text_file(self.path_from_webkit_root('S ource', 'core', 'css', 'CSSPropertyNames.in')) 56 contents = self._filesystem.read_text_file(self._css_property_file)
52 for line in contents.splitlines(): 57 for line in contents.splitlines():
53 # Find lines starting with the -webkit- prefix. 58 # Find lines starting with the -webkit- prefix.
54 match = re.match('-webkit-[\w|-]*', line) 59 match = re.match('-webkit-[\w|-]*', line)
55 if match: 60 if match:
56 # Ignore lines where both the prefixed and non-prefixed property 61 # Ignore lines where both the prefixed and non-prefixed property
57 # are supported - denoted by -webkit-some-property = some-proper ty. 62 # are supported - denoted by -webkit-some-property = some-proper ty.
58 fields = line.split('alias_for=') 63 fields = line.split(self._css_property_split_string)
59 if len(fields) == 2 and fields[1].strip() in fields[0].strip(): 64 if len(fields) == 2 and fields[1].strip() in fields[0].strip():
60 continue 65 continue
61 prefixed_properties.append(match.group(0)) 66 prefixed_properties.append(match.group(0))
62 67
63 return prefixed_properties 68 return prefixed_properties
64 69
65 def convert_for_webkit(self, new_path, filename): 70 def convert_for_webkit(self, new_path, filename):
66 """ Converts a file's |contents| so it will function correctly in its |n ew_path| in Webkit. 71 """ Converts a file's |contents| so it will function correctly in its |n ew_path| in Webkit.
67 72
68 Returns the list of modified properties and the modified text if the fil e was modifed, None otherwise.""" 73 Returns the list of modified properties and the modified text if the fil e was modifed, None otherwise."""
69 contents = self._filesystem.read_text_file(filename) 74 contents = self._filesystem.read_binary_file(filename)
Dirk Pranke 2013/05/21 00:46:53 Note: here and below, we need to open the files as
70 if filename.endswith('.css'): 75 if filename.endswith('.css'):
71 return self.convert_css(contents) 76 return self.convert_css(contents)
72 return self.convert_html(new_path, contents) 77 return self.convert_html(new_path, contents)
73 78
74 def convert_css(self, contents): 79 def convert_css(self, contents):
75 return self.add_webkit_prefix_to_unprefixed_properties(contents) 80 return self.add_webkit_prefix_to_unprefixed_properties(contents)
76 81
77 def convert_html(self, new_path, contents): 82 def convert_html(self, new_path, contents):
78 doc = BeautifulSoup(contents) 83 doc = BeautifulSoup(contents)
79 did_modify_paths = self.convert_testharness_paths(doc, new_path) 84 did_modify_paths = self.convert_testharness_paths(doc, new_path)
(...skipping 11 matching lines...) Expand all
91 link_tags = doc.findAll(href=pattern) 96 link_tags = doc.findAll(href=pattern)
92 testharness_tags = script_tags + link_tags 97 testharness_tags = script_tags + link_tags
93 98
94 if not testharness_tags: 99 if not testharness_tags:
95 return False 100 return False
96 101
97 resources_path = self.path_from_webkit_root('LayoutTests', 'resources') 102 resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
98 resources_relpath = self._filesystem.relpath(resources_path, new_path) 103 resources_relpath = self._filesystem.relpath(resources_path, new_path)
99 104
100 for tag in testharness_tags: 105 for tag in testharness_tags:
106 # FIXME: We need to handle img, audio, video tags also.
101 attr = 'src' 107 attr = 'src'
102 if tag.name != 'script': 108 if tag.name != 'script':
103 attr = 'href' 109 attr = 'href'
104 110
105 old_path = tag[attr] 111 old_path = tag[attr]
106 new_tag = Tag(doc, tag.name, tag.attrs) 112 new_tag = Tag(doc, tag.name, tag.attrs)
107 new_tag[attr] = re.sub(pattern, resources_relpath + '/testharness', old_path) 113 new_tag[attr] = re.sub(pattern, resources_relpath + '/testharness', old_path)
108 114
109 self.replace_tag(tag, new_tag) 115 self.replace_tag(tag, new_tag)
110 116
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return (converted_properties, doc.prettify()) 153 return (converted_properties, doc.prettify())
148 154
149 def add_webkit_prefix_to_unprefixed_properties(self, text): 155 def add_webkit_prefix_to_unprefixed_properties(self, text):
150 """ Searches |text| for instances of properties requiring the -webkit- p refix and adds the prefix to them. 156 """ Searches |text| for instances of properties requiring the -webkit- p refix and adds the prefix to them.
151 157
152 Returns the list of converted properties and the modified text.""" 158 Returns the list of converted properties and the modified text."""
153 159
154 converted_properties = [] 160 converted_properties = []
155 161
156 for prefixed_property in self.prefixed_properties: 162 for prefixed_property in self.prefixed_properties:
163 # FIXME: add in both the prefixed and unprefixed versions, rather th an just replacing them?
164 # That might allow the imported test to work in other browsers more easily.
157 165
158 unprefixed_property = prefixed_property.replace('-webkit-', '') 166 unprefixed_property = prefixed_property.replace('-webkit-', '')
159 167
160 # Look for the various ways it might be in the CSS 168 # Look for the various ways it might be in the CSS
161 # Match the the property preceded by either whitespace or left curly brace 169 # Match the the property preceded by either whitespace or left curly brace
162 # or at the beginning of the string (for inline style attribute) 170 # or at the beginning of the string (for inline style attribute)
163 pattern = '([\s{]|^)' + unprefixed_property + '(\s+:|:)' 171 pattern = '([\s{]|^)' + unprefixed_property + '(\s+:|:)'
164 if re.search(pattern, text): 172 if re.search(pattern, text):
165 print 'converting %s -> %s' % (unprefixed_property, prefixed_pro perty) 173 print 'converting %s -> %s' % (unprefixed_property, prefixed_pro perty)
166 converted_properties.append(prefixed_property) 174 converted_properties.append(prefixed_property)
167 text = re.sub(pattern, prefixed_property + ':', text) 175 text = re.sub(pattern, prefixed_property + ':', text)
168 176
169 # FIXME: Handle the JS versions of these properties, too. 177 # FIXME: Handle the JS versions of these properties and GetComputedStyle , too.
170 return (converted_properties, text) 178 return (converted_properties, text)
171 179
172 def replace_tag(self, old_tag, new_tag): 180 def replace_tag(self, old_tag, new_tag):
173 index = old_tag.parent.contents.index(old_tag) 181 index = old_tag.parent.contents.index(old_tag)
174 old_tag.parent.insert(index, new_tag) 182 old_tag.parent.insert(index, new_tag)
175 old_tag.extract() 183 old_tag.extract()
OLDNEW
« no previous file with comments | « no previous file | Tools/Scripts/webkitpy/w3c/test_importer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698