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
28import unittest
29
30from webkitpy.common.system import filesystem_mock
31
32from webkitpy.layout_tests.port.webkit import WebKitPort
33from webkitpy.layout_tests.port import port_testcase
34
35
36class TestWebKitPort(WebKitPort):
37    def __init__(self, symbol_list=None, feature_list=None,
38                 expectations_file=None, skips_file=None, **kwargs):
39        self.symbol_list = symbol_list
40        self.feature_list = feature_list
41        self.expectations_file = expectations_file
42        self.skips_file = skips_file
43        WebKitPort.__init__(self, **kwargs)
44
45    def _runtime_feature_list(self):
46        return self.feature_list
47
48    def _supported_symbol_list(self):
49        return self.symbol_list
50
51    def _tests_for_other_platforms(self):
52        return ["media", ]
53
54    def _tests_for_disabled_features(self):
55        return ["accessibility", ]
56
57    def path_to_test_expectations_file(self):
58        if self.expectations_file:
59            return self.expectations_file
60        return WebKitPort.path_to_test_expectations_file(self)
61
62    def _skipped_file_paths(self):
63        if self.skips_file:
64            return [self.skips_file]
65        return []
66
67
68class WebKitPortTest(port_testcase.PortTestCase):
69    def port_maker(self, platform):
70        return WebKitPort
71
72    def test_driver_cmd_line(self):
73        # Routine is not implemented.
74        pass
75
76    def test_baseline_search_path(self):
77        # Routine is not implemented.
78        pass
79
80    def test_skipped_directories_for_symbols(self):
81        supported_symbols = ["GraphicsLayer", "WebCoreHas3DRendering", "isXHTMLMPDocument", "fooSymbol"]
82        expected_directories = set(["mathml", "fast/canvas/webgl", "compositing/webgl", "http/tests/canvas/webgl", "http/tests/wml", "fast/wml", "wml", "fast/wcss"])
83        result_directories = set(TestWebKitPort(supported_symbols, None)._skipped_tests_for_unsupported_features())
84        self.assertEqual(result_directories, expected_directories)
85
86    def test_skipped_directories_for_features(self):
87        supported_features = ["Accelerated Compositing", "Foo Feature"]
88        expected_directories = set(["animations/3d", "transforms/3d"])
89        result_directories = set(TestWebKitPort(None, supported_features)._skipped_tests_for_unsupported_features())
90        self.assertEqual(result_directories, expected_directories)
91
92    def test_skipped_layout_tests(self):
93        self.assertEqual(TestWebKitPort(None, None).skipped_layout_tests(),
94                         set(["media", "accessibility"]))
95
96    def test_test_expectations(self):
97        # Check that we read both the expectations file and anything in a
98        # Skipped file, and that we include the feature and platform checks.
99        files = {
100            '/tmp/test_expectations.txt': 'BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL\n',
101            '/tmp/Skipped': 'fast/html/keygen.html',
102        }
103        mock_fs = filesystem_mock.MockFileSystem(files)
104        port = TestWebKitPort(expectations_file='/tmp/test_expectations.txt',
105                              skips_file='/tmp/Skipped', filesystem=mock_fs)
106        self.assertEqual(port.test_expectations(),
107        """BUG_TESTEXPECTATIONS SKIP : fast/html/article-element.html = FAIL
108BUG_SKIPPED SKIP : fast/html/keygen.html = FAIL
109BUG_SKIPPED SKIP : media = FAIL
110BUG_SKIPPED SKIP : accessibility = FAIL""")
111
112
113if __name__ == '__main__':
114    unittest.main()
115