tizen beta release
[framework/web/webkit-efl.git] / Tools / Scripts / webkitpy / layout_tests / port / win.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 import logging
30 import re
31 import sys
32
33 from webkitpy.common.system.executive import ScriptError
34 from webkitpy.layout_tests.port.apple import ApplePort
35
36
37 _log = logging.getLogger(__name__)
38
39
40 class WinPort(ApplePort):
41     port_name = "win"
42
43     # This is a list of all supported OS-VERSION pairs for the AppleWin port
44     # and the order of fallback between them.  Matches ORWT.
45     VERSION_FALLBACK_ORDER = ["win-xp", "win-vista", "win-7sp0", "win"]
46
47     def _version_string_from_windows_version_tuple(self, windows_version_tuple):
48         if windows_version_tuple[:3] == (6, 1, 7600):
49             return '7sp0'
50         if windows_version_tuple[:2] == (6, 0):
51             return 'vista'
52         if windows_version_tuple[:2] == (5, 1):
53             return 'xp'
54         return None
55
56     def _detect_version(self, os_version_string=None, run_on_non_windows_platforms=None):
57         # FIXME: os_version_string is for unit testing, but may eventually be provided by factory.py instead.
58         if os_version_string is not None:
59             return os_version_string
60
61         # No sense in trying to detect our windows version on non-windows platforms, unless we're unittesting.
62         if sys.platform != 'cygwin' and not run_on_non_windows_platforms:
63             return None
64
65         # Note, this intentionally returns None to mean that it can't detect what the current version is.
66         # Callers can then decide what version they want to pretend to be.
67         try:
68             ver_output = self._executive.run_command(['cmd', '/c', 'ver'])
69         except (ScriptError, OSError), e:
70             ver_output = ""
71             _log.error("Failed to detect Windows version, assuming latest.\n%s" % e)
72         match_object = re.search(r'(?P<major>\d)\.(?P<minor>\d)\.(?P<build>\d+)', ver_output)
73         if match_object:
74             version_tuple = tuple(map(int, match_object.groups()))
75             return self._version_string_from_windows_version_tuple(version_tuple)
76
77     def __init__(self, host, **kwargs):
78         ApplePort.__init__(self, host, **kwargs)
79         self._operating_system = 'win'
80
81     def compare_text(self, expected_text, actual_text):
82         # Sanity was restored in WK2, so we don't need this hack there.
83         if self.get_option('webkit_test_runner'):
84             return ApplePort.compare_text(self, expected_text, actual_text)
85
86         # This is a hack (which dates back to ORWT).
87         # Windows does not have an EDITING DELEGATE, so we strip any EDITING DELEGATE
88         # messages to make more of the tests pass.
89         # It's possible more of the ports might want this and this could move down into WebKitPort.
90         delegate_regexp = re.compile("^EDITING DELEGATE: .*?\n", re.MULTILINE)
91         expected_text = delegate_regexp.sub("", expected_text)
92         actual_text = delegate_regexp.sub("", actual_text)
93         return expected_text != actual_text
94
95     def baseline_search_path(self):
96         try:
97             fallback_index = self.VERSION_FALLBACK_ORDER.index(self._port_name_with_version())
98             fallback_names = list(self.VERSION_FALLBACK_ORDER[fallback_index:])
99         except ValueError:
100             # Unknown versions just fall back to the base port results.
101             fallback_names = [self.port_name]
102         # FIXME: The AppleWin port falls back to AppleMac for some results.  Eventually we'll have a shared 'apple' port.
103         if self.get_option('webkit_test_runner'):
104             fallback_names.insert(0, 'win-wk2')
105             fallback_names.append('mac-wk2')
106             # Note we do not add 'wk2' here, even though it's included in _skipped_search_paths().
107         # FIXME: Perhaps we should get this list from MacPort?
108         fallback_names.extend(['mac-lion', 'mac'])
109         return map(self._webkit_baseline_path, fallback_names)
110
111     # This port may need to override setup_environ_for_server
112     # to match behavior of setPathForRunningWebKitApp from ORWT.
113     # $env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), appleApplicationSupportPath(), $env->{PATH} || "");
114
115     # FIXME: webkitperl/httpd.pm installs /usr/lib/apache/libphp4.dll on cycwin automatically
116     # as part of running old-run-webkit-tests.  That's bad design, but we may need some similar hack.
117     # We might use setup_environ_for_server for such a hack (or modify apache_http_server.py).