1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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
31 from webkitpy.common.system.outputcapture import OutputCapture
32 from webkitpy.w3c.test_parser import TestParser
35 options = {'all': False, 'no_overwrite': False}
38 class TestParserTest(unittest.TestCase):
40 def test_analyze_test_reftest_one_match(self):
42 <link rel="match" href="green-box-ref.xht" />
45 test_path = '/some/madeup/path/'
46 parser = TestParser(options, test_path + 'somefile.html')
47 test_info = parser.analyze_test(test_contents=test_html)
49 self.assertNotEqual(test_info, None, 'did not find a test')
50 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
51 self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
52 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
53 self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
54 self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
56 def test_analyze_test_reftest_multiple_matches(self):
58 <link rel="match" href="green-box-ref.xht" />
59 <link rel="match" href="blue-box-ref.xht" />
60 <link rel="match" href="orange-box-ref.xht" />
66 test_path = '/some/madeup/path/'
67 parser = TestParser(options, test_path + 'somefile.html')
68 test_info = parser.analyze_test(test_contents=test_html)
70 _, _, logs = oc.restore_output()
72 self.assertNotEqual(test_info, None, 'did not find a test')
73 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
74 self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
75 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
76 self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
77 self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
79 self.assertEqual(logs, 'Multiple references are not supported. Importing the first ref defined in somefile.html\n')
81 def test_analyze_test_reftest_match_and_mismatch(self):
83 <link rel="match" href="green-box-ref.xht" />
84 <link rel="match" href="blue-box-ref.xht" />
85 <link rel="mismatch" href="orange-box-notref.xht" />
92 test_path = '/some/madeup/path/'
93 parser = TestParser(options, test_path + 'somefile.html')
94 test_info = parser.analyze_test(test_contents=test_html)
96 _, _, logs = oc.restore_output()
98 self.assertNotEqual(test_info, None, 'did not find a test')
99 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
100 self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
101 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
102 self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
103 self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
105 self.assertEqual(logs, 'Multiple references are not supported. Importing the first ref defined in somefile.html\n')
107 def test_analyze_test_reftest_with_ref_support_Files(self):
108 """ Tests analyze_test() using a reftest that has refers to a reference file outside of the tests directory and the reference file has paths to other support files """
110 test_html = """<html>
112 <link rel="match" href="../reference/green-box-ref.xht" />
116 <link href="support/css/ref-stylesheet.css" rel="stylesheet" type="text/css">
117 <style type="text/css">
118 background-image: url("../../support/some-image.png")
122 <div><img src="../support/black96x96.png" alt="Image download support must be enabled" /></div>
126 test_path = '/some/madeup/path/'
127 parser = TestParser(options, test_path + 'somefile.html')
128 test_info = parser.analyze_test(test_contents=test_html, ref_contents=ref_html)
130 self.assertNotEqual(test_info, None, 'did not find a test')
131 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
132 self.assertTrue('reference' in test_info.keys(), 'did not find a reference file')
133 self.assertTrue(test_info['reference'].startswith(test_path), 'reference path is not correct')
134 self.assertTrue('reference_support_info' in test_info.keys(), 'there should be reference_support_info for this test')
135 self.assertEquals(len(test_info['reference_support_info']['files']), 3, 'there should be 3 support files in this reference')
136 self.assertFalse('jstest' in test_info.keys(), 'test should not have been analyzed as a jstest')
138 def test_analyze_jstest(self):
139 """ Tests analyze_test() using a jstest """
141 test_html = """<head>
142 <link href="/resources/testharness.css" rel="stylesheet" type="text/css">
143 <script src="/resources/testharness.js"></script>
146 test_path = '/some/madeup/path/'
147 parser = TestParser(options, test_path + 'somefile.html')
148 test_info = parser.analyze_test(test_contents=test_html)
150 self.assertNotEqual(test_info, None, 'test_info is None')
151 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
152 self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file')
153 self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
154 self.assertTrue('jstest' in test_info.keys(), 'test should be a jstest')
156 def test_analyze_pixel_test_all_true(self):
157 """ Tests analyze_test() using a test that is neither a reftest or jstest with all=False """
159 test_html = """<html>
161 <title>CSS Test: DESCRIPTION OF TEST</title>
162 <link rel="author" title="NAME_OF_AUTHOR" />
163 <style type="text/css"><![CDATA[
172 # Set options to 'all' so this gets found
173 options['all'] = True
175 test_path = '/some/madeup/path/'
176 parser = TestParser(options, test_path + 'somefile.html')
177 test_info = parser.analyze_test(test_contents=test_html)
179 self.assertNotEqual(test_info, None, 'test_info is None')
180 self.assertTrue('test' in test_info.keys(), 'did not find a test file')
181 self.assertFalse('reference' in test_info.keys(), 'shold not have found a reference file')
182 self.assertFalse('refsupport' in test_info.keys(), 'there should be no refsupport files for this test')
183 self.assertFalse('jstest' in test_info.keys(), 'test should not be a jstest')
185 def test_analyze_pixel_test_all_false(self):
186 """ Tests analyze_test() using a test that is neither a reftest or jstest, with -all=False """
188 test_html = """<html>
190 <title>CSS Test: DESCRIPTION OF TEST</title>
191 <link rel="author" title="NAME_OF_AUTHOR" />
192 <style type="text/css"><![CDATA[
201 # Set all to false so this gets skipped
202 options['all'] = False
204 test_path = '/some/madeup/path/'
205 parser = TestParser(options, test_path + 'somefile.html')
206 test_info = parser.analyze_test(test_contents=test_html)
208 self.assertEqual(test_info, None, 'test should have been skipped')
210 def test_analyze_non_html_file(self):
211 """ Tests analyze_test() with a file that has no html"""
212 # FIXME: use a mock filesystem
213 parser = TestParser(options, os.path.join(os.path.dirname(__file__), 'test_parser.py'))
214 test_info = parser.analyze_test()
215 self.assertEqual(test_info, None, 'no tests should have been found in this file')