OSDN Git Service

am 0ee15178: (-s ours) am e4be1fd5: DO NOT MERGE Refactor find and select dialogs
[android-x86/external-webkit.git] / WebKitTools / Scripts / webkitpy / layout_tests / port / test.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 #     * 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.
17 #
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.
29
30 """Dummy Port implementation used for testing."""
31 from __future__ import with_statement
32
33 import codecs
34 import os
35 import time
36
37 import base
38
39
40 class TestPort(base.Port):
41     """Test implementation of the Port interface."""
42
43     def __init__(self, port_name=None, options=None):
44         base.Port.__init__(self, port_name, options)
45
46     def base_platforms(self):
47         return ('test',)
48
49     def baseline_path(self):
50         return os.path.join(self.layout_tests_dir(), 'platform',
51                             self.name())
52
53     def baseline_search_path(self):
54         return [self.baseline_path()]
55
56     def check_build(self, needs_http):
57         return True
58
59     def compare_text(self, expected_text, actual_text):
60         return False
61
62     def diff_image(self, expected_filename, actual_filename,
63                    diff_filename=None, tolerance=0):
64         return False
65
66     def diff_text(self, expected_text, actual_text,
67                   expected_filename, actual_filename):
68         return ''
69
70     def layout_tests_dir(self):
71         return self.path_from_webkit_base('WebKitTools', 'Scripts',
72                                           'webkitpy', 'layout_tests', 'data')
73
74     def name(self):
75         return self._name
76
77     def options(self):
78         return self._options
79
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')
84
85     def results_directory(self):
86         return '/tmp/' + self._options.results_directory
87
88     def setup_test_run(self):
89         pass
90
91     def show_results_html_file(self, filename):
92         pass
93
94     def create_driver(self, image_path, options):
95         return TestDriver(image_path, options, self)
96
97     def start_http_server(self):
98         pass
99
100     def start_websocket_server(self):
101         pass
102
103     def stop_http_server(self):
104         pass
105
106     def stop_websocket_server(self):
107         pass
108
109     def test_expectations(self):
110         """Returns the test expectations for this port.
111
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:
116             return file.read()
117
118     def test_base_platform_names(self):
119         return ('test',)
120
121     def test_platform_name(self):
122         return 'test'
123
124     def test_platform_names(self):
125         return self.test_base_platform_names()
126
127     def test_platform_name_to_name(self, test_platform_name):
128         return test_platform_name
129
130     def version():
131         return ''
132
133     def wdiff_text(self, expected_filename, actual_filename):
134         return ''
135
136
137 class TestDriver(base.Driver):
138     """Test/Dummy implementation of the DumpRenderTree interface."""
139
140     def __init__(self, image_path, test_driver_options, port):
141         self._driver_options = test_driver_options
142         self._image_path = image_path
143         self._port = port
144         self._image_written = False
145
146     def poll(self):
147         return True
148
149     def returncode(self):
150         return 0
151
152     def run_test(self, uri, timeoutms, image_hash):
153         if not self._image_written and self._port._options.pixel_tests:
154             with open(self._image_path, "w") as f:
155                 f.write("bad png file from TestDriver")
156                 self._image_written = True
157
158         # We special-case this because we can't fake an image hash for a
159         # missing expectation.
160         if uri.find('misc/missing-expectation') != -1:
161             return (False, False, 'deadbeefdeadbeefdeadbeefdeadbeef', '', None)
162         return (False, False, image_hash, '', None)
163
164     def start(self):
165         pass
166
167     def stop(self):
168         pass