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_unknown_specified(self): 156 # Test what happens when you specify an unknown port. 157 orig_platform = sys.platform 158 self.assertRaises(NotImplementedError, factory.get, 159 port_name='unknown') 160 161 def test_unknown_default(self): 162 # Test what happens when you're running on an unknown platform. 163 orig_platform = sys.platform 164 sys.platform = 'unknown' 165 self.assertRaises(NotImplementedError, factory.get) 166 sys.platform = orig_platform 167 168 169 if __name__ == '__main__': 170 unittest.main() 171