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.
32 from webkitpy.common.system.filesystem_mock import MockFileSystem
33 from webkitpy.tool.mocktool import MockOptions, MockUser, MockExecutive
49 class FactoryTest(unittest.TestCase):
50 """Test factory creates proper port object for the target.
52 Target is specified by port_name, sys.platform and options.
55 # FIXME: The ports themselves should expose what options they require,
56 # instead of passing generic "options".
59 self.real_sys_platform = sys.platform
60 self.webkit_options = MockOptions(pixel_tests=False)
61 self.chromium_options = MockOptions(pixel_tests=False, chromium=True)
64 sys.platform = self.real_sys_platform
66 def assert_port(self, port_name, expected_port, port_obj=None):
67 """Helper assert for port_name.
70 port_name: port name to get port object.
71 expected_port: class of expected port object.
72 port_obj: optional port object
75 port_obj = port_obj or factory.get(port_name=port_name, filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive())
76 self.assertTrue(isinstance(port_obj, expected_port))
78 def assert_platform_port(self, platform, options, expected_port):
79 """Helper assert for platform and options.
82 platform: sys.platform.
83 options: options to get port object.
84 expected_port: class of expected port object.
87 orig_platform = sys.platform
88 sys.platform = platform
89 self.assertTrue(isinstance(factory.get(options=options, filesystem=MockFileSystem(), user=MockUser(), executive=MockExecutive()), expected_port))
90 sys.platform = orig_platform
93 self.assert_port("mac", mac.MacPort)
94 self.assert_platform_port("darwin", None, mac.MacPort)
95 self.assert_platform_port("darwin", self.webkit_options, mac.MacPort)
98 self.assert_port("win", win.WinPort)
99 self.assert_platform_port("win32", None, win.WinPort)
100 self.assert_platform_port("win32", self.webkit_options, win.WinPort)
101 self.assert_platform_port("cygwin", None, win.WinPort)
102 self.assert_platform_port("cygwin", self.webkit_options, win.WinPort)
104 def test_google_chrome(self):
105 # The actual Chrome class names aren't available so we test that the
106 # objects we get are at least subclasses of the Chromium versions.
107 self.assert_port("google-chrome-linux32", chromium_linux.ChromiumLinuxPort)
108 self.assert_port("google-chrome-linux64", chromium_linux.ChromiumLinuxPort)
109 self.assert_port("google-chrome-win", chromium_win.ChromiumWinPort)
110 self.assert_port("google-chrome-mac", chromium_mac.ChromiumMacPort)
113 self.assert_port("gtk", gtk.GtkPort)
116 self.assert_port("qt", qt.QtPort)
118 def test_chromium_gpu_linux(self):
119 self.assert_port("chromium-gpu-linux", chromium_gpu.ChromiumGpuLinuxPort)
121 def test_chromium_gpu_mac(self):
122 self.assert_port("chromium-gpu-cg-mac", chromium_gpu.ChromiumGpuCgMacPort)
123 self.assert_port("chromium-gpu-mac", chromium_gpu.ChromiumGpuMacPort)
125 def test_chromium_gpu_win(self):
126 self.assert_port("chromium-gpu-win", chromium_gpu.ChromiumGpuWinPort)
128 def test_chromium_mac(self):
129 self.assert_port("chromium-mac", chromium_mac.ChromiumMacPort)
130 self.assert_port("chromium-cg-mac", chromium_mac.ChromiumMacPort)
131 self.assert_platform_port("darwin", self.chromium_options,
132 chromium_mac.ChromiumMacPort)
134 def test_chromium_linux(self):
135 self.assert_port("chromium-linux", chromium_linux.ChromiumLinuxPort)
136 self.assert_platform_port("linux2", self.chromium_options,
137 chromium_linux.ChromiumLinuxPort)
138 self.assert_platform_port("linux3", self.chromium_options,
139 chromium_linux.ChromiumLinuxPort)
141 def test_chromium_win(self):
142 self.assert_port("chromium-win", chromium_win.ChromiumWinPort)
143 self.assert_platform_port("win32", self.chromium_options,
144 chromium_win.ChromiumWinPort)
145 self.assert_platform_port("cygwin", self.chromium_options,
146 chromium_win.ChromiumWinPort)
148 def test_unknown_specified(self):
149 # Test what happens when you specify an unknown port.
150 orig_platform = sys.platform
151 self.assertRaises(NotImplementedError, factory.get, port_name='unknown')
153 def test_unknown_default(self):
154 # Test what happens when you're running on an unknown platform.
155 orig_platform = sys.platform
156 sys.platform = 'unknown'
157 self.assertRaises(NotImplementedError, factory.get)
158 sys.platform = orig_platform
161 if __name__ == '__main__':