def test_read_prefixed_property_list(self): """ Tests that the current list of properties requiring the -webkit- prefix load correctly """ # FIXME: We should be passing in a MockHost here ... converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME) prop_list = converter.prefixed_properties self.assertTrue(prop_list, 'No prefixed properties found')
def test_convert_test_harness_paths(self): """ Tests convert_testharness_paths() with a test that uses multiple testharness files """ test_html = """<head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> <script src="/resources/WebIDLParser.js"></script> <script src="/resources/idlharness.js"></script> </head> """ fake_dir_path = self.fake_dir_path('testharnesspaths') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 4, 1)
def test_convert_attributes_if_needed(self): """Tests convert_attributes_if_needed() using a reference file that has some relative src paths.""" test_html = """<html> <head> <script src="../../some-script.js"></script> <style src="../../../some-style.css"></style> </head> <body> <img src="../../../../some-image.jpg"> </body> </html> """ test_reference_support_info = { 'reference_relpath': '../', 'files': ['../../some-script.js', '../../../some-style.css', '../../../../some-image.jpg'], 'elements': ['script', 'style', 'img'] } converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference_support_info) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_reference_relative_paths(converted, test_reference_support_info)
def test_convert_for_webkit_properties_only(self): """ Tests convert_for_webkit() using a test that has 2 prefixed properties: 1 in a style block + 1 inline style """ test_html = """<html> <head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> <style type="text/css"> #block1 { @test0@: @propvalue0@; } </style> </head> <body> <div id="elem1" style="@test1@: @propvalue1@;"></div> </body> </html> """ fake_dir_path = self.fake_dir_path('harnessandprops') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) test_content = self.generate_test_content_properties_and_values(converter.prefixed_properties, converter.prefixed_property_values, 1, test_html) oc = OutputCapture() oc.capture_output() try: converter.feed(test_content[2]) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 1, 1) self.verify_prefixed_properties(converted, test_content[0]) self.verify_prefixed_property_values(converted, test_content[1])
def test_convert_for_webkit_harness_and_properties(self): """ Tests convert_for_webkit() using a basic JS test that uses testharness.js and testharness.css and has 4 prefixed properties: 3 in a style block + 1 inline style """ test_html = """<html> <head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> <style type="text/css"> #block1 { @test0@: @propvalue0@; } #block2 { @test1@: @propvalue1@; } #block3 { @test2@: @propvalue2@; } </style> </head> <body> <div id="elem1" style="@test3@: @propvalue3@;"></div> </body> </html> """ fake_dir_path = self.fake_dir_path('harnessandprops') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) with OutputCapture(): test_content = self.generate_test_content_properties_and_values(converter.prefixed_properties, converter.prefixed_property_values, 2, test_html) converter.feed(test_content[2]) converter.close() converted = converter.output() self.verify_conversion_happened(converted) self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 1, 1) self.verify_prefixed_properties(converted, test_content[0]) self.verify_prefixed_property_values(converted, test_content[1])
def test_convert_for_webkit_properties_only(self): """Tests convert_for_webkit() using a test that has 2 prefixed properties: 1 in a style block + 1 inline style.""" test_html = """<html> <head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> <style type="text/css"> #block1 { @test0@: propvalue; } </style> </head> <body> <div id="elem1" style="@test1@: propvalue;"></div> </body> </html> """ fake_dir_path = self.fake_dir_path('harnessandprops') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) test_content = self.generate_test_content( converter.prefixed_properties, 1, test_html) oc = OutputCapture() oc.capture_output() try: converter.feed(test_content[1]) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_prefixed_properties(converted, test_content[0])
def test_convert_for_webkit_nothing_to_convert(self): """ Tests convert_for_webkit() using a basic test that has nothing to convert """ test_html = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CSS Test: DESCRIPTION OF TEST</title> <link rel="author" title="NAME_OF_AUTHOR" href="mailto:EMAIL OR http://CONTACT_PAGE"/> <link rel="help" href="RELEVANT_SPEC_SECTION"/> <meta name="assert" content="TEST ASSERTION"/> <style type="text/css"><![CDATA[ CSS FOR TEST ]]></style> </head> <body> CONTENT OF TEST </body> </html> """ converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_no_conversion_happened(converted, test_html)
def test_hides_all_instructions_for_manual_testers(self): test_html = """<body> <h1 class="instructions">Hello manual tester!</h1> <p class="instructions some_other_class">This is how you run this test.</p> <p style="willbeoverwritten" class="instructions">...</p> <doesntmatterwhichtagitis class="some_other_class instructions">...</p> <p>Legit content may contain the instructions string</p> </body> """ expected_test_html = """<body> <h1 class="instructions" style="display:none">Hello manual tester!</h1> <p class="instructions some_other_class" style="display:none">This is how you run this test.</p> <p class="instructions" style="display:none">...</p> <doesntmatterwhichtagitis class="some_other_class instructions" style="display:none">...</p> <p>Legit content may contain the instructions string</p> </body> """ converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() self.assertEqual(converted[1], expected_test_html)
def test_read_prefixed_property_list(self): """ Tests that the current list of properties requiring the -webkit- prefix load correctly """ # FIXME: We should be passing in a MockHost here ... converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) prop_list = converter.prefixed_properties self.assertTrue(prop_list, 'No prefixed properties found')
def test_convert_vendor_prefix_js_paths(self): test_html = """<head> <script src="/common/vendor-prefix.js"> </head> """ fake_dir_path = self.fake_dir_path('adapterjspaths') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() new_html = BeautifulSoup(converted[1]) # Verify the original paths are gone, and the new paths are present. orig_path_pattern = re.compile('\"/common/vendor-prefix.js') self.assertEquals(len(new_html.findAll(src=orig_path_pattern)), 0, 'vendor-prefix.js path was not converted') resources_dir = converter.path_from_webkit_root("tests", "resources") new_relpath = os.path.relpath(resources_dir, fake_dir_path) relpath_pattern = re.compile(new_relpath) self.assertEquals(len(new_html.findAll(src=relpath_pattern)), 1, 'vendor-prefix.js relative path not correct')
def test_convert_vendor_prefix_js_paths(self): test_html = """<head> <script src="/common/vendor-prefix.js"> </head> """ fake_dir_path = self.fake_dir_path('adapterjspaths') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() new_html = BeautifulSoup(converted[1]) # Verify the original paths are gone, and the new paths are present. orig_path_pattern = re.compile('\"/common/vendor-prefix.js') self.assertEquals(len(new_html.findAll(src=orig_path_pattern)), 0, 'vendor-prefix.js path was not converted') resources_dir = converter.path_from_webkit_root("LayoutTests", "resources") new_relpath = os.path.relpath(resources_dir, fake_dir_path) relpath_pattern = re.compile(new_relpath) self.assertEquals(len(new_html.findAll(src=relpath_pattern)), 1, 'vendor-prefix.js relative path not correct')
def test_convert_attributes_if_needed(self): """ Tests convert_attributes_if_needed() using a reference file that has some relative src paths """ test_html = """<html> <head> <link href="../support/base-style.css"> <video src="resources/video.mkv"></video> <script src="../../some-script.js"></script> <style src="../../../some-style.css"></style> </head> <body> <img src="../../../../some-image.jpg"> </body> </html> """ test_reference_support_info = {'reference_relpath': '../', 'files': ['../../some-script.js', '../../../some-style.css', '../../../../some-image.jpg', '../support/base-style.css', 'resources/video.mkv'], 'elements': ['script', 'style', 'img', 'link', 'video']} converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference_support_info) with OutputCapture(): converter.feed(test_html) converter.close() converted = converter.output() self.verify_conversion_happened(converted) self.verify_reference_relative_paths(converted, test_reference_support_info)
def test_convert_attributes_if_needed(self): """ Tests convert_attributes_if_needed() using a reference file that has some relative src paths """ test_html = """<html> <head> <script src="../../some-script.js"></script> <style src="../../../some-style.css"></style> </head> <body> <img src="../../../../some-image.jpg"> </body> </html> """ test_reference_support_info = {'reference_relpath': '../', 'files': ['../../some-script.js', '../../../some-style.css', '../../../../some-image.jpg'], 'elements': ['script', 'style', 'img']} converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference_support_info) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_reference_relative_paths(converted, test_reference_support_info)
def test_convert_style_multiple_url(self): """ Tests convert_attributes_if_needed() using a reference file that has several relative URL paths in the style """ test_html = """<html> <head> <style type="text/css"> .redSquare { position: absolute; left:50px; width: 100px; height: 100px; background-image:url(../support/yyy.png); } .greenSquare { position: absolute; left:50px; width: 100px; height: 100px; background-image:url(../support/yy.png); } .yellowSquare { position: absolute; left:50px; width: 100px; height: 100px; background-image:url(../../another/directory/x.png); } .container { position: absolute; } </style> </head> <body> </body> </html> """ test_reference_support_info = {'reference_relpath': '../', 'files': ['../support/yyy.png', '../support/yy.png', '../../another/directory/x.png']} converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, test_reference_support_info) oc = OutputCapture() oc.capture_output() try: converter.feed(test_html) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) for path in test_reference_support_info['files']: expected_path = re.sub(test_reference_support_info['reference_relpath'], '', path, 1) expected_url = 'background-image:url(' + expected_path + ');' self.assertTrue(expected_url in converted[2], 'relative path ' + path + ' was not converted correcty')
def test_convert_for_webkit_harness_only(self): """ Tests convert_for_webkit() using a basic JS test that uses testharness.js only and has no prefixed properties """ test_html = """<head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> </head> """ fake_dir_path = self.fake_dir_path("harnessonly") converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME) converter.feed(test_html) converter.close() converted = converter.output() self.verify_conversion_happened(converted) self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1, 1) self.verify_prefixed_properties(converted, [])
def test_convert_for_webkit_harness_only(self): """ Tests convert_for_webkit() using a basic JS test that uses testharness.js only and has no prefixed properties """ test_html = """<head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> </head> """ fake_dir_path = self.fake_dir_path("harnessonly") converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) converter.feed(test_html) converter.close() converted = converter.output() self.verify_conversion_happened(converted) self.verify_test_harness_paths(converter, converted[1], fake_dir_path, 1, 1) self.verify_prefixed_properties(converted, [])
def test_convert_test_harness_paths(self): """ Tests convert_testharness_paths() with a test that uses all three testharness files """ test_html = """<head> <link href="/resources/testharness.css" rel="stylesheet" type="text/css"> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> </head> """ fake_dir_path = self.fake_dir_path('testharnesspaths') converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME, None) with OutputCapture(): converter.feed(test_html) converter.close() converted = converter.output() self.verify_conversion_happened(converted) self.verify_test_harness_paths(converter, converted[2], fake_dir_path, 2, 1)
def test_convert_prefixed_properties(self): """ Tests convert_prefixed_properties() file that has 20 properties requiring the -webkit- prefix: 10 in one style block + 5 in another style block + 5 inline styles, including one with multiple prefixed properties. The properties in the test content are in all sorts of wack formatting. """ test_html = """<html> <style type="text/css"><![CDATA[ .block1 { width: 300px; height: 300px } .block2 { @test0@: propvalue; } .block3{@test1@: propvalue;} .block4 { @test2@:propvalue; } .block5{ @test3@ :propvalue; } #block6 { @test4@ : propvalue; } #block7 { @test5@: propvalue; } #block8 { @test6@: propvalue; } #block9:pseudo { @test7@: propvalue; @test8@: propvalue propvalue propvalue;; } ]]></style> </head> <body> <div id="elem1" style="@test9@: propvalue;"></div> <div id="elem2" style="propname: propvalue; @test10@ : propvalue; propname:propvalue;"></div> <div id="elem2" style="@test11@: propvalue; @test12@ : propvalue; @test13@ :propvalue;"></div> <div id="elem3" style="@test14@:propvalue"></div> </body> <style type="text/css"><![CDATA[ .block10{ @test15@: propvalue; } .block11{ @test16@: propvalue; } .block12{ @test17@: propvalue; } #block13:pseudo { @test18@: propvalue; @test19@: propvalue; } ]]></style> </html> """ converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) test_content = self.generate_test_content( converter.prefixed_properties, 20, test_html) oc = OutputCapture() oc.capture_output() try: converter.feed(test_content[1]) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_prefixed_properties(converted, test_content[0])
def test_convert_prefixed_properties(self): """Tests convert_prefixed_properties() file that has 20 properties requiring the -webkit- prefix. The properties are: 10 in one style block + 5 in another style block + 5 inline styles, including one with multiple prefixed properties. 2 when prefixed properties appear in comments without ending ';'. The properties in the test content are in all sorts of wack formatting. """ test_html = """<html> <style type="text/css"><![CDATA[ .block1 { width: 300px; height: 300px } .block2 { @test0@: propvalue; } .block3{@test1@: propvalue;} .block4 { @test2@:propvalue; } .block5{ @test3@ :propvalue; } #block6 { @test4@ : propvalue; } #block7 { @test5@: propvalue; } #block8 { @test6@: propvalue; } #block9:pseudo { @test7@: propvalue; @test8@: propvalue propvalue propvalue; } ]]></style> </head> <body> <div id="elem1" style="@test9@: propvalue;"></div> <div id="elem2" style="propname: propvalue; @test10@ : propvalue; propname:propvalue;"></div> <div id="elem2" style="@test11@: propvalue; @test12@ : propvalue; @test13@ :propvalue;"></div> <div id="elem3" style="@test14@:propvalue"></div> </body> <style type="text/css"><![CDATA[ .block10{ @test15@: propvalue; } .block11{ @test16@: propvalue; } .block12{ @test17@: propvalue; } #block13:pseudo { @test18@: propvalue; @test19@: propvalue; } #missing-semicolon-in-comments { /* @test20@: propvalue */ @test21@: propvalue; } ]]></style> </html> """ converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) test_content = self.generate_test_content(converter.prefixed_properties, 22, test_html) oc = OutputCapture() oc.capture_output() try: converter.feed(test_content[1]) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_prefixed_properties(converted, test_content[0])
def test_for_capital_end_tags(self): test_html = """<FONT></FONT>""" converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) converter.feed(test_html) self.assertEqual(converter.output(), ([], """<FONT></FONT>"""))
def test_for_comments(self): test_html = """<!--abc--><!-- foo -->""" converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) converter.feed(test_html) self.assertEqual(converter.output(), ([], """<!--abc--><!-- foo -->"""))
def test_convert_prefixed_properties(self): """ Tests convert_prefixed_properties() file that has 20 properties requiring the -webkit- prefix: 10 in one style block + 5 in another style block + 5 inline styles, including one with multiple prefixed properties. The properties in the test content are in all sorts of wack formatting. """ test_html = """<html> <style type="text/css"><![CDATA[ .block1 { width: 300px; height: 300px } .block2 { @test0@: @propvalue0@; } .block3{@test1@: @propvalue1@;} .block4 { @test2@:@propvalue2@; } .block5{ @test3@ :@propvalue3@; } #block6 { @test4@ : @propvalue4@ ; } #block7 { @test5@: @propvalue5@; } #block8 { @test6@: @propvalue6@ } #block9:pseudo { @test7@: @propvalue7@; @test8@: propvalue propvalue propvalue;; propname: @propvalue8@; } ]]></style> </head> <body> <div id="elem1" style="@test9@: @propvalue9@;"></div> <div id="elem2" style="propname: propvalue; @test10@ : @propvalue10@; propname:propvalue;"></div> <div id="elem2" style="@test11@: @propvalue11@; @test12@ : @propvalue12@; @test13@ : @propvalue13@ ;"></div> <div id="elem3" style="@test14@:@propvalue14@"></div> </body> <style type="text/css"><![CDATA[ .block10{ @test15@: @propvalue15@; } .block11{ @test16@: @propvalue16@; } .block12{ @test17@: @propvalue17@; } #block13:pseudo { @test18@: @propvalue18@; @test19@: @propvalue19@; } ]]></style> </html> """ converter = _W3CTestConverter(DUMMY_PATH, DUMMY_FILENAME, None) test_content = self.generate_test_content_properties_and_values(converter.prefixed_properties, converter.prefixed_property_values, 20, test_html) oc = OutputCapture() oc.capture_output() try: converter.feed(test_content[2]) converter.close() converted = converter.output() finally: oc.restore_output() self.verify_conversion_happened(converted) self.verify_prefixed_properties(converted, test_content[0]) self.verify_prefixed_property_values(converted, test_content[1])