2 # Copyright (C) 2010 Google Inc. All rights reserved.
3 # Copyright (C) 2010 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Szeged
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 """Unit tests for TestRunner()."""
35 from webkitpy.thirdparty.mock import Mock
40 class TestRunnerWrapper(test_runner.TestRunner):
41 def _get_test_input_for_file(self, test_file):
45 class TestRunnerTest(unittest.TestCase):
46 def test_results_html(self):
48 mock_port.relative_test_filename = lambda name: name
49 mock_port.filename_to_uri = lambda name: name
51 runner = test_runner.TestRunner(port=mock_port, options=Mock(),
53 expected_html = u"""<html>
55 <title>Layout Test Results (time)</title>
59 <p><a href='test_path'>test_path</a><br />
63 html = runner._results_html(["test_path"], {}, "Title", override_time="time")
64 self.assertEqual(html, expected_html)
66 def test_shard_tests(self):
67 # Test that _shard_tests in test_runner.TestRunner really
68 # put the http tests first in the queue.
69 runner = TestRunnerWrapper(port=Mock(), options=Mock(),
73 "LayoutTests/websocket/tests/unicode.htm",
74 "LayoutTests/animations/keyframes.html",
75 "LayoutTests/http/tests/security/view-source-no-refresh.html",
76 "LayoutTests/websocket/tests/websocket-protocol-ignored.html",
77 "LayoutTests/fast/css/display-none-inline-style-change-crash.html",
78 "LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types.html",
79 "LayoutTests/dom/html/level2/html/HTMLAnchorElement03.html",
80 "LayoutTests/ietestcenter/Javascript/11.1.5_4-4-c-1.html",
81 "LayoutTests/dom/html/level2/html/HTMLAnchorElement06.html",
84 expected_tests_to_http_lock = set([
85 'LayoutTests/websocket/tests/unicode.htm',
86 'LayoutTests/http/tests/security/view-source-no-refresh.html',
87 'LayoutTests/websocket/tests/websocket-protocol-ignored.html',
88 'LayoutTests/http/tests/xmlhttprequest/supported-xml-content-types.html',
91 # FIXME: Ideally the HTTP tests don't have to all be in one shard.
92 single_thread_results = runner._shard_tests(test_list, False)
93 multi_thread_results = runner._shard_tests(test_list, True)
95 self.assertEqual("tests_to_http_lock", single_thread_results[0][0])
96 self.assertEqual(expected_tests_to_http_lock, set(single_thread_results[0][1]))
97 self.assertEqual("tests_to_http_lock", multi_thread_results[0][0])
98 self.assertEqual(expected_tests_to_http_lock, set(multi_thread_results[0][1]))
101 if __name__ == '__main__':