Rename WebKitTools to Tools
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / factory_unittest.py
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 import sys
30 import unittest
31
32 from webkitpy.tool import mocktool
33
34 import chromium_gpu
35 import chromium_linux
36 import chromium_mac
37 import chromium_win
38 import dryrun
39 import factory
40 import google_chrome
41 import gtk
42 import mac
43 import qt
44 import test
45 import win
46
47
48 class FactoryTest(unittest.TestCase):
49     """Test factory creates proper port object for the target.
50
51     Target is specified by port_name, sys.platform and options.
52
53     """
54     # FIXME: The ports themselves should expose what options they require,
55     # instead of passing generic "options".
56
57     def setUp(self):
58         self.real_sys_platform = sys.platform
59         self.webkit_options = mocktool.MockOptions(pixel_tests=False)
60         self.chromium_options = mocktool.MockOptions(pixel_tests=False,
61                                                     chromium=True)
62
63     def tearDown(self):
64         sys.platform = self.real_sys_platform
65
66     def assert_port(self, port_name, expected_port, port_obj=None):
67         """Helper assert for port_name.
68
69         Args:
70           port_name: port name to get port object.
71           expected_port: class of expected port object.
72           port_obj: optional port object
73         """
74         port_obj = port_obj or factory.get(port_name=port_name)
75         self.assertTrue(isinstance(port_obj, expected_port))
76
77     def assert_platform_port(self, platform, options, expected_port):
78         """Helper assert for platform and options.
79
80         Args:
81           platform: sys.platform.
82           options: options to get port object.
83           expected_port: class of expected port object.
84
85         """
86         orig_platform = sys.platform
87         sys.platform = platform
88         self.assertTrue(isinstance(factory.get(options=options),
89                                    expected_port))
90         sys.platform = orig_platform
91
92     def test_test(self):
93         self.assert_port("test", test.TestPort)
94
95     def test_dryrun(self):
96         self.assert_port("dryrun-test", dryrun.DryRunPort)
97         self.assert_port("dryrun-mac", dryrun.DryRunPort)
98
99     def test_mac(self):
100         self.assert_port("mac", mac.MacPort)
101         self.assert_platform_port("darwin", None, mac.MacPort)
102         self.assert_platform_port("darwin", self.webkit_options, mac.MacPort)
103
104     def test_win(self):
105         self.assert_port("win", win.WinPort)
106         self.assert_platform_port("win32", None, win.WinPort)
107         self.assert_platform_port("win32", self.webkit_options, win.WinPort)
108         self.assert_platform_port("cygwin", None, win.WinPort)
109         self.assert_platform_port("cygwin", self.webkit_options, win.WinPort)
110
111     def test_google_chrome(self):
112         # The actual Chrome class names aren't available so we test that the
113         # objects we get are at least subclasses of the Chromium versions.
114         self.assert_port("google-chrome-linux32",
115                          chromium_linux.ChromiumLinuxPort)
116         self.assert_port("google-chrome-linux64",
117                          chromium_linux.ChromiumLinuxPort)
118         self.assert_port("google-chrome-win",
119                          chromium_win.ChromiumWinPort)
120         self.assert_port("google-chrome-mac",
121                          chromium_mac.ChromiumMacPort)
122
123     def test_gtk(self):
124         self.assert_port("gtk", gtk.GtkPort)
125
126     def test_qt(self):
127         self.assert_port("qt", qt.QtPort)
128
129     def test_chromium_gpu_linux(self):
130         self.assert_port("chromium-gpu-linux", chromium_gpu.ChromiumGpuLinuxPort)
131
132     def test_chromium_gpu_mac(self):
133         self.assert_port("chromium-gpu-mac", chromium_gpu.ChromiumGpuMacPort)
134
135     def test_chromium_gpu_win(self):
136         self.assert_port("chromium-gpu-win", chromium_gpu.ChromiumGpuWinPort)
137
138     def test_chromium_mac(self):
139         self.assert_port("chromium-mac", chromium_mac.ChromiumMacPort)
140         self.assert_platform_port("darwin", self.chromium_options,
141                                   chromium_mac.ChromiumMacPort)
142
143     def test_chromium_linux(self):
144         self.assert_port("chromium-linux", chromium_linux.ChromiumLinuxPort)
145         self.assert_platform_port("linux2", self.chromium_options,
146                                   chromium_linux.ChromiumLinuxPort)
147
148     def test_chromium_win(self):
149         self.assert_port("chromium-win", chromium_win.ChromiumWinPort)
150         self.assert_platform_port("win32", self.chromium_options,
151                                   chromium_win.ChromiumWinPort)
152         self.assert_platform_port("cygwin", self.chromium_options,
153                                   chromium_win.ChromiumWinPort)
154
155     def test_get_all_ports(self):
156         ports = factory.get_all()
157         for name in factory.ALL_PORT_NAMES:
158             self.assertTrue(name in ports.keys())
159         self.assert_port("test", test.TestPort, ports["test"])
160         self.assert_port("dryrun-test", dryrun.DryRunPort, ports["dryrun"])
161         self.assert_port("dryrun-mac", dryrun.DryRunPort, ports["dryrun"])
162         self.assert_port("mac", mac.MacPort, ports["mac"])
163         self.assert_port("win", win.WinPort, ports["win"])
164         self.assert_port("gtk", gtk.GtkPort, ports["gtk"])
165         self.assert_port("qt", qt.QtPort, ports["qt"])
166         self.assert_port("chromium-mac", chromium_mac.ChromiumMacPort,
167                          ports["chromium-mac"])
168         self.assert_port("chromium-linux", chromium_linux.ChromiumLinuxPort,
169                          ports["chromium-linux"])
170         self.assert_port("chromium-win", chromium_win.ChromiumWinPort,
171                          ports["chromium-win"])
172
173     def test_unknown_specified(self):
174         # Test what happens when you specify an unknown port.
175         orig_platform = sys.platform
176         self.assertRaises(NotImplementedError, factory.get,
177                           port_name='unknown')
178
179     def test_unknown_default(self):
180         # Test what happens when you're running on an unknown platform.
181         orig_platform = sys.platform
182         sys.platform = 'unknown'
183         self.assertRaises(NotImplementedError, factory.get)
184         sys.platform = orig_platform
185
186
187 if __name__ == '__main__':
188     unittest.main()