Home | History | Annotate | Download | only in port
      1 # Copyright (C) 2010 Google Inc. All rights reserved.
      2 #
      3 # Redistribution and use in source and binary forms, with or without
      4 # modification, are permitted provided that the following conditions are
      5 # met:
      6 #
      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
     12 # distribution.
     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.
     16 #
     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.
     28 
     29 """Unit testing base class for Port implementations."""
     30 
     31 import sys
     32 import unittest
     33 
     34 # Handle Python < 2.6 where multiprocessing isn't available.
     35 try:
     36     import multiprocessing
     37 except ImportError:
     38     multiprocessing = None
     39 
     40 from webkitpy.tool import mocktool
     41 mock_options = mocktool.MockOptions(use_apache=True,
     42                                     configuration='Release')
     43 
     44 # FIXME: This should be used for all ports, not just WebKit Mac. See
     45 # https://bugs.webkit.org/show_bug.cgi?id=50043 .
     46 
     47 class PortTestCase(unittest.TestCase):
     48     """Tests the WebKit port implementation."""
     49     def port_maker(self, platform):
     50         """Override to return the class object of the port to be tested,
     51         or None if a valid port object cannot be constructed on the specified
     52         platform."""
     53         raise NotImplementedError()
     54 
     55     def make_port(self, options=mock_options):
     56         """This routine should be used for tests that should only be run
     57         when we can create a full, valid port object."""
     58         maker = self.port_maker(sys.platform)
     59         if not maker:
     60             return None
     61 
     62         return maker(options=options)
     63 
     64     def test_default_worker_model(self):
     65         port = self.make_port()
     66         if not port:
     67             return
     68 
     69         if multiprocessing:
     70             self.assertEqual(port.default_worker_model(), 'processes')
     71         else:
     72             self.assertEqual(port.default_worker_model(), 'threads')
     73 
     74     def test_driver_cmd_line(self):
     75         port = self.make_port()
     76         if not port:
     77             return
     78         self.assertTrue(len(port.driver_cmd_line()))
     79 
     80         options = mocktool.MockOptions(additional_drt_flag=['--foo=bar', '--foo=baz'])
     81         port = self.make_port(options=options)
     82         cmd_line = port.driver_cmd_line()
     83         self.assertTrue('--foo=bar' in cmd_line)
     84         self.assertTrue('--foo=baz' in cmd_line)
     85 
     86     def disabled_test_http_server(self):
     87         port = self.make_port()
     88         if not port:
     89             return
     90         port.start_http_server()
     91         port.stop_http_server()
     92 
     93     def disabled_test_image_diff(self):
     94         port = self.make_port()
     95         if not port:
     96             return
     97 
     98         if not port.check_image_diff():
     99             # The port hasn't been built - don't run the tests.
    100             return
    101 
    102         dir = port.layout_tests_dir()
    103         file1 = port._filesystem.join(dir, 'fast', 'css', 'button_center.png')
    104         contents1 = port._filesystem.read_binary_file(file1)
    105         file2 = port._filesystem.join(dir, 'fast', 'css',
    106                                       'remove-shorthand-expected.png')
    107         contents2 = port._filesystem.read_binary_file(file2)
    108         tmpfd, tmpfile = port._filesystem.open_binary_tempfile('')
    109         tmpfd.close()
    110 
    111         self.assertFalse(port.diff_image(contents1, contents1))
    112         self.assertTrue(port.diff_image(contents1, contents2))
    113 
    114         self.assertTrue(port.diff_image(contents1, contents2, tmpfile))
    115 
    116         port._filesystem.remove(tmpfile)
    117 
    118     def test_diff_image__missing_both(self):
    119         port = self.make_port()
    120         if not port:
    121             return
    122         self.assertFalse(port.diff_image(None, None, None))
    123         self.assertFalse(port.diff_image(None, '', None))
    124         self.assertFalse(port.diff_image('', None, None))
    125         self.assertFalse(port.diff_image('', '', None))
    126 
    127     def test_diff_image__missing_actual(self):
    128         port = self.make_port()
    129         if not port:
    130             return
    131         self.assertTrue(port.diff_image(None, 'foo', None))
    132         self.assertTrue(port.diff_image('', 'foo', None))
    133 
    134     def test_diff_image__missing_expected(self):
    135         port = self.make_port()
    136         if not port:
    137             return
    138         self.assertTrue(port.diff_image('foo', None, None))
    139         self.assertTrue(port.diff_image('foo', '', None))
    140 
    141 
    142     def disabled_test_websocket_server(self):
    143         port = self.make_port()
    144         if not port:
    145             return
    146         port.start_websocket_server()
    147         port.stop_websocket_server()
    148 
    149     def test_test_configuration(self):
    150         port = self.make_port()
    151         if not port:
    152             return
    153         self.assertTrue(port.test_configuration())
    154 
    155     def test_all_test_configurations(self):
    156         port = self.make_port()
    157         if not port:
    158             return
    159         self.assertTrue(len(port.all_test_configurations()) > 0)
    160 
    161     def test_baseline_search_path(self):
    162         port = self.make_port()
    163         if not port:
    164             return
    165         self.assertTrue(port.baseline_path() in port.baseline_search_path())
    166