Windows test results should not fall back to mac-mountainlion after r180176
[WebKit-https.git] / Tools / Scripts / webkitpy / port / win_unittest.py
1 # Copyright (C) 2011 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 StringIO
30 import unittest
31
32 from webkitpy.common.system.executive import ScriptError
33 from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2
34 from webkitpy.common.system.filesystem_mock import MockFileSystem
35 from webkitpy.common.system.outputcapture import OutputCapture
36 from webkitpy.common.system.systemhost_mock import MockSystemHost
37 from webkitpy.port import port_testcase
38 from webkitpy.port.win import WinPort
39 from webkitpy.tool.mocktool import MockOptions
40
41
42 class WinPortTest(port_testcase.PortTestCase):
43     os_name = 'win'
44     os_version = 'xp'
45     port_name = 'win-xp'
46     port_maker = WinPort
47
48     def test_show_results_html_file(self):
49         port = self.make_port()
50         port._executive = MockExecutive(should_log=True)
51         capture = OutputCapture()
52         capture.capture_output()
53         port.show_results_html_file('test.html')
54         _, _, logs = capture.restore_output()
55         # We can't know for sure what path will be produced by cygpath, but we can assert about
56         # everything else.
57         self.assertTrue(logs.startswith("MOCK run_command: ['Tools/Scripts/run-safari', '--release', '"))
58         self.assertTrue(logs.endswith("test.html'], cwd=/mock-checkout\n"))
59
60     def _assert_search_path(self, expected_search_paths, version, use_webkit2=False):
61         port = self.make_port(port_name='win', os_version=version, options=MockOptions(webkit_test_runner=use_webkit2))
62         absolute_search_paths = map(port._webkit_baseline_path, expected_search_paths)
63         self.assertEqual(port.baseline_search_path(), absolute_search_paths)
64
65     def test_baseline_search_path(self):
66         self._assert_search_path(['win-xp', 'win-vista', 'win-7sp0', 'win', 'mac'], 'xp')
67         self._assert_search_path(['win-vista', 'win-7sp0', 'win', 'mac'], 'vista')
68         self._assert_search_path(['win-7sp0', 'win', 'mac'], '7sp0')
69
70         self._assert_search_path(['win-wk2', 'win-xp', 'win-vista', 'win-7sp0', 'win', 'mac-wk2', 'mac'], 'xp', use_webkit2=True)
71         self._assert_search_path(['win-wk2', 'win-vista', 'win-7sp0', 'win', 'mac-wk2', 'mac'], 'vista', use_webkit2=True)
72         self._assert_search_path(['win-wk2', 'win-7sp0', 'win', 'mac-wk2', 'mac'], '7sp0', use_webkit2=True)
73
74     def _assert_version(self, port_name, expected_version):
75         host = MockSystemHost(os_name='win', os_version=expected_version)
76         port = WinPort(host, port_name=port_name)
77         self.assertEqual(port.version(), expected_version)
78
79     def test_versions(self):
80         self._assert_version('win-xp', 'xp')
81         self._assert_version('win-vista', 'vista')
82         self._assert_version('win-7sp0', '7sp0')
83         self.assertRaises(AssertionError, self._assert_version, 'win-me', 'xp')
84
85     def test_compare_text(self):
86         expected = "EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\nfoo\nEDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"
87         port = self.make_port()
88         self.assertFalse(port.do_text_results_differ(expected, "foo\n"))
89         self.assertTrue(port.do_text_results_differ(expected, "foo"))
90         self.assertTrue(port.do_text_results_differ(expected, "bar"))
91
92         # This hack doesn't exist in WK2.
93         port._options = MockOptions(webkit_test_runner=True)
94         self.assertTrue(port.do_text_results_differ(expected, "foo\n"))
95
96     def test_operating_system(self):
97         self.assertEqual('win', self.make_port().operating_system())
98
99     def test_runtime_feature_list(self):
100         port = self.make_port()
101         port._executive.run_command = lambda command, cwd=None, error_handler=None: "Nonsense"
102         # runtime_features_list returns None when its results are meaningless (it couldn't run DRT or parse the output, etc.)
103         self.assertEqual(port._runtime_feature_list(), None)
104         port._executive.run_command = lambda command, cwd=None, error_handler=None: "SupportedFeatures:foo bar"
105         self.assertEqual(port._runtime_feature_list(), ['foo', 'bar'])
106
107     def test_expectations_files(self):
108         self.assertEqual(len(self.make_port().expectations_files()), 3)
109         self.assertEqual(len(self.make_port(options=MockOptions(webkit_test_runner=True, configuration='Release')).expectations_files()), 5)
110
111     def test_get_crash_log(self):
112         # Win crash logs are tested elsewhere, so here we just make sure we don't crash.
113         def fake_time_cb():
114             times = [0, 20, 40]
115             return lambda: times.pop(0)
116         port = self.make_port(port_name='win')
117         port._get_crash_log('DumpRenderTree', 1234, '', '', 0,
118             time_fn=fake_time_cb(), sleep_fn=lambda delay: None)