Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / Scripts / webkitpy / layout_tests / port / win_unittest.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 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 os
30 import unittest
31
32 from webkitpy.common.system import outputcapture
33 from webkitpy.common.system.executive_mock import MockExecutive
34 from webkitpy.common.system.filesystem_mock import MockFileSystem
35 from webkitpy.layout_tests.port import port_testcase
36 from webkitpy.layout_tests.port import win
37 from webkitpy.tool.mocktool import MockOptions
38
39
40 class WinPortTest(port_testcase.PortTestCase):
41     port_name = 'win'
42     full_port_name = 'win-xp'
43     port_maker = win.WinPort
44     os_name = 'win'
45     os_version = 'xp'
46
47     def test_setup_environ_for_server(self):
48         port = self.make_port()
49         port._executive = MockExecutive(should_log=True)
50         output = outputcapture.OutputCapture()
51         # FIXME: This test should not use the real os.environ
52         orig_environ = os.environ.copy()
53         env = output.assert_outputs(self, port.setup_environ_for_server)
54         self.assertEqual(orig_environ["PATH"], os.environ["PATH"])
55         self.assertNotEqual(env["PATH"], os.environ["PATH"])
56
57     def test_setup_environ_for_server_cygpath(self):
58         port = self.make_port()
59         env = port.setup_environ_for_server(port.driver_name())
60         self.assertEqual(env['CYGWIN_PATH'], '/mock-checkout/third_party/cygwin/bin')
61
62     def test_setup_environ_for_server_register_cygwin(self):
63         port = self.make_port(options=MockOptions(register_cygwin=True, results_directory='/'))
64         port._executive = MockExecutive(should_log=True)
65         expected_logs = "MOCK run_command: ['/mock-checkout/third_party/cygwin/setup_mount.bat'], cwd=None\n"
66         output = outputcapture.OutputCapture()
67         output.assert_outputs(self, port.setup_environ_for_server, expected_logs=expected_logs)
68
69     def assert_name(self, port_name, os_version_string, expected):
70         port = self.make_port(port_name=port_name, os_version=os_version_string)
71         self.assertEqual(expected, port.name())
72
73     def test_versions(self):
74         port = self.make_port()
75         self.assertIn(port.name(), ('win-xp', 'win-win7'))
76
77         self.assert_name(None, 'xp', 'win-xp')
78         self.assert_name('win', 'xp', 'win-xp')
79         self.assert_name('win-xp', 'xp', 'win-xp')
80         self.assert_name('win-xp', '7sp0', 'win-xp')
81
82         self.assert_name(None, '7sp0', 'win-win7')
83         self.assert_name(None, 'vista', 'win-win7')
84         self.assert_name('win', '7sp0', 'win-win7')
85         self.assert_name('win-win7', 'xp', 'win-win7')
86         self.assert_name('win-win7', '7sp0', 'win-win7')
87         self.assert_name('win-win7', 'vista', 'win-win7')
88
89         self.assertRaises(AssertionError, self.assert_name, None, 'w2k', 'win-xp')
90
91     def test_baseline_path(self):
92         port = self.make_port(port_name='win-xp')
93         self.assertEqual(port.baseline_path(), port._webkit_baseline_path('win-xp'))
94
95         port = self.make_port(port_name='win-win7')
96         self.assertEqual(port.baseline_path(), port._webkit_baseline_path('win'))
97
98     def test_build_path(self):
99         # Test that optional paths are used regardless of whether they exist.
100         options = MockOptions(configuration='Release', build_directory='/foo')
101         self.assert_build_path(options, ['/mock-checkout/out/Release'], '/foo/Release')
102
103         # Test that optional relative paths are returned unmodified.
104         options = MockOptions(configuration='Release', build_directory='foo')
105         self.assert_build_path(options, ['/mock-checkout/out/Release'], 'foo/Release')
106
107         # Test that we prefer the legacy dir over the new dir.
108         options = MockOptions(configuration='Release', build_directory=None)
109         self.assert_build_path(options, ['/mock-checkout/build/Release', '/mock-checkout/out'], '/mock-checkout/build/Release')
110
111     def test_build_path_timestamps(self):
112         options = MockOptions(configuration='Release', build_directory=None)
113         port = self.make_port(options=options)
114         port.host.filesystem.maybe_make_directory('/mock-checkout/out/Release')
115         port.host.filesystem.maybe_make_directory('/mock-checkout/build/Release')
116         # Check with 'out' being newer.
117         port.host.filesystem.mtime = lambda f: 5 if '/out/' in f else 4
118         self.assertEqual(port._build_path(), '/mock-checkout/out/Release')
119         # Check with 'build' being newer.
120         port.host.filesystem.mtime = lambda f: 5 if '/build/' in f else 4
121         self.assertEqual(port._build_path(), '/mock-checkout/build/Release')
122
123     def test_operating_system(self):
124         self.assertEqual('win', self.make_port().operating_system())
125
126     def test_driver_name_option(self):
127         self.assertTrue(self.make_port()._path_to_driver().endswith('content_shell.exe'))
128         self.assertTrue(self.make_port(options=MockOptions(driver_name='OtherDriver'))._path_to_driver().endswith('OtherDriver.exe'))
129
130     def test_path_to_image_diff(self):
131         self.assertEqual(self.make_port()._path_to_image_diff(), '/mock-checkout/out/Release/image_diff.exe')