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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_converter_unittest.py

Issue 2016953002: update-w3c-deps: Do not rewrite links to /resources and /common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a comment, fix python tests Created 4 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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 oc.capture_output() 85 oc.capture_output()
86 try: 86 try:
87 converter.feed(test_html) 87 converter.feed(test_html)
88 converter.close() 88 converter.close()
89 converted = converter.output() 89 converted = converter.output()
90 finally: 90 finally:
91 oc.restore_output() 91 oc.restore_output()
92 92
93 self.verify_no_conversion_happened(converted, test_html) 93 self.verify_no_conversion_happened(converted, test_html)
94 94
95 def test_convert_for_webkit_harness_only(self):
96 """ Tests convert_for_webkit() using a basic JS test that uses testharne ss.js only and has no prefixed properties """
97
98 test_html = """<head>
99 <link href="/resources/testharness.css" rel="stylesheet" type="text/css">
100 <script src="/resources/testharness.js"></script>
101 </head>
102 """
103 fake_dir_path = self.fake_dir_path("harnessonly")
104 converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None)
105 converter.feed(test_html)
106 converter.close()
107 converted = converter.output()
108
109 self.verify_conversion_happened(converted)
110 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1 , 1)
111 self.verify_prefixed_properties(converted, [])
112
113 def test_convert_for_webkit_properties_only(self): 95 def test_convert_for_webkit_properties_only(self):
114 """ Tests convert_for_webkit() using a test that has 2 prefixed properti es: 1 in a style block + 1 inline style """ 96 """ Tests convert_for_webkit() using a test that has 2 prefixed properti es: 1 in a style block + 1 inline style """
115 97
116 test_html = """<html> 98 test_html = """<html>
117 <head> 99 <head>
118 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> 100 <link href="/resources/testharness.css" rel="stylesheet" type="text/css">
119 <script src="/resources/testharness.js"></script> 101 <script src="/resources/testharness.js"></script>
120 <style type="text/css"> 102 <style type="text/css">
121 103
122 #block1 { @test0@: propvalue; } 104 #block1 { @test0@: propvalue; }
(...skipping 12 matching lines...) Expand all
135 oc = OutputCapture() 117 oc = OutputCapture()
136 oc.capture_output() 118 oc.capture_output()
137 try: 119 try:
138 converter.feed(test_content[1]) 120 converter.feed(test_content[1])
139 converter.close() 121 converter.close()
140 converted = converter.output() 122 converted = converter.output()
141 finally: 123 finally:
142 oc.restore_output() 124 oc.restore_output()
143 125
144 self.verify_conversion_happened(converted) 126 self.verify_conversion_happened(converted)
145 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1 , 1)
146 self.verify_prefixed_properties(converted, test_content[0]) 127 self.verify_prefixed_properties(converted, test_content[0])
147 128
148 def test_convert_for_webkit_harness_and_properties(self):
149 """ 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 """
150
151 test_html = """<html>
152 <head>
153 <link href="/resources/testharness.css" rel="stylesheet" type="text/css">
154 <script src="/resources/testharness.js"></script>
155 <style type="text/css">
156
157 #block1 { @test0@: propvalue; }
158 #block2 { @test1@: propvalue; }
159 #block3 { @test2@: propvalue; }
160
161 </style>
162 </head>
163 <body>
164 <div id="elem1" style="@test3@: propvalue;"></div>
165 </body>
166 </html>
167 """
168 fake_dir_path = self.fake_dir_path('harnessandprops')
169 converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None)
170
171 oc = OutputCapture()
172 oc.capture_output()
173 try:
174 test_content = self.generate_test_content(converter.prefixed_propert ies, 2, test_html)
175 converter.feed(test_content[1])
176 converter.close()
177 converted = converter.output()
178 finally:
179 oc.restore_output()
180
181 self.verify_conversion_happened(converted)
182 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1 , 1)
183 self.verify_prefixed_properties(converted, test_content[0])
184
185 def test_convert_test_harness_paths(self):
186 """ Tests convert_testharness_paths() with a test that uses multiple tes tharness files """
187
188 test_html = """<head>
189 <link href="/resources/testharness.css" rel="stylesheet" type="text/css">
190 <script src="/resources/testharness.js"></script>
191 <script src="/resources/testharnessreport.js"></script>
192 <script src="/resources/WebIDLParser.js"></script>
193 <script src="/resources/idlharness.js"></script>
194 </head>
195 """
196 fake_dir_path = self.fake_dir_path('testharnesspaths')
197 converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None)
198
199 oc = OutputCapture()
200 oc.capture_output()
201 try:
202 converter.feed(test_html)
203 converter.close()
204 converted = converter.output()
205 finally:
206 oc.restore_output()
207
208 self.verify_conversion_happened(converted)
209 self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 4 , 1)
210
211 def test_convert_vendor_prefix_js_paths(self):
212 test_html = """<head>
213 <script src="/common/vendor-prefix.js">
214 </head>
215 """
216 fake_dir_path = self.fake_dir_path('adapterjspaths')
217 converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None)
218
219 oc = OutputCapture()
220 oc.capture_output()
221 try:
222 converter.feed(test_html)
223 converter.close()
224 converted = converter.output()
225 finally:
226 oc.restore_output()
227
228 new_html = BeautifulSoup(converted[1])
229
230 # Verify the original paths are gone, and the new paths are present.
231 orig_path_pattern = re.compile('\"/common/vendor-prefix.js')
232 self.assertEquals(len(new_html.findAll(src=orig_path_pattern)), 0, 'vend or-prefix.js path was not converted')
233
234 resources_dir = converter.path_from_webkit_root("LayoutTests", "resource s")
235 new_relpath = os.path.relpath(resources_dir, fake_dir_path)
236 relpath_pattern = re.compile(new_relpath)
237 self.assertEquals(len(new_html.findAll(src=relpath_pattern)), 1, 'vendor -prefix.js relative path not correct')
238
239 def test_convert_prefixed_properties(self): 129 def test_convert_prefixed_properties(self):
240 """ Tests convert_prefixed_properties() file that has 20 properties requ iring the -webkit- prefix: 130 """ Tests convert_prefixed_properties() file that has 20 properties requ iring the -webkit- prefix:
241 10 in one style block + 5 in another style 131 10 in one style block + 5 in another style
242 block + 5 inline styles, including one with multiple prefixed properties . 132 block + 5 inline styles, including one with multiple prefixed properties .
243 2 when prefixed properties appear in comments without ending ';'. 133 2 when prefixed properties appear in comments without ending ';'.
244 The properties in the test content are in all sorts of wack formatting. 134 The properties in the test content are in all sorts of wack formatting.
245 """ 135 """
246 136
247 test_html = """<html> 137 test_html = """<html>
248 <style type="text/css"><![CDATA[ 138 <style type="text/css"><![CDATA[
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 269
380 self.verify_conversion_happened(converted) 270 self.verify_conversion_happened(converted)
381 self.verify_reference_relative_paths(converted, test_reference_support_i nfo) 271 self.verify_reference_relative_paths(converted, test_reference_support_i nfo)
382 272
383 def verify_conversion_happened(self, converted): 273 def verify_conversion_happened(self, converted):
384 self.assertTrue(converted, "conversion didn't happen") 274 self.assertTrue(converted, "conversion didn't happen")
385 275
386 def verify_no_conversion_happened(self, converted, original): 276 def verify_no_conversion_happened(self, converted, original):
387 self.assertEqual(converted[1], original, 'test should not have been conv erted') 277 self.assertEqual(converted[1], original, 'test should not have been conv erted')
388 278
389 def verify_test_harness_paths(self, converter, converted, test_path, num_src _paths, num_href_paths):
390 if isinstance(converted, basestring):
391 converted = BeautifulSoup(converted)
392
393 resources_dir = converter.path_from_webkit_root("LayoutTests", "resource s")
394
395 # Verify the original paths are gone, and the new paths are present.
396 orig_path_pattern = re.compile('\"/resources/testharness')
397 self.assertEquals(len(converted.findAll(src=orig_path_pattern)), 0, 'tes tharness src path was not converted')
398 self.assertEquals(len(converted.findAll(href=orig_path_pattern)), 0, 'te stharness href path was not converted')
399
400 new_relpath = os.path.relpath(resources_dir, test_path)
401 relpath_pattern = re.compile(new_relpath)
402 self.assertEquals(len(converted.findAll(src=relpath_pattern)), num_src_p aths, 'testharness src relative path not correct')
403 self.assertEquals(len(converted.findAll(href=relpath_pattern)),
404 num_href_paths, 'testharness href relative path not co rrect')
405
406 def verify_prefixed_properties(self, converted, test_properties): 279 def verify_prefixed_properties(self, converted, test_properties):
407 self.assertEqual(len(set(converted[0])), len(set(test_properties)), 'Inc orrect number of properties converted') 280 self.assertEqual(len(set(converted[0])), len(set(test_properties)), 'Inc orrect number of properties converted')
408 for test_prop in test_properties: 281 for test_prop in test_properties:
409 self.assertTrue((test_prop in converted[1]), 'Property ' + test_prop + ' not found in converted doc') 282 self.assertTrue((test_prop in converted[1]), 'Property ' + test_prop + ' not found in converted doc')
410 283
411 def verify_reference_relative_paths(self, converted, reference_support_info) : 284 def verify_reference_relative_paths(self, converted, reference_support_info) :
412 idx = 0 285 idx = 0
413 for path in reference_support_info['files']: 286 for path in reference_support_info['files']:
414 expected_path = re.sub(reference_support_info['reference_relpath'], '', path, 1) 287 expected_path = re.sub(reference_support_info['reference_relpath'], '', path, 1)
415 element = reference_support_info['elements'][idx] 288 element = reference_support_info['elements'][idx]
(...skipping 13 matching lines...) Expand all
429 # through the list to replace the double-digit tokens first 302 # through the list to replace the double-digit tokens first
430 index = len(test_properties) - 1 303 index = len(test_properties) - 1
431 while index >= 0: 304 while index >= 0:
432 # Use the unprefixed version 305 # Use the unprefixed version
433 test_prop = test_properties[index].replace('-webkit-', '') 306 test_prop = test_properties[index].replace('-webkit-', '')
434 # Replace the token 307 # Replace the token
435 html = html.replace('@test' + str(index) + '@', test_prop) 308 html = html.replace('@test' + str(index) + '@', test_prop)
436 index -= 1 309 index -= 1
437 310
438 return (test_properties, html) 311 return (test_properties, html)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698