0795982244fa1ca285d97f2e2f53624d4449f748
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / chromium_gpu_unittest.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 import sys
28 import unittest
29
30 import chromium_gpu
31
32 from webkitpy.tool.mocktool import MockOptions
33 from webkitpy.common.host_mock import MockHost
34 from webkitpy.layout_tests.port import port_testcase
35
36
37 class ChromiumGpuTest(unittest.TestCase):
38     def integration_test_chromium_gpu_linux(self):
39         self.assert_port_works('chromium-gpu-linux')
40         self.assert_port_works('chromium-gpu-linux', 'chromium-gpu', 'linux2')
41         self.assert_port_works('chromium-gpu-linux', 'chromium-gpu', 'linux3')
42
43     def integration_test_chromium_gpu_mac(self):
44         self.assert_port_works('chromium-gpu-cg-mac')
45         self.assert_port_works('chromium-gpu-mac')
46         # For now, chromium-gpu on Mac defaults to the chromium-gpu-cg-mac port.
47         self.assert_port_works('chromium-gpu-cg-mac', 'chromium-gpu', 'darwin')
48
49     def integration_test_chromium_gpu_win(self):
50         self.assert_port_works('chromium-gpu-win')
51         self.assert_port_works('chromium-gpu-win', 'chromium-gpu', 'win32')
52         self.assert_port_works('chromium-gpu-win', 'chromium-gpu', 'cygwin')
53
54     def assert_port_works(self, port_name, input_name=None, platform=None):
55         host = MockHost()
56         host.filesystem = FileSystem()  # FIXME: This test should not use a real filesystem!
57
58         # test that we got the right port
59         mock_options = MockOptions(accelerated_2d_canvas=None,
60                                    accelerated_video=None,
61                                    builder_name='foo',
62                                    child_processes=None)
63         if input_name and platform:
64             port = chromium_gpu.get(host, platform=platform, port_name=input_name, options=mock_options)
65         else:
66             port = chromium_gpu.get(host, port_name=port_name, options=mock_options)
67         self.assertTrue(port._options.accelerated_2d_canvas)
68         self.assertTrue(port._options.accelerated_video)
69         self.assertTrue(port._options.experimental_fully_parallel)
70         self.assertEqual(port._options.builder_name, 'foo - GPU')
71
72         self.assertTrue(port.name().startswith(port_name))
73
74         # test that it has the right directories in front of the search path.
75         paths = port.baseline_search_path()
76         self.assertEqual(port._webkit_baseline_path(port_name), paths[0])
77         if port_name == 'chromium-gpu-linux':
78             self.assertEqual(port._webkit_baseline_path('chromium-gpu-win'), paths[1])
79             self.assertEqual(port._webkit_baseline_path('chromium-gpu'), paths[2])
80         else:
81             self.assertEqual(port._webkit_baseline_path('chromium-gpu'), paths[1])
82
83         # Test that we're limiting to the correct directories.
84         # These two tests are picked mostly at random, but we make sure they
85         # exist separately from being filtered out by the port.
86
87         # Note that this is using a real filesystem.
88         files = port.tests(None)
89
90         path = 'fast/html/keygen.html'
91         self.assertTrue(port._filesystem.exists(port.abspath_for_test(path)))
92         self.assertFalse(path in files)
93         if port_name.startswith('chromium-gpu-cg-mac'):
94             path = 'fast/canvas/set-colors.html'
95             self.assertTrue(port._filesystem.exists(port.abspath_for_test(path)))
96             self.assertFalse(path in files)
97
98     def _assert_baseline_path(self, port_name, baseline_path):
99         host = MockHost()
100         port = host.port_factory.get(port_name)
101         self.assertEquals(port.name(), port_name)
102         self.assertEquals(port.baseline_path(), port._webkit_baseline_path(baseline_path))
103
104     def test_baseline_paths(self):
105         self._assert_baseline_path('chromium-gpu-win-vista', 'chromium-gpu-win')
106         self._assert_baseline_path('chromium-gpu-win-xp', 'chromium-gpu-win')
107         self._assert_baseline_path('chromium-gpu-win-win7', 'chromium-gpu-win')
108         self._assert_baseline_path('chromium-gpu-cg-mac-leopard', 'chromium-gpu-cg-mac')
109         self._assert_baseline_path('chromium-gpu-cg-mac-snowleopard', 'chromium-gpu-cg-mac')
110
111     def test_graphics_type(self):
112         host = MockHost()
113         port = host.port_factory.get('chromium-gpu-cg-mac')
114         self.assertEquals('gpu-cg', port.graphics_type())
115         port = host.port_factory.get('chromium-gpu-mac')
116         self.assertEquals('gpu', port.graphics_type())
117
118
119 if __name__ == '__main__':
120     port_testcase.main()