Clean up ChunkedUpdateDrawingAreaProxy
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / google_chrome_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 codecs
28 import os
29 import unittest
30
31 from webkitpy.common import newstringio
32
33 import factory
34 import google_chrome
35
36
37 class GetGoogleChromePortTest(unittest.TestCase):
38     def test_get_google_chrome_port(self):
39         test_ports = ('google-chrome-linux32', 'google-chrome-linux64',
40             'google-chrome-mac', 'google-chrome-win')
41         for port in test_ports:
42             self._verify_baseline_path(port, port)
43             self._verify_expectations_overrides(port)
44
45         self._verify_baseline_path('google-chrome-mac', 'google-chrome-mac-leopard')
46         self._verify_baseline_path('google-chrome-win', 'google-chrome-win-xp')
47         self._verify_baseline_path('google-chrome-win', 'google-chrome-win-vista')
48
49     def _verify_baseline_path(self, expected_path, port_name):
50         port = google_chrome.GetGoogleChromePort(port_name=port_name,
51                                                  options=None)
52         path = port.baseline_search_path()[0]
53         self.assertEqual(expected_path, os.path.split(path)[1])
54
55     def _verify_expectations_overrides(self, port_name):
56         # FIXME: make this more robust when we have the Tree() abstraction.
57         # we should be able to test for the files existing or not, and
58         # be able to control the contents better.
59
60         chromium_port = factory.get("chromium-mac")
61         chromium_overrides = chromium_port.test_expectations_overrides()
62         port = google_chrome.GetGoogleChromePort(port_name=port_name,
63                                                  options=None)
64
65         orig_exists = os.path.exists
66         orig_open = codecs.open
67         expected_string = "// hello, world\n"
68
69         def mock_exists_chrome_not_found(path):
70             if 'test_expectations_chrome.txt' in path:
71                 return False
72             return orig_exists(path)
73
74         def mock_exists_chrome_found(path):
75             if 'test_expectations_chrome.txt' in path:
76                 return True
77             return orig_exists(path)
78
79         def mock_open(path, mode, encoding):
80             if 'test_expectations_chrome.txt' in path:
81                 return newstringio.StringIO(expected_string)
82             return orig_open(path, mode, encoding)
83
84         try:
85             os.path.exists = mock_exists_chrome_not_found
86             chrome_overrides = port.test_expectations_overrides()
87             self.assertEqual(chromium_overrides, chrome_overrides)
88
89             os.path.exists = mock_exists_chrome_found
90             codecs.open = mock_open
91             chrome_overrides = port.test_expectations_overrides()
92             if chromium_overrides:
93                 self.assertEqual(chrome_overrides,
94                                  chromium_overrides + expected_string)
95             else:
96                 self.assertEqual(chrome_overrides, expected_string)
97         finally:
98             os.path.exists = orig_exists
99             codecs.open = orig_open
100
101
102 if __name__ == '__main__':
103     unittest.main()