OLD | NEW |
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 logging |
30 import re | 31 import re |
31 | 32 |
32 from webkitpy.common.host import Host | 33 from webkitpy.common.host import Host |
33 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup, Tag | 34 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup, Tag |
34 | 35 |
35 | 36 |
| 37 _log = logging.getLogger(__name__) |
| 38 |
| 39 |
36 class W3CTestConverter(object): | 40 class W3CTestConverter(object): |
37 | 41 |
38 def __init__(self): | 42 def __init__(self): |
39 self._host = Host() | 43 self._host = Host() |
40 self._filesystem = self._host.filesystem | 44 self._filesystem = self._host.filesystem |
41 self._host.initialize_scm() | 45 self._host.initialize_scm() |
42 self._webkit_root = self._host.scm().checkout_root | 46 self._webkit_root = self._host.scm().checkout_root |
43 | 47 |
44 # These settings might vary between WebKit and Blink | 48 # These settings might vary between WebKit and Blink |
45 self._css_property_file = self.path_from_webkit_root('Source', 'core', '
css', 'CSSPropertyNames.in') | 49 self._css_property_file = self.path_from_webkit_root('Source', 'core', '
css', 'CSSPropertyNames.in') |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 105 |
102 resources_path = self.path_from_webkit_root('LayoutTests', 'resources') | 106 resources_path = self.path_from_webkit_root('LayoutTests', 'resources') |
103 resources_relpath = self._filesystem.relpath(resources_path, new_path) | 107 resources_relpath = self._filesystem.relpath(resources_path, new_path) |
104 | 108 |
105 for tag in testharness_tags: | 109 for tag in testharness_tags: |
106 # FIXME: We need to handle img, audio, video tags also. | 110 # FIXME: We need to handle img, audio, video tags also. |
107 attr = 'src' | 111 attr = 'src' |
108 if tag.name != 'script': | 112 if tag.name != 'script': |
109 attr = 'href' | 113 attr = 'href' |
110 | 114 |
111 if not attr in tag: | 115 if not attr in tag.attrMap: |
112 # FIXME: Figure out what to do w/ invalid tags. For now, we retu
rn False | 116 # FIXME: Figure out what to do w/ invalid tags. For now, we retu
rn False |
113 # and leave the document unmodified, which means that it'll prob
ably fail to run. | 117 # and leave the document unmodified, which means that it'll prob
ably fail to run. |
114 print "Error: missing an attr in %s" % filename | 118 _log.error("Missing an attr in %s" % filename) |
115 return False | 119 return False |
116 | 120 |
117 old_path = tag[attr] | 121 old_path = tag[attr] |
118 new_tag = Tag(doc, tag.name, tag.attrs) | 122 new_tag = Tag(doc, tag.name, tag.attrs) |
119 new_tag[attr] = re.sub(pattern, resources_relpath + '/testharness',
old_path) | 123 new_tag[attr] = re.sub(pattern, resources_relpath + '/testharness',
old_path) |
120 | 124 |
121 self.replace_tag(tag, new_tag) | 125 self.replace_tag(tag, new_tag) |
122 | 126 |
123 return True | 127 return True |
124 | 128 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 # FIXME: add in both the prefixed and unprefixed versions, rather th
an just replacing them? | 173 # FIXME: add in both the prefixed and unprefixed versions, rather th
an just replacing them? |
170 # That might allow the imported test to work in other browsers more
easily. | 174 # That might allow the imported test to work in other browsers more
easily. |
171 | 175 |
172 unprefixed_property = prefixed_property.replace('-webkit-', '') | 176 unprefixed_property = prefixed_property.replace('-webkit-', '') |
173 | 177 |
174 # Look for the various ways it might be in the CSS | 178 # Look for the various ways it might be in the CSS |
175 # Match the the property preceded by either whitespace or left curly
brace | 179 # Match the the property preceded by either whitespace or left curly
brace |
176 # or at the beginning of the string (for inline style attribute) | 180 # or at the beginning of the string (for inline style attribute) |
177 pattern = '([\s{]|^)' + unprefixed_property + '(\s+:|:)' | 181 pattern = '([\s{]|^)' + unprefixed_property + '(\s+:|:)' |
178 if re.search(pattern, text): | 182 if re.search(pattern, text): |
179 print 'converting %s -> %s' % (unprefixed_property, prefixed_pro
perty) | 183 _log.info('converting %s -> %s' % (unprefixed_property, prefixed
_property)) |
180 converted_properties.append(prefixed_property) | 184 converted_properties.append(prefixed_property) |
181 text = re.sub(pattern, prefixed_property + ':', text) | 185 text = re.sub(pattern, prefixed_property + ':', text) |
182 | 186 |
183 # FIXME: Handle the JS versions of these properties and GetComputedStyle
, too. | 187 # FIXME: Handle the JS versions of these properties and GetComputedStyle
, too. |
184 return (converted_properties, text) | 188 return (converted_properties, text) |
185 | 189 |
186 def replace_tag(self, old_tag, new_tag): | 190 def replace_tag(self, old_tag, new_tag): |
187 index = old_tag.parent.contents.index(old_tag) | 191 index = old_tag.parent.contents.index(old_tag) |
188 old_tag.parent.insert(index, new_tag) | 192 old_tag.parent.insert(index, new_tag) |
189 old_tag.extract() | 193 old_tag.extract() |
OLD | NEW |