1 # Copyright (C) 2010 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 """Unit testing base class for Port implementations."""
33 from webkitpy.tool import mocktool
34 mock_options = mocktool.MockOptions(results_directory='layout-test-results',
36 configuration='Release')
38 # FIXME: This should be used for all ports, not just WebKit Mac. See
39 # https://bugs.webkit.org/show_bug.cgi?id=50043 .
41 class PortTestCase(unittest.TestCase):
42 """Tests the WebKit port implementation."""
43 def make_port(self, options=mock_options):
44 """Override in subclass."""
45 raise NotImplementedError()
47 def test_driver_cmd_line(self):
48 port = self.make_port()
51 self.assertTrue(len(port.driver_cmd_line()))
53 def test_http_server(self):
54 port = self.make_port()
57 port.start_http_server()
58 port.stop_http_server()
60 def test_image_diff(self):
61 port = self.make_port()
65 if not port.check_image_diff():
66 # The port hasn't been built - don't run the tests.
69 dir = port.layout_tests_dir()
70 file1 = port._filesystem.join(dir, 'fast', 'css', 'button_center.png')
71 contents1 = port._filesystem.read_binary_file(file1)
72 file2 = port._filesystem.join(dir, 'fast', 'css',
73 'remove-shorthand-expected.png')
74 contents2 = port._filesystem.read_binary_file(file2)
75 tmpfd, tmpfile = port._filesystem.open_binary_tempfile('')
78 self.assertFalse(port.diff_image(contents1, contents1))
79 self.assertTrue(port.diff_image(contents1, contents2))
81 self.assertTrue(port.diff_image(contents1, contents2, tmpfile))
83 port._filesystem.remove(tmpfile)
85 def test_websocket_server(self):
86 port = self.make_port()
89 port.start_websocket_server()
90 port.stop_websocket_server()