factory_unittest.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. import unittest2 as unittest
  29. from webkitpy.tool.mocktool import MockOptions
  30. from webkitpy.common.system.systemhost_mock import MockSystemHost
  31. from webkitpy.port import factory
  32. from webkitpy.port import gtk
  33. from webkitpy.port import mac
  34. from webkitpy.port import qt
  35. from webkitpy.port import test
  36. from webkitpy.port import win
  37. class FactoryTest(unittest.TestCase):
  38. """Test that the factory creates the proper port object for given combination of port_name, host.platform, and options."""
  39. # FIXME: The ports themselves should expose what options they require,
  40. # instead of passing generic "options".
  41. def setUp(self):
  42. self.webkit_options = MockOptions(pixel_tests=False)
  43. def assert_port(self, port_name=None, os_name=None, os_version=None, options=None, cls=None):
  44. host = MockSystemHost(os_name=os_name, os_version=os_version)
  45. port = factory.PortFactory(host).get(port_name, options=options)
  46. self.assertIsInstance(port, cls)
  47. def test_mac(self):
  48. self.assert_port(port_name='mac-lion', cls=mac.MacPort)
  49. self.assert_port(port_name='mac-lion-wk2', cls=mac.MacPort)
  50. self.assert_port(port_name='mac', os_name='mac', os_version='lion', cls=mac.MacPort)
  51. self.assert_port(port_name=None, os_name='mac', os_version='lion', cls=mac.MacPort)
  52. def test_win(self):
  53. self.assert_port(port_name='win-xp', cls=win.WinPort)
  54. self.assert_port(port_name='win-xp-wk2', cls=win.WinPort)
  55. self.assert_port(port_name='win', os_name='win', os_version='xp', cls=win.WinPort)
  56. self.assert_port(port_name=None, os_name='win', os_version='xp', cls=win.WinPort)
  57. self.assert_port(port_name=None, os_name='win', os_version='xp', options=self.webkit_options, cls=win.WinPort)
  58. def test_gtk(self):
  59. self.assert_port(port_name='gtk', cls=gtk.GtkPort)
  60. def test_qt(self):
  61. self.assert_port(port_name='qt', cls=qt.QtPort)
  62. def test_unknown_specified(self):
  63. self.assertRaises(NotImplementedError, factory.PortFactory(MockSystemHost()).get, port_name='unknown')
  64. def test_unknown_default(self):
  65. self.assertRaises(NotImplementedError, factory.PortFactory(MockSystemHost(os_name='vms')).get)
  66. def test_get_from_builder_name(self):
  67. self.assertEqual(factory.PortFactory(MockSystemHost()).get_from_builder_name('Apple Lion Release WK1 (Tests)').name(),
  68. 'mac-lion')