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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 import os | 30 import os |
31 import re | 31 import re |
32 import unittest2 as unittest | 32 import unittest2 as unittest |
33 | 33 |
34 from webkitpy.common.system.outputcapture import OutputCapture | 34 from webkitpy.common.system.outputcapture import OutputCapture |
35 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup | 35 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup |
36 from webkitpy.w3c.test_converter import W3CTestConverter | 36 from webkitpy.w3c.test_converter import W3CTestConverter |
37 | 37 |
38 | 38 |
| 39 DUMMY_FILENAME = 'dummy.html' |
| 40 |
39 class W3CTestConverterTest(unittest.TestCase): | 41 class W3CTestConverterTest(unittest.TestCase): |
40 | 42 |
41 def fake_dir_path(self, converter, dirname): | 43 def fake_dir_path(self, converter, dirname): |
42 return converter.path_from_webkit_root("LayoutTests", "css", dirname) | 44 return converter.path_from_webkit_root("LayoutTests", "css", dirname) |
43 | 45 |
44 def test_read_prefixed_property_list(self): | 46 def test_read_prefixed_property_list(self): |
45 """ Tests that the current list of properties requiring the -webkit- pre
fix load correctly """ | 47 """ Tests that the current list of properties requiring the -webkit- pre
fix load correctly """ |
46 | 48 |
47 # FIXME: We should be passing in a MockHost here ... | 49 # FIXME: We should be passing in a MockHost here ... |
48 converter = W3CTestConverter() | 50 converter = W3CTestConverter() |
(...skipping 21 matching lines...) Expand all Loading... |
70 <body> | 72 <body> |
71 CONTENT OF TEST | 73 CONTENT OF TEST |
72 </body> | 74 </body> |
73 </html> | 75 </html> |
74 """ | 76 """ |
75 converter = W3CTestConverter() | 77 converter = W3CTestConverter() |
76 | 78 |
77 oc = OutputCapture() | 79 oc = OutputCapture() |
78 oc.capture_output() | 80 oc.capture_output() |
79 try: | 81 try: |
80 converted = converter.convert_html('/nothing/to/convert', test_html) | 82 converted = converter.convert_html('/nothing/to/convert', test_html,
DUMMY_FILENAME) |
81 finally: | 83 finally: |
82 oc.restore_output() | 84 oc.restore_output() |
83 | 85 |
84 self.verify_no_conversion_happened(converted) | 86 self.verify_no_conversion_happened(converted) |
85 | 87 |
86 def test_convert_for_webkit_harness_only(self): | 88 def test_convert_for_webkit_harness_only(self): |
87 """ Tests convert_for_webkit() using a basic JS test that uses testharne
ss.js only and has no prefixed properties """ | 89 """ Tests convert_for_webkit() using a basic JS test that uses testharne
ss.js only and has no prefixed properties """ |
88 | 90 |
89 test_html = """<head> | 91 test_html = """<head> |
90 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> | 92 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> |
91 <script src="/resources/testharness.js"></script> | 93 <script src="/resources/testharness.js"></script> |
92 </head> | 94 </head> |
93 """ | 95 """ |
94 converter = W3CTestConverter() | 96 converter = W3CTestConverter() |
95 fake_dir_path = self.fake_dir_path(converter, "harnessonly") | 97 fake_dir_path = self.fake_dir_path(converter, "harnessonly") |
96 | 98 |
97 converted = converter.convert_html(fake_dir_path, test_html) | 99 converted = converter.convert_html(fake_dir_path, test_html, DUMMY_FILEN
AME) |
98 | 100 |
99 self.verify_conversion_happened(converted) | 101 self.verify_conversion_happened(converted) |
100 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1
, 1) | 102 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1
, 1) |
101 self.verify_prefixed_properties(converted, []) | 103 self.verify_prefixed_properties(converted, []) |
102 | 104 |
103 def test_convert_for_webkit_properties_only(self): | 105 def test_convert_for_webkit_properties_only(self): |
104 """ Tests convert_for_webkit() using a test that has 2 prefixed properti
es: 1 in a style block + 1 inline style """ | 106 """ Tests convert_for_webkit() using a test that has 2 prefixed properti
es: 1 in a style block + 1 inline style """ |
105 | 107 |
106 test_html = """<html> | 108 test_html = """<html> |
107 <head> | 109 <head> |
(...skipping 10 matching lines...) Expand all Loading... |
118 </body> | 120 </body> |
119 </html> | 121 </html> |
120 """ | 122 """ |
121 converter = W3CTestConverter() | 123 converter = W3CTestConverter() |
122 fake_dir_path = self.fake_dir_path(converter, 'harnessandprops') | 124 fake_dir_path = self.fake_dir_path(converter, 'harnessandprops') |
123 test_content = self.generate_test_content(converter.prefixed_properties,
1, test_html) | 125 test_content = self.generate_test_content(converter.prefixed_properties,
1, test_html) |
124 | 126 |
125 oc = OutputCapture() | 127 oc = OutputCapture() |
126 oc.capture_output() | 128 oc.capture_output() |
127 try: | 129 try: |
128 converted = converter.convert_html(fake_dir_path, test_content[1]) | 130 converted = converter.convert_html(fake_dir_path, test_content[1], D
UMMY_FILENAME) |
129 finally: | 131 finally: |
130 oc.restore_output() | 132 oc.restore_output() |
131 | 133 |
132 self.verify_conversion_happened(converted) | 134 self.verify_conversion_happened(converted) |
133 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1
, 1) | 135 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1
, 1) |
134 self.verify_prefixed_properties(converted, test_content[0]) | 136 self.verify_prefixed_properties(converted, test_content[0]) |
135 | 137 |
136 def test_convert_for_webkit_harness_and_properties(self): | 138 def test_convert_for_webkit_harness_and_properties(self): |
137 """ Tests convert_for_webkit() using a basic JS test that uses testharne
ss.js and testharness.css and has 4 prefixed properties: 3 in a style block + 1
inline style """ | 139 """ Tests convert_for_webkit() using a basic JS test that uses testharne
ss.js and testharness.css and has 4 prefixed properties: 3 in a style block + 1
inline style """ |
138 | 140 |
(...skipping 14 matching lines...) Expand all Loading... |
153 </body> | 155 </body> |
154 </html> | 156 </html> |
155 """ | 157 """ |
156 converter = W3CTestConverter() | 158 converter = W3CTestConverter() |
157 fake_dir_path = self.fake_dir_path(converter, 'harnessandprops') | 159 fake_dir_path = self.fake_dir_path(converter, 'harnessandprops') |
158 | 160 |
159 oc = OutputCapture() | 161 oc = OutputCapture() |
160 oc.capture_output() | 162 oc.capture_output() |
161 try: | 163 try: |
162 test_content = self.generate_test_content(converter.prefixed_propert
ies, 2, test_html) | 164 test_content = self.generate_test_content(converter.prefixed_propert
ies, 2, test_html) |
163 converted = converter.convert_html(fake_dir_path, test_content[1]) | 165 converted = converter.convert_html(fake_dir_path, test_content[1], D
UMMY_FILENAME) |
164 finally: | 166 finally: |
165 oc.restore_output() | 167 oc.restore_output() |
166 | 168 |
167 self.verify_conversion_happened(converted) | 169 self.verify_conversion_happened(converted) |
168 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1
, 1) | 170 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1
, 1) |
169 self.verify_prefixed_properties(converted, test_content[0]) | 171 self.verify_prefixed_properties(converted, test_content[0]) |
170 | 172 |
171 def test_convert_test_harness_paths(self): | 173 def test_convert_test_harness_paths(self): |
172 """ Tests convert_testharness_paths() with a test that uses all three te
stharness files """ | 174 """ Tests convert_testharness_paths() with a test that uses all three te
stharness files """ |
173 | 175 |
174 test_html = """<head> | 176 test_html = """<head> |
175 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> | 177 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> |
176 <script src="/resources/testharness.js"></script> | 178 <script src="/resources/testharness.js"></script> |
177 <script src="/resources/testharnessreport.js"></script> | 179 <script src="/resources/testharnessreport.js"></script> |
178 </head> | 180 </head> |
179 """ | 181 """ |
180 converter = W3CTestConverter() | 182 converter = W3CTestConverter() |
181 | 183 |
182 fake_dir_path = self.fake_dir_path(converter, 'testharnesspaths') | 184 fake_dir_path = self.fake_dir_path(converter, 'testharnesspaths') |
183 | 185 |
184 doc = BeautifulSoup(test_html) | 186 doc = BeautifulSoup(test_html) |
185 oc = OutputCapture() | 187 oc = OutputCapture() |
186 oc.capture_output() | 188 oc.capture_output() |
187 try: | 189 try: |
188 converted = converter.convert_testharness_paths(doc, fake_dir_path) | 190 converted = converter.convert_testharness_paths(doc, fake_dir_path,
DUMMY_FILENAME) |
189 finally: | 191 finally: |
190 oc.restore_output() | 192 oc.restore_output() |
191 | 193 |
192 self.verify_conversion_happened(converted) | 194 self.verify_conversion_happened(converted) |
193 self.verify_test_harness_paths(converter, doc, fake_dir_path, 2, 1) | 195 self.verify_test_harness_paths(converter, doc, fake_dir_path, 2, 1) |
194 | 196 |
195 def test_convert_prefixed_properties(self): | 197 def test_convert_prefixed_properties(self): |
196 """ Tests convert_prefixed_properties() file that has 20 properties requ
iring the -webkit- prefix: | 198 """ Tests convert_prefixed_properties() file that has 20 properties requ
iring the -webkit- prefix: |
197 10 in one style block + 5 in another style | 199 10 in one style block + 5 in another style |
198 block + 5 inline styles, including one with multiple prefixed properties
. | 200 block + 5 inline styles, including one with multiple prefixed properties
. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 ]]></style> | 257 ]]></style> |
256 </html> | 258 </html> |
257 """ | 259 """ |
258 converter = W3CTestConverter() | 260 converter = W3CTestConverter() |
259 | 261 |
260 test_content = self.generate_test_content(converter.prefixed_properties,
20, test_html) | 262 test_content = self.generate_test_content(converter.prefixed_properties,
20, test_html) |
261 | 263 |
262 oc = OutputCapture() | 264 oc = OutputCapture() |
263 oc.capture_output() | 265 oc.capture_output() |
264 try: | 266 try: |
265 converted = converter.convert_prefixed_properties(BeautifulSoup(test
_content[1])) | 267 converted = converter.convert_prefixed_properties(BeautifulSoup(test
_content[1]), DUMMY_FILENAME) |
266 finally: | 268 finally: |
267 oc.restore_output() | 269 oc.restore_output() |
268 | 270 |
269 self.verify_conversion_happened(converted) | 271 self.verify_conversion_happened(converted) |
270 self.verify_prefixed_properties(converted, test_content[0]) | 272 self.verify_prefixed_properties(converted, test_content[0]) |
271 | 273 |
272 def verify_conversion_happened(self, converted): | 274 def verify_conversion_happened(self, converted): |
273 self.assertTrue(converted, "conversion didn't happen") | 275 self.assertTrue(converted, "conversion didn't happen") |
274 | 276 |
275 def verify_no_conversion_happened(self, converted): | 277 def verify_no_conversion_happened(self, converted): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 # through the list to replace the double-digit tokens first | 310 # through the list to replace the double-digit tokens first |
309 index = len(test_properties) - 1 | 311 index = len(test_properties) - 1 |
310 while index >= 0: | 312 while index >= 0: |
311 # Use the unprefixed version | 313 # Use the unprefixed version |
312 test_prop = test_properties[index].replace('-webkit-', '') | 314 test_prop = test_properties[index].replace('-webkit-', '') |
313 # Replace the token | 315 # Replace the token |
314 html = html.replace('@test' + str(index) + '@', test_prop) | 316 html = html.replace('@test' + str(index) + '@', test_prop) |
315 index -= 1 | 317 index -= 1 |
316 | 318 |
317 return (test_properties, html) | 319 return (test_properties, html) |
OLD | NEW |