2 # Copyright (C) 2010 Google Inc. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
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
14 # * Neither the Google name nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 """Dummy Port implementation used for testing."""
31 from __future__ import with_statement
40 class TestPort(base.Port):
41 """Test implementation of the Port interface."""
43 def __init__(self, port_name=None, options=None):
44 base.Port.__init__(self, port_name, options)
46 def base_platforms(self):
49 def baseline_path(self):
50 return os.path.join(self.layout_tests_dir(), 'platform',
53 def baseline_search_path(self):
54 return [self.baseline_path()]
56 def check_build(self, needs_http):
59 def compare_text(self, expected_text, actual_text):
62 def diff_image(self, expected_filename, actual_filename,
63 diff_filename=None, tolerance=0):
66 def diff_text(self, expected_text, actual_text,
67 expected_filename, actual_filename):
70 def layout_tests_dir(self):
71 return self.path_from_webkit_base('WebKitTools', 'Scripts',
72 'webkitpy', 'layout_tests', 'data')
80 def path_to_test_expectations_file(self):
81 return self.path_from_webkit_base('WebKitTools', 'Scripts',
82 'webkitpy', 'layout_tests', 'data', 'platform', 'test',
83 'test_expectations.txt')
85 def results_directory(self):
86 return '/tmp/' + self._options.results_directory
88 def setup_test_run(self):
91 def show_results_html_file(self, filename):
94 def create_driver(self, image_path, options):
95 return TestDriver(image_path, options, self)
97 def start_http_server(self):
100 def start_websocket_server(self):
103 def stop_http_server(self):
106 def stop_websocket_server(self):
109 def test_expectations(self):
110 """Returns the test expectations for this port.
112 Basically this string should contain the equivalent of a
113 test_expectations file. See test_expectations.py for more details."""
114 expectations_path = self.path_to_test_expectations_file()
115 with codecs.open(expectations_path, "r", "utf-8") as file:
118 def test_base_platform_names(self):
121 def test_platform_name(self):
124 def test_platform_names(self):
125 return self.test_base_platform_names()
130 def wdiff_text(self, expected_filename, actual_filename):
134 class TestDriver(base.Driver):
135 """Test/Dummy implementation of the DumpRenderTree interface."""
137 def __init__(self, image_path, test_driver_options, port):
138 self._driver_options = test_driver_options
139 self._image_path = image_path
141 self._image_written = False
146 def returncode(self):
149 def run_test(self, uri, timeoutms, image_hash):
150 if not self._image_written and self._port._options.pixel_tests:
151 with open(self._image_path, "w") as f:
152 f.write("bad png file from TestDriver")
153 self._image_written = True
155 # We special-case this because we can't fake an image hash for a
156 # missing expectation.
157 if uri.find('misc/missing-expectation') != -1:
158 return (False, False, 'deadbeefdeadbeefdeadbeefdeadbeef', '', None)
159 return (False, False, image_hash, '', None)