| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 try: | 198 try: |
| 199 converter.feed(test_html) | 199 converter.feed(test_html) |
| 200 converter.close() | 200 converter.close() |
| 201 converted = converter.output() | 201 converted = converter.output() |
| 202 finally: | 202 finally: |
| 203 oc.restore_output() | 203 oc.restore_output() |
| 204 | 204 |
| 205 self.verify_conversion_happened(converted) | 205 self.verify_conversion_happened(converted) |
| 206 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 2
, 1) | 206 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 2
, 1) |
| 207 | 207 |
| 208 def test_convert_vendor_prefix_js_paths(self): |
| 209 test_html = """<head> |
| 210 <script src="/common/vendor-prefix.js"> |
| 211 </head> |
| 212 """ |
| 213 fake_dir_path = self.fake_dir_path('adapterjspaths') |
| 214 converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME) |
| 215 |
| 216 oc = OutputCapture() |
| 217 oc.capture_output() |
| 218 try: |
| 219 converter.feed(test_html) |
| 220 converter.close() |
| 221 converted = converter.output() |
| 222 finally: |
| 223 oc.restore_output() |
| 224 |
| 225 new_html = BeautifulSoup(converted[1]) |
| 226 |
| 227 # Verify the original paths are gone, and the new paths are present. |
| 228 orig_path_pattern = re.compile('\"/common/vendor-prefix.js') |
| 229 self.assertEquals(len(new_html.findAll(src=orig_path_pattern)), 0, 'vend
or-prefix.js path was not converted') |
| 230 |
| 231 resources_dir = converter.path_from_webkit_root("LayoutTests", "resource
s") |
| 232 new_relpath = os.path.relpath(resources_dir, fake_dir_path) |
| 233 relpath_pattern = re.compile(new_relpath) |
| 234 self.assertEquals(len(new_html.findAll(src=relpath_pattern)), 1, 'vendor
-prefix.js relative path not correct') |
| 235 |
| 208 def test_convert_prefixed_properties(self): | 236 def test_convert_prefixed_properties(self): |
| 209 """ Tests convert_prefixed_properties() file that has 20 properties requ
iring the -webkit- prefix: | 237 """ Tests convert_prefixed_properties() file that has 20 properties requ
iring the -webkit- prefix: |
| 210 10 in one style block + 5 in another style | 238 10 in one style block + 5 in another style |
| 211 block + 5 inline styles, including one with multiple prefixed properties
. | 239 block + 5 inline styles, including one with multiple prefixed properties
. |
| 212 The properties in the test content are in all sorts of wack formatting. | 240 The properties in the test content are in all sorts of wack formatting. |
| 213 """ | 241 """ |
| 214 | 242 |
| 215 test_html = """<html> | 243 test_html = """<html> |
| 216 <style type="text/css"><![CDATA[ | 244 <style type="text/css"><![CDATA[ |
| 217 | 245 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 try: | 304 try: |
| 277 converter.feed(test_content[1]) | 305 converter.feed(test_content[1]) |
| 278 converter.close() | 306 converter.close() |
| 279 converted = converter.output() | 307 converted = converter.output() |
| 280 finally: | 308 finally: |
| 281 oc.restore_output() | 309 oc.restore_output() |
| 282 | 310 |
| 283 self.verify_conversion_happened(converted) | 311 self.verify_conversion_happened(converted) |
| 284 self.verify_prefixed_properties(converted, test_content[0]) | 312 self.verify_prefixed_properties(converted, test_content[0]) |
| 285 | 313 |
| 314 def test_hides_all_instructions_for_manual_testers(self): |
| 315 test_html = """<body> |
| 316 <h1 class="instructions">Hello manual tester!</h1> |
| 317 <p class="instructions some_other_class">This is how you run this test.</p> |
| 318 <p style="willbeoverwritten" class="instructions">...</p> |
| 319 <doesntmatterwhichtagitis class="some_other_class instructions">...</p> |
| 320 <p>Legit content may contain the instructions string</p> |
| 321 </body> |
| 322 """ |
| 323 expected_test_html = """<body> |
| 324 <h1 class="instructions" style="display:none">Hello manual tester!</h1> |
| 325 <p class="instructions some_other_class" style="display:none">This is how you ru
n this test.</p> |
| 326 <p class="instructions" style="display:none">...</p> |
| 327 <doesntmatterwhichtagitis class="some_other_class instructions" style="display:n
one">...</p> |
| 328 <p>Legit content may contain the instructions string</p> |
| 329 </body> |
| 330 """ |
| 331 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME) |
| 332 |
| 333 oc = OutputCapture() |
| 334 oc.capture_output() |
| 335 try: |
| 336 converter.feed(test_html) |
| 337 converter.close() |
| 338 converted = converter.output() |
| 339 finally: |
| 340 oc.restore_output() |
| 341 |
| 342 self.assertEqual(converted[1], expected_test_html) |
| 343 |
| 286 def verify_conversion_happened(self, converted): | 344 def verify_conversion_happened(self, converted): |
| 287 self.assertTrue(converted, "conversion didn't happen") | 345 self.assertTrue(converted, "conversion didn't happen") |
| 288 | 346 |
| 289 def verify_no_conversion_happened(self, converted, original): | 347 def verify_no_conversion_happened(self, converted, original): |
| 290 self.assertEqual(converted[1], original, 'test should not have been conv
erted') | 348 self.assertEqual(converted[1], original, 'test should not have been conv
erted') |
| 291 | 349 |
| 292 def verify_test_harness_paths(self, converter, converted, test_path, num_src
_paths, num_href_paths): | 350 def verify_test_harness_paths(self, converter, converted, test_path, num_src
_paths, num_href_paths): |
| 293 if isinstance(converted, basestring): | 351 if isinstance(converted, basestring): |
| 294 converted = BeautifulSoup(converted) | 352 converted = BeautifulSoup(converted) |
| 295 | 353 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 322 # through the list to replace the double-digit tokens first | 380 # through the list to replace the double-digit tokens first |
| 323 index = len(test_properties) - 1 | 381 index = len(test_properties) - 1 |
| 324 while index >= 0: | 382 while index >= 0: |
| 325 # Use the unprefixed version | 383 # Use the unprefixed version |
| 326 test_prop = test_properties[index].replace('-webkit-', '') | 384 test_prop = test_properties[index].replace('-webkit-', '') |
| 327 # Replace the token | 385 # Replace the token |
| 328 html = html.replace('@test' + str(index) + '@', test_prop) | 386 html = html.replace('@test' + str(index) + '@', test_prop) |
| 329 index -= 1 | 387 index -= 1 |
| 330 | 388 |
| 331 return (test_properties, html) | 389 return (test_properties, html) |
| OLD | NEW |