| OLD | NEW |
| (Empty) |
| 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions | |
| 5 # are met: | |
| 6 # | |
| 7 # 1. Redistributions of source code must retain the above | |
| 8 # copyright notice, this list of conditions and the following | |
| 9 # disclaimer. | |
| 10 # 2. Redistributions in binary form must reproduce the above | |
| 11 # copyright notice, this list of conditions and the following | |
| 12 # disclaimer in the documentation and/or other materials | |
| 13 # provided with the distribution. | |
| 14 # | |
| 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY | |
| 16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE | |
| 19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
| 20 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
| 24 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | |
| 25 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 26 # SUCH DAMAGE. | |
| 27 | |
| 28 import re | |
| 29 import unittest | |
| 30 | |
| 31 from webkitpy.common.host import Host | |
| 32 from webkitpy.common.webkit_finder import WebKitFinder | |
| 33 from webkitpy.w3c.test_converter import _W3CTestConverter, convert_for_webkit | |
| 34 from webkitpy.common.system.system_host_mock import MockSystemHost | |
| 35 from webkitpy.common.system.filesystem_mock import MockFileSystem | |
| 36 | |
| 37 DUMMY_FILENAME = 'dummy.html' | |
| 38 DUMMY_PATH = 'dummy/testharness/path' | |
| 39 | |
| 40 | |
| 41 class W3CTestConverterTest(unittest.TestCase): | |
| 42 | |
| 43 # FIXME: When we move to using a MockHost, this method should be removed, si
nce | |
| 44 # then we can just pass in a dummy dir path | |
| 45 def fake_dir_path(self, dirname): | |
| 46 filesystem = Host().filesystem | |
| 47 webkit_root = WebKitFinder(filesystem).webkit_base() | |
| 48 return filesystem.abspath(filesystem.join(webkit_root, 'LayoutTests', 'c
ss', dirname)) | |
| 49 | |
| 50 def test_read_prefixed_property_list(self): | |
| 51 """Tests that the current list of properties requiring the -webkit- pref
ix load correctly.""" | |
| 52 | |
| 53 # FIXME: We should be passing in a MockHost here ... | |
| 54 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) | |
| 55 prop_list = converter.prefixed_properties | |
| 56 self.assertTrue(prop_list, 'No prefixed properties found') | |
| 57 | |
| 58 def test_convert_for_webkit_nothing_to_convert(self): | |
| 59 """Tests convert_for_webkit() using a basic test that has nothing to con
vert.""" | |
| 60 | |
| 61 test_html = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
| 62 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
| 63 <html xmlns="http://www.w3.org/1999/xhtml"> | |
| 64 <head> | |
| 65 <title>CSS Test: DESCRIPTION OF TEST</title> | |
| 66 <link rel="author" title="NAME_OF_AUTHOR" | |
| 67 href="mailto:EMAIL OR http://CONTACT_PAGE"/> | |
| 68 <link rel="help" href="RELEVANT_SPEC_SECTION"/> | |
| 69 <meta name="assert" content="TEST ASSERTION"/> | |
| 70 <style type="text/css"><![CDATA[ | |
| 71 CSS FOR TEST | |
| 72 ]]></style> | |
| 73 </head> | |
| 74 <body> | |
| 75 CONTENT OF TEST | |
| 76 </body> | |
| 77 </html> | |
| 78 """ | |
| 79 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) | |
| 80 | |
| 81 converter.feed(test_html) | |
| 82 converter.close() | |
| 83 converted = converter.output() | |
| 84 | |
| 85 self.verify_no_conversion_happened(converted, test_html) | |
| 86 | |
| 87 def test_convert_for_webkit_properties_only(self): | |
| 88 """Tests convert_for_webkit() using a test that has 2 prefixed propertie
s: 1 in a style block + 1 inline style.""" | |
| 89 | |
| 90 test_html = """<html> | |
| 91 <head> | |
| 92 <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> | |
| 93 <script src="/resources/testharness.js"></script> | |
| 94 <style type="text/css"> | |
| 95 | |
| 96 #block1 { @test0@: propvalue; } | |
| 97 | |
| 98 </style> | |
| 99 </head> | |
| 100 <body> | |
| 101 <div id="elem1" style="@test1@: propvalue;"></div> | |
| 102 </body> | |
| 103 </html> | |
| 104 """ | |
| 105 fake_dir_path = self.fake_dir_path('harnessandprops') | |
| 106 converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) | |
| 107 test_content = self.generate_test_content(converter.prefixed_properties,
1, test_html) | |
| 108 | |
| 109 converter.feed(test_content[1]) | |
| 110 converter.close() | |
| 111 converted = converter.output() | |
| 112 | |
| 113 self.verify_conversion_happened(converted) | |
| 114 self.verify_prefixed_properties(converted, test_content[0]) | |
| 115 | |
| 116 def test_convert_prefixed_properties(self): | |
| 117 """Tests convert_prefixed_properties() file that has 20 properties requi
ring the -webkit- prefix. | |
| 118 | |
| 119 The properties are: | |
| 120 10 in one style block + 5 in another style | |
| 121 block + 5 inline styles, including one with multiple prefixed properties
. | |
| 122 2 when prefixed properties appear in comments without ending ';'. | |
| 123 | |
| 124 The properties in the test content are in all sorts of wack formatting. | |
| 125 """ | |
| 126 | |
| 127 test_html = """<html> | |
| 128 <style type="text/css"><![CDATA[ | |
| 129 | |
| 130 .block1 { | |
| 131 width: 300px; | |
| 132 height: 300px | |
| 133 } | |
| 134 | |
| 135 .block2 { | |
| 136 @test0@: propvalue; | |
| 137 } | |
| 138 | |
| 139 .block3{@test1@: propvalue;} | |
| 140 | |
| 141 .block4 { @test2@:propvalue; } | |
| 142 | |
| 143 .block5{ @test3@ :propvalue; } | |
| 144 | |
| 145 #block6 { @test4@ : propvalue; } | |
| 146 | |
| 147 #block7 | |
| 148 { | |
| 149 @test5@: propvalue; | |
| 150 } | |
| 151 | |
| 152 #block8 { @test6@: propvalue; } | |
| 153 | |
| 154 #block9:pseudo | |
| 155 { | |
| 156 | |
| 157 @test7@: propvalue; | |
| 158 @test8@: propvalue propvalue propvalue; | |
| 159 } | |
| 160 | |
| 161 ]]></style> | |
| 162 </head> | |
| 163 <body> | |
| 164 <div id="elem1" style="@test9@: propvalue;"></div> | |
| 165 <div id="elem2" style="propname: propvalue; @test10@ : propvalue; propname:p
ropvalue;"></div> | |
| 166 <div id="elem2" style="@test11@: propvalue; @test12@ : propvalue; @test13@
:propvalue;"></div> | |
| 167 <div id="elem3" style="@test14@:propvalue"></div> | |
| 168 </body> | |
| 169 <style type="text/css"><![CDATA[ | |
| 170 | |
| 171 .block10{ @test15@: propvalue; } | |
| 172 .block11{ @test16@: propvalue; } | |
| 173 .block12{ @test17@: propvalue; } | |
| 174 #block13:pseudo | |
| 175 { | |
| 176 @test18@: propvalue; | |
| 177 @test19@: propvalue; | |
| 178 } | |
| 179 | |
| 180 #missing-semicolon-in-comments { | |
| 181 /* @test20@: propvalue */ | |
| 182 @test21@: propvalue; | |
| 183 } | |
| 184 | |
| 185 ]]></style> | |
| 186 </html> | |
| 187 """ | |
| 188 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) | |
| 189 test_content = self.generate_test_content(converter.prefixed_properties,
4, test_html) | |
| 190 | |
| 191 converter.feed(test_content[1]) | |
| 192 converter.close() | |
| 193 converted = converter.output() | |
| 194 | |
| 195 self.verify_conversion_happened(converted) | |
| 196 self.verify_prefixed_properties(converted, test_content[0]) | |
| 197 | |
| 198 def test_convert_attributes_if_needed(self): | |
| 199 """Tests convert_attributes_if_needed() using a reference file that has
some relative src paths.""" | |
| 200 | |
| 201 test_html = """<html> | |
| 202 <head> | |
| 203 <script src="../../some-script.js"></script> | |
| 204 <style src="../../../some-style.css"></style> | |
| 205 </head> | |
| 206 <body> | |
| 207 <img src="../../../../some-image.jpg"> | |
| 208 </body> | |
| 209 </html> | |
| 210 """ | |
| 211 test_reference_support_info = { | |
| 212 'reference_relpath': '../', | |
| 213 'files': ['../../some-script.js', '../../../some-style.css', '../../
../../some-image.jpg'], | |
| 214 'elements': ['script', 'style', 'img'] | |
| 215 } | |
| 216 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference
_support_info) | |
| 217 | |
| 218 converter.feed(test_html) | |
| 219 converter.close() | |
| 220 converted = converter.output() | |
| 221 | |
| 222 self.verify_conversion_happened(converted) | |
| 223 self.verify_reference_relative_paths(converted, test_reference_support_i
nfo) | |
| 224 | |
| 225 def verify_conversion_happened(self, converted): | |
| 226 self.assertTrue(converted, "conversion didn't happen") | |
| 227 | |
| 228 def verify_no_conversion_happened(self, converted, original): | |
| 229 self.assertEqual(converted[1], original, 'test should not have been conv
erted') | |
| 230 | |
| 231 def verify_prefixed_properties(self, converted, test_properties): | |
| 232 self.assertEqual(len(set(converted[0])), len(set(test_properties)), 'Inc
orrect number of properties converted') | |
| 233 for test_prop in test_properties: | |
| 234 self.assertTrue((test_prop in converted[1]), 'Property ' + test_prop
+ ' not found in converted doc') | |
| 235 | |
| 236 def verify_reference_relative_paths(self, converted, reference_support_info)
: | |
| 237 idx = 0 | |
| 238 for path in reference_support_info['files']: | |
| 239 expected_path = re.sub(reference_support_info['reference_relpath'],
'', path, 1) | |
| 240 element = reference_support_info['elements'][idx] | |
| 241 expected_tag = '<' + element + ' src=\"' + expected_path + '\">' | |
| 242 self.assertTrue(expected_tag in converted[1], 'relative path ' + pat
h + ' was not converted correctly') | |
| 243 idx += 1 | |
| 244 | |
| 245 def generate_test_content(self, full_property_list, num_test_properties, htm
l): | |
| 246 """Inserts properties requiring a -webkit- prefix into the content, repl
acing \'@testXX@\' with a property.""" | |
| 247 test_properties = [] | |
| 248 count = 0 | |
| 249 while count < num_test_properties: | |
| 250 test_properties.append(full_property_list[count]) | |
| 251 count += 1 | |
| 252 | |
| 253 # Replace the tokens in the testhtml with the test properties. Walk back
ward | |
| 254 # through the list to replace the double-digit tokens first | |
| 255 index = len(test_properties) - 1 | |
| 256 while index >= 0: | |
| 257 # Use the unprefixed version | |
| 258 test_prop = test_properties[index].replace('-webkit-', '') | |
| 259 # Replace the token | |
| 260 html = html.replace('@test' + str(index) + '@', test_prop) | |
| 261 index -= 1 | |
| 262 | |
| 263 return (test_properties, html) | |
| 264 | |
| 265 def test_convert_for_webkit_with_non_utf8(self): | |
| 266 files = {'/file': 'e\x87[P', } | |
| 267 host = MockSystemHost(filesystem=MockFileSystem(files=files)) | |
| 268 convert_for_webkit('', '/file', '', host) | |
| 269 | |
| 270 # This test passes if no Exception is raised | |
| 271 def test_convert_for_webkit_with_utf8(self): | |
| 272 files = {'/file': 'foo', } | |
| 273 host = MockSystemHost(filesystem=MockFileSystem(files=files)) | |
| 274 convert_for_webkit('', '/file', '', host) | |
| 275 | |
| 276 def test_for_capital_end_tags(self): | |
| 277 test_html = """<FONT></FONT>""" | |
| 278 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) | |
| 279 converter.feed(test_html) | |
| 280 self.assertEqual(converter.output(), ([], """<FONT></FONT>""")) | |
| 281 | |
| 282 def test_for_comments(self): | |
| 283 test_html = """<!--abc--><!-- foo -->""" | |
| 284 converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) | |
| 285 converter.feed(test_html) | |
| 286 self.assertEqual(converter.output(), ([], """<!--abc--><!-- foo -->""")) | |
| OLD | NEW |