Rename WebKitTools to Tools
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / google_chrome.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 from __future__ import with_statement
28
29 import codecs
30 import os
31
32
33 def _test_expectations_overrides(port, super):
34     # The chrome ports use the regular overrides plus anything in the
35     # official test_expectations as well. Hopefully we don't get collisions.
36     chromium_overrides = super.test_expectations_overrides(port)
37
38     # FIXME: It used to be that AssertionError would get raised by
39     # path_from_chromium_base() if we weren't in a Chromium checkout, but
40     # this changed in r60427. This should probably be changed back.
41     overrides_path = port.path_from_chromium_base('webkit', 'tools',
42             'layout_tests', 'test_expectations_chrome.txt')
43     if not os.path.exists(overrides_path):
44         return chromium_overrides
45
46     with codecs.open(overrides_path, "r", "utf-8") as file:
47         if chromium_overrides:
48             return chromium_overrides + file.read()
49         else:
50             return file.read()
51
52 def GetGoogleChromePort(**kwargs):
53     """Some tests have slightly different results when compiled as Google
54     Chrome vs Chromium.  In those cases, we prepend an additional directory to
55     to the baseline paths."""
56     port_name = kwargs['port_name']
57     del kwargs['port_name']
58     if port_name == 'google-chrome-linux32':
59         import chromium_linux
60
61         class GoogleChromeLinux32Port(chromium_linux.ChromiumLinuxPort):
62             def baseline_search_path(self):
63                 paths = chromium_linux.ChromiumLinuxPort.baseline_search_path(
64                     self)
65                 paths.insert(0, self._webkit_baseline_path(
66                     'google-chrome-linux32'))
67                 return paths
68
69             def test_expectations_overrides(self):
70                 return _test_expectations_overrides(self,
71                     chromium_linux.ChromiumLinuxPort)
72
73         return GoogleChromeLinux32Port(**kwargs)
74     elif port_name == 'google-chrome-linux64':
75         import chromium_linux
76
77         class GoogleChromeLinux64Port(chromium_linux.ChromiumLinuxPort):
78             def baseline_search_path(self):
79                 paths = chromium_linux.ChromiumLinuxPort.baseline_search_path(
80                     self)
81                 paths.insert(0, self._webkit_baseline_path(
82                     'google-chrome-linux64'))
83                 return paths
84
85             def test_expectations_overrides(self):
86                 return _test_expectations_overrides(self,
87                     chromium_linux.ChromiumLinuxPort)
88
89         return GoogleChromeLinux64Port(**kwargs)
90     elif port_name.startswith('google-chrome-mac'):
91         import chromium_mac
92
93         class GoogleChromeMacPort(chromium_mac.ChromiumMacPort):
94             def baseline_search_path(self):
95                 paths = chromium_mac.ChromiumMacPort.baseline_search_path(
96                     self)
97                 paths.insert(0, self._webkit_baseline_path(
98                     'google-chrome-mac'))
99                 return paths
100
101             def test_expectations_overrides(self):
102                 return _test_expectations_overrides(self,
103                     chromium_mac.ChromiumMacPort)
104
105         return GoogleChromeMacPort(**kwargs)
106     elif port_name.startswith('google-chrome-win'):
107         import chromium_win
108
109         class GoogleChromeWinPort(chromium_win.ChromiumWinPort):
110             def baseline_search_path(self):
111                 paths = chromium_win.ChromiumWinPort.baseline_search_path(
112                     self)
113                 paths.insert(0, self._webkit_baseline_path(
114                     'google-chrome-win'))
115                 return paths
116
117             def test_expectations_overrides(self):
118                 return _test_expectations_overrides(self,
119                     chromium_win.ChromiumWinPort)
120
121         return GoogleChromeWinPort(**kwargs)
122     raise NotImplementedError('unsupported port: %s' % port_name)