2011-01-21 Dirk Pranke <dpranke@chromium.org>
[WebKit.git] / Tools / Scripts / webkitpy / layout_tests / port / webkit_unittest.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 Gabor Rapcsanyi <rgabor@inf.u-szeged.hu>, University of Szeged
3 # Copyright (C) 2010 Google Inc. All rights reserved.
4 #
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 import unittest
29
30 from webkitpy.common.system import filesystem_mock
31
32 from webkitpy.layout_tests.port.webkit import WebKitPort
33
34
35 class TestWebKitPort(WebKitPort):
36     def __init__(self, symbol_list=None, feature_list=None,
37                  expectations_file=None, skips_file=None, **kwargs):
38         self.symbol_list = symbol_list
39         self.feature_list = feature_list
40         self.expectations_file = expectations_file
41         self.skips_file = skips_file
42         WebKitPort.__init__(self, **kwargs)
43
44     def _runtime_feature_list(self):
45         return self.feature_list
46
47     def _supported_symbol_list(self):
48         return self.symbol_list
49
50     def _tests_for_other_platforms(self):
51         return ["media", ]
52
53     def _tests_for_disabled_features(self):
54         return ["accessibility", ]
55
56     def path_to_test_expectations_file(self):
57         if self.expectations_file:
58             return self.expectations_file
59         return WebKitPort.path_to_test_expectations_file(self)
60
61     def _skipped_file_paths(self):
62         if self.skips_file:
63             return [self.skips_file]
64         return []
65
66 class WebKitPortTest(unittest.TestCase):
67
68     def test_skipped_directories_for_symbols(self):
69         supported_symbols = ["GraphicsLayer", "WebCoreHas3DRendering", "isXHTMLMPDocument", "fooSymbol"]
70         expected_directories = set(["mathml", "fast/canvas/webgl", "compositing/webgl", "http/tests/canvas/webgl", "http/tests/wml", "fast/wml", "wml", "fast/wcss"])
71         result_directories = set(TestWebKitPort(supported_symbols, None)._skipped_tests_for_unsupported_features())
72         self.assertEqual(result_directories, expected_directories)
73
74     def test_skipped_directories_for_features(self):
75         supported_features = ["Accelerated Compositing", "Foo Feature"]
76         expected_directories = set(["animations/3d", "transforms/3d"])
77         result_directories = set(TestWebKitPort(None, supported_features)._skipped_tests_for_unsupported_features())
78         self.assertEqual(result_directories, expected_directories)
79
80     def test_skipped_layout_tests(self):
81         self.assertEqual(TestWebKitPort(None, None).skipped_layout_tests(),
82                          set(["media", "accessibility"]))
83
84     def test_test_expectations(self):
85         # Check that we read both the expectations file and anything in a
86         # Skipped file, and that we include the feature and platform checks.
87         files = {
88             '/tmp/test_expectations.txt': 'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL\n',
89             '/tmp/Skipped': 'fast/html/keygen.html',
90         }
91         mock_fs = filesystem_mock.MockFileSystem(files)
92         port = TestWebKitPort(expectations_file='/tmp/test_expectations.txt',
93                               skips_file='/tmp/Skipped', filesystem=mock_fs)
94         self.assertEqual(port.test_expectations(),
95         """BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL
96 BUG_SKIPPED SKIP : fast/html/keygen.html = FAIL
97 BUG_SKIPPED SKIP : media = FAIL
98 BUG_SKIPPED SKIP : accessibility = FAIL""")
99
100
101 if __name__ == '__main__':
102     unittest.main()