initial import
[vuplus_webkit] / 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.common.system.filesystem_mock import MockFileSystem
33 from webkitpy.tool.mocktool import MockOptions, MockUser, MockExecutive
34
35 import chromium_gpu
36 import chromium_linux
37 import chromium_mac
38 import chromium_win
39 import dryrun
40 import factory
41 import google_chrome
42 import gtk
43 import mac
44 import qt
45 import test
46 import win
47
48
49 class FactoryTest(unittest.TestCase):
50     """Test factory creates proper port object for the target.
51
52     Target is specified by port_name, sys.platform and options.
53
54     """
55     # FIXME: The ports themselves should expose what options they require,
56     # instead of passing generic "options".
57
58     def setUp(self):
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)
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
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))
77
78     def assert_platform_port(self, platform, options, expected_port):
79         """Helper assert for platform and options.
80
81         Args:
82           platform: sys.platform.
83           options: options to get port object.
84           expected_port: class of expected port object.
85
86         """
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
91
92     def test_mac(self):
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)
96
97     def test_win(self):
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)
103
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)
111
112     def test_gtk(self):
113         self.assert_port("gtk", gtk.GtkPort)
114
115     def test_qt(self):
116         self.assert_port("qt", qt.QtPort)
117
118     def test_chromium_gpu_linux(self):
119         self.assert_port("chromium-gpu-linux", chromium_gpu.ChromiumGpuLinuxPort)
120
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)
124
125     def test_chromium_gpu_win(self):
126         self.assert_port("chromium-gpu-win", chromium_gpu.ChromiumGpuWinPort)
127
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)
133
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)
140
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)
147
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')
152
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
159
160
161 if __name__ == '__main__':
162     unittest.main()