1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # Copyright (C) 2010 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Szeged
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 """Unit tests for manager.py."""
36 from webkitpy.common.host_mock import MockHost
37 from webkitpy.layout_tests.controllers.manager import Manager
38 from webkitpy.layout_tests.models import test_expectations
39 from webkitpy.layout_tests.models.test_run_results import TestRunResults
40 from webkitpy.thirdparty.mock import Mock
41 from webkitpy.tool.mocktool import MockOptions
44 class ManagerTest(unittest.TestCase):
45 def test_needs_servers(self):
47 port = Mock() # FIXME: Use a tighter mock.
48 port.TEST_PATH_SEPARATOR = '/'
49 manager = Manager(port, options=MockOptions(http=True, max_locked_shards=1), printer=Mock())
52 manager = get_manager()
53 self.assertFalse(manager.needs_servers(['fast/html']))
55 manager = get_manager()
56 self.assertTrue(manager.needs_servers(['http/tests/misc']))
58 def test_servers_started(self):
59 def get_manager(port):
60 manager = Manager(port, options=MockOptions(http=True, max_locked_shards=1), printer=Mock())
63 def start_http_server(additional_dirs, number_of_drivers):
64 self.http_started = True
66 def start_websocket_server():
67 self.websocket_started = True
69 def stop_http_server():
70 self.http_stopped = True
72 def stop_websocket_server():
73 self.websocket_stopped = True
76 port = host.port_factory.get('test-mac-leopard')
77 port.start_http_server = start_http_server
78 port.start_websocket_server = start_websocket_server
79 port.stop_http_server = stop_http_server
80 port.stop_websocket_server = stop_websocket_server
82 self.http_started = self.http_stopped = self.websocket_started = self.websocket_stopped = False
83 manager = get_manager(port)
84 manager._start_servers(['http/tests/foo.html'])
85 self.assertEqual(self.http_started, True)
86 self.assertEqual(self.websocket_started, False)
87 manager._stop_servers()
88 self.assertEqual(self.http_stopped, True)
89 self.assertEqual(self.websocket_stopped, False)
91 self.http_started = self.http_stopped = self.websocket_started = self.websocket_stopped = False
92 manager._start_servers(['http/tests/websocket/foo.html'])
93 self.assertEqual(self.http_started, True)
94 self.assertEqual(self.websocket_started, True)
95 manager._stop_servers()
96 self.assertEqual(self.http_stopped, True)
97 self.assertEqual(self.websocket_stopped, True)
99 self.http_started = self.http_stopped = self.websocket_started = self.websocket_stopped = False
100 manager._start_servers(['fast/html/foo.html'])
101 self.assertEqual(self.http_started, False)
102 self.assertEqual(self.websocket_started, False)
103 manager._stop_servers()
104 self.assertEqual(self.http_stopped, False)
105 self.assertEqual(self.websocket_stopped, False)
108 def test_look_for_new_crash_logs(self):
111 port = host.port_factory.get('test-mac-leopard')
112 manager = Manager(port, options=MockOptions(test_list=None, http=True, max_locked_shards=1), printer=Mock())
115 port = host.port_factory.get('test-mac-leopard')
116 tests = ['failures/expected/crash.html']
117 expectations = test_expectations.TestExpectations(port, tests)
118 run_results = TestRunResults(expectations, len(tests))
119 manager = get_manager()
120 manager._look_for_new_crash_logs(run_results, time.time())