15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Copyright (C) 2010 Google Inc. All rights reserved.
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Redistribution and use in source and binary forms, with or without
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# modification, are permitted provided that the following conditions are
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# met:
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    * Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    * Redistributions in binary form must reproduce the above
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# copyright notice, this list of conditions and the following disclaimer
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# in the documentation and/or other materials provided with the
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# distribution.
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#    * Neither the name of Google Inc. nor the names of its
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# contributors may be used to endorse or promote products derived from
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# this software without specific prior written permission.
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
29e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)import unittest
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.tool.mocktool import MockOptions
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.systemhost_mock import MockSystemHost
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
34e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochfrom webkitpy.layout_tests.port import android
35591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochfrom webkitpy.layout_tests.port import linux
36e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochfrom webkitpy.layout_tests.port import mac
37591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochfrom webkitpy.layout_tests.port import win
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.layout_tests.port import factory
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.layout_tests.port import test
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class FactoryTest(unittest.TestCase):
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    """Test that the factory creates the proper port object for given combination of port_name, host.platform, and options."""
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    # FIXME: The ports themselves should expose what options they require,
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    # instead of passing generic "options".
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    def setUp(self):
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        self.webkit_options = MockOptions(pixel_tests=False)
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    def assert_port(self, port_name=None, os_name=None, os_version=None, options=None, cls=None):
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        host = MockSystemHost(os_name=os_name, os_version=os_version)
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        port = factory.PortFactory(host).get(port_name, options=options)
53926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        self.assertIsInstance(port, cls)
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
55e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    def test_mac(self):
56e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        self.assert_port(port_name='mac', os_name='mac', os_version='snowleopard',
57e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch                         cls=mac.MacPort)
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        self.assert_port(port_name='chromium', os_name='mac', os_version='lion',
59e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch                         cls=mac.MacPort)
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
61591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    def test_linux(self):
62591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        self.assert_port(port_name='linux', cls=linux.LinuxPort)
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        self.assert_port(port_name='chromium', os_name='linux', os_version='lucid',
64591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch                         cls=linux.LinuxPort)
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
66e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    def test_android(self):
67e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        self.assert_port(port_name='android', cls=android.AndroidPort)
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        # NOTE: We can't check for port_name=chromium here, as this will append the host's
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        # operating system, whereas host!=target for Android.
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
71591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    def test_win(self):
72591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        self.assert_port(port_name='win-xp', cls=win.WinPort)
73591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        self.assert_port(port_name='win', os_name='win', os_version='xp',
74591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch                         cls=win.WinPort)
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        self.assert_port(port_name='chromium', os_name='win', os_version='xp',
76591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch                         cls=win.WinPort)
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    def test_unknown_specified(self):
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        self.assertRaises(NotImplementedError, factory.PortFactory(MockSystemHost()).get, port_name='unknown')
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    def test_unknown_default(self):
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        self.assertRaises(NotImplementedError, factory.PortFactory(MockSystemHost(os_name='vms')).get)
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    def test_get_from_builder_name(self):
85926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        self.assertEqual(factory.PortFactory(MockSystemHost()).get_from_builder_name('WebKit Mac10.7').name(),
86e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch                          'mac-lion')
87