tizen beta release
[profile/ivi/webkit-efl.git] / Tools / Scripts / webkitpy / layout_tests / port / qt.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 Google name 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 """QtWebKit implementation of the Port interface."""
30
31 import logging
32 import re
33 import sys
34
35 import webkit
36
37 from webkitpy.common.memoized import memoized
38 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
39 from webkitpy.layout_tests.port.webkit import WebKitPort
40
41
42 _log = logging.getLogger(__name__)
43
44
45 class QtPort(WebKitPort):
46     ALL_VERSIONS = ['linux', 'win', 'mac']
47     port_name = "qt"
48
49     def _port_flag_for_scripts(self):
50         return "--qt"
51
52     def _operating_system_for_platform(self, platform):
53         if platform.startswith('linux'):
54             return "linux"
55         elif platform in ('win32', 'cygwin'):
56             return "win"
57         elif platform == 'darwin':
58             return "mac"
59         return None
60
61     # sys_platform exists only for unit testing.
62     def __init__(self, host, port_name=None, sys_platform=None, **kwargs):
63         port_name = port_name or self.port_name
64         WebKitPort.__init__(self, host, port_name=None, **kwargs)
65         self._operating_system = self._operating_system_for_platform(sys_platform or sys.platform)
66         self._version = self._operating_system
67
68         # FIXME: This will allow WebKitPort.baseline_search_path and WebKitPort._skipped_file_search_paths
69         # to do the right thing, but doesn't include support for qt-4.8 or qt-arm (seen in LayoutTests/platform) yet.
70
71         if port_name != self.port_name:
72             self._name = port_name
73         else:
74             name_components = [self.port_name]
75             if self._operating_system:
76                 name_components.append(self._operating_system)
77             self._name = "-".join(name_components)
78
79     def _generate_all_test_configurations(self):
80         configurations = []
81         for version in self.ALL_VERSIONS:
82             for build_type in self.ALL_BUILD_TYPES:
83                 configurations.append(TestConfiguration(version=version, architecture='x86', build_type=build_type, graphics_type='cpu'))
84         return configurations
85
86     def _build_driver(self):
87         # The Qt port builds DRT as part of the main build step
88         return True
89
90     def _path_to_driver(self):
91         return self._build_path('bin/%s' % self.driver_name())
92
93     def _path_to_image_diff(self):
94         return self._build_path('bin/ImageDiff')
95
96     def _path_to_webcore_library(self):
97         if self._operating_system == 'mac':
98             return self._build_path('lib/QtWebKit.framework/QtWebKit')
99         else:
100             return self._build_path('lib/libQtWebKit.so')
101
102     @memoized
103     def qt_version(self):
104         version = ''
105         try:
106             for line in self._executive.run_command(['qmake', '-v']).split('\n'):
107                 match = re.search('Qt\sversion\s(?P<version>\d\.\d)', line)
108                 if match:
109                     version = match.group('version')
110                     break
111         except OSError:
112             version = '4.7'
113         return version
114
115     def baseline_search_path(self):
116         search_paths = []
117         if self.get_option('webkit_test_runner'):
118             search_paths.append(self._wk2_port_name())
119         search_paths.append(self.name())
120         version = self.qt_version()
121         if '4.7' in version:
122             search_paths.append('qt-4.7')
123         elif '4.8' in version:
124             search_paths.append('qt-4.8')
125         elif version:
126             search_paths.append('qt-5.0')
127         search_paths.append(self.port_name)
128         return map(self._webkit_baseline_path, search_paths)
129
130     def _skipped_file_search_paths(self):
131         search_paths = set([self.port_name, self.name()])
132         version = self.qt_version()
133         if '4.7' in version:
134             search_paths.add('qt-4.7')
135         elif '4.8' in version:
136             search_paths.add('qt-4.8')
137         elif version:
138             search_paths.add('qt-5.0')
139         if self.get_option('webkit_test_runner'):
140             search_paths.update(['qt-wk2', 'wk2'])
141         else:
142             search_paths.add('qt-wk1')
143         return search_paths
144
145     def _runtime_feature_list(self):
146         return None
147
148     def setup_environ_for_server(self, server_name=None):
149         clean_env = WebKitPort.setup_environ_for_server(self, server_name)
150         clean_env['QTWEBKIT_PLUGIN_PATH'] = self._build_path('lib/plugins')
151         self._copy_value_from_environ_if_set(clean_env, 'QT_DRT_WEBVIEW_MODE')
152         return clean_env
153
154     # FIXME: We should find a way to share this implmentation with Gtk,
155     # or teach run-launcher how to call run-safari and move this down to WebKitPort.
156     def show_results_html_file(self, results_filename):
157         run_launcher_args = []
158         if self.get_option('webkit_test_runner'):
159             run_launcher_args.append('-2')
160         run_launcher_args.append("file://%s" % results_filename)
161         self._run_script("run-launcher", run_launcher_args)