OLD | NEW |
1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 pass | 69 pass |
70 | 70 |
71 def test_get_crash_log(self): | 71 def test_get_crash_log(self): |
72 pass | 72 pass |
73 | 73 |
74 def test_check_build(self): | 74 def test_check_build(self): |
75 pass | 75 pass |
76 | 76 |
77 | 77 |
78 class MockDRTTest(unittest.TestCase): | 78 class MockDRTTest(unittest.TestCase): |
79 def input_line(self, port, test_name, checksum=None): | 79 def input_line(self, port, test_name, pixel_tests, checksum=None): |
80 url = port.create_driver(0).test_to_uri(test_name) | 80 url = port.create_driver(0).test_to_uri(test_name) |
81 if url.startswith('file://'): | 81 if url.startswith('file://'): |
82 url = url[len('file://'):] | 82 url = url[len('file://'):] |
83 | 83 if pixel_tests: |
| 84 url += "'--pixel-test" |
84 if checksum: | 85 if checksum: |
85 return url + "'" + checksum + '\n' | 86 url += "'" + checksum |
86 return url + '\n' | 87 return url + '\n' |
87 | 88 |
88 def extra_args(self, pixel_tests): | |
89 if pixel_tests: | |
90 return ['--pixel-tests', '-'] | |
91 return ['-'] | |
92 | |
93 def make_drt(self, options, args, host, stdin, stdout, stderr): | 89 def make_drt(self, options, args, host, stdin, stdout, stderr): |
94 return mock_drt.MockDRT(options, args, host, stdin, stdout, stderr) | 90 return mock_drt.MockDRT(options, args, host, stdin, stdout, stderr) |
95 | 91 |
96 def make_input_output(self, port, test_name, pixel_tests, | 92 def make_input_output(self, port, test_name, pixel_tests, |
97 expected_checksum, drt_output, drt_input=None, expecte
d_text=None): | 93 expected_checksum, drt_output, drt_input=None, expecte
d_text=None): |
98 if pixel_tests: | 94 if pixel_tests: |
99 if not expected_checksum: | 95 if not expected_checksum: |
100 expected_checksum = port.expected_checksum(test_name) | 96 expected_checksum = port.expected_checksum(test_name) |
101 if not drt_input: | 97 if not drt_input: |
102 drt_input = self.input_line(port, test_name, expected_checksum) | 98 drt_input = self.input_line(port, test_name, pixel_tests, expected_c
hecksum) |
103 text_output = expected_text or port.expected_text(test_name) or '' | 99 text_output = expected_text or port.expected_text(test_name) or '' |
104 | 100 |
105 if not drt_output: | 101 if not drt_output: |
106 drt_output = self.expected_output(port, test_name, pixel_tests, | 102 drt_output = self.expected_output(port, test_name, pixel_tests, |
107 text_output, expected_checksum) | 103 text_output, expected_checksum) |
108 return (drt_input, drt_output) | 104 return (drt_input, drt_output) |
109 | 105 |
110 def expected_output(self, port, test_name, pixel_tests, text_output, expecte
d_checksum): | 106 def expected_output(self, port, test_name, pixel_tests, text_output, expecte
d_checksum): |
111 output = ['Content-Type: text/plain\n'] | 107 output = ['Content-Type: text/plain\n'] |
112 if text_output: | 108 if text_output: |
113 output.append(text_output) | 109 output.append(text_output) |
114 output.append('#EOF\n') | 110 output.append('#EOF\n') |
115 if pixel_tests and expected_checksum: | 111 if pixel_tests and expected_checksum: |
116 output.extend(['\n', | 112 output.extend(['\n', |
117 'ActualHash: %s\n' % expected_checksum, | 113 'ActualHash: %s\n' % expected_checksum, |
118 'ExpectedHash: %s\n' % expected_checksum]) | 114 'ExpectedHash: %s\n' % expected_checksum]) |
119 output.append('#EOF\n') | 115 output.append('#EOF\n') |
120 return output | 116 return output |
121 | 117 |
122 def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_out
put=None, host=None, expected_text=None): | 118 def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_out
put=None, host=None, expected_text=None): |
123 port_name = 'test' | 119 port_name = 'test' |
124 host = host or MockSystemHost() | 120 host = host or MockSystemHost() |
125 test.add_unit_tests_to_mock_filesystem(host.filesystem) | 121 test.add_unit_tests_to_mock_filesystem(host.filesystem) |
126 port = PortFactory(host).get(port_name) | 122 port = PortFactory(host).get(port_name) |
127 drt_input, drt_output = self.make_input_output(port, test_name, | 123 drt_input, drt_output = self.make_input_output(port, test_name, |
128 pixel_tests, expected_checksum, drt_output, drt_input=None, expected
_text=expected_text) | 124 pixel_tests, expected_checksum, drt_output, drt_input=None, expected
_text=expected_text) |
129 | 125 |
130 args = ['--platform', port_name] + self.extra_args(pixel_tests) | 126 args = ['--dump-render-tree', '--platform', port_name, '-'] |
131 stdin = newstringio.StringIO(drt_input) | 127 stdin = newstringio.StringIO(drt_input) |
132 stdout = newstringio.StringIO() | 128 stdout = newstringio.StringIO() |
133 stderr = newstringio.StringIO() | 129 stderr = newstringio.StringIO() |
134 options, args = mock_drt.parse_options(args) | 130 options, args = mock_drt.parse_options(args) |
135 | 131 |
136 drt = self.make_drt(options, args, host, stdin, stdout, stderr) | 132 drt = self.make_drt(options, args, host, stdin, stdout, stderr) |
137 res = drt.run() | 133 res = drt.run() |
138 | 134 |
139 self.assertEqual(res, 0) | 135 self.assertEqual(res, 0) |
140 | 136 |
141 # We use the StringIO.buflist here instead of getvalue() because | 137 # We use the StringIO.buflist here instead of getvalue() because |
142 # the StringIO might be a mix of unicode/ascii and 8-bit strings. | 138 # the StringIO might be a mix of unicode/ascii and 8-bit strings. |
143 self.assertEqual(stdout.buflist, drt_output) | 139 self.assertEqual(stdout.buflist, drt_output) |
144 self.assertEqual(stderr.getvalue(), '' if options.test_shell else '#EOF\
n') | 140 self.assertEqual(stderr.getvalue(), '#EOF\n') |
145 | 141 |
146 def test_main(self): | 142 def test_main(self): |
147 host = MockSystemHost() | 143 host = MockSystemHost() |
148 test.add_unit_tests_to_mock_filesystem(host.filesystem) | 144 test.add_unit_tests_to_mock_filesystem(host.filesystem) |
149 stdin = newstringio.StringIO() | 145 stdin = newstringio.StringIO() |
150 stdout = newstringio.StringIO() | 146 stdout = newstringio.StringIO() |
151 stderr = newstringio.StringIO() | 147 stderr = newstringio.StringIO() |
152 res = mock_drt.main(['--platform', 'test'] + self.extra_args(False), | 148 res = mock_drt.main(['--dump-render-tree', '--platform', 'test', '-'], |
153 host, stdin, stdout, stderr) | 149 host, stdin, stdout, stderr) |
154 self.assertEqual(res, 0) | 150 self.assertEqual(res, 0) |
155 self.assertEqual(stdout.getvalue(), '') | 151 self.assertEqual(stdout.getvalue(), '') |
156 self.assertEqual(stderr.getvalue(), '') | 152 self.assertEqual(stderr.getvalue(), '') |
157 self.assertEqual(host.filesystem.written_files, {}) | 153 self.assertEqual(host.filesystem.written_files, {}) |
158 | 154 |
159 def test_pixeltest_passes(self): | 155 def test_pixeltest_passes(self): |
160 # This also tests that we handle HTTP: test URLs properly. | 156 # This also tests that we handle HTTP: test URLs properly. |
161 self.assertTest('http/tests/passes/text.html', True) | 157 self.assertTest('http/tests/passes/text.html', True) |
162 | 158 |
(...skipping 14 matching lines...) Expand all Loading... |
177 def test_checksum_in_png(self): | 173 def test_checksum_in_png(self): |
178 self.assertTest('passes/checksum_in_image.html', True) | 174 self.assertTest('passes/checksum_in_image.html', True) |
179 | 175 |
180 def test_missing_image(self): | 176 def test_missing_image(self): |
181 self.assertTest('failures/expected/missing_image.html', True) | 177 self.assertTest('failures/expected/missing_image.html', True) |
182 | 178 |
183 def test_missing_text(self): | 179 def test_missing_text(self): |
184 self.assertTest('failures/expected/missing_text.html', True) | 180 self.assertTest('failures/expected/missing_text.html', True) |
185 | 181 |
186 def test_reftest_match(self): | 182 def test_reftest_match(self): |
187 self.assertTest('passes/reftest.html', False, expected_checksum='mock-ch
ecksum', expected_text='reference text\n') | |
188 self.assertTest('passes/reftest.html', True, expected_checksum='mock-che
cksum', expected_text='reference text\n') | 183 self.assertTest('passes/reftest.html', True, expected_checksum='mock-che
cksum', expected_text='reference text\n') |
189 | 184 |
190 def test_reftest_mismatch(self): | 185 def test_reftest_mismatch(self): |
191 self.assertTest('passes/mismatch.html', False, expected_checksum='mock-c
hecksum', expected_text='reference text\n') | |
192 self.assertTest('passes/mismatch.html', True, expected_checksum='mock-ch
ecksum', expected_text='reference text\n') | 186 self.assertTest('passes/mismatch.html', True, expected_checksum='mock-ch
ecksum', expected_text='reference text\n') |
193 | 187 |
| 188 def test_audio(self): |
| 189 self.assertTest('passes/audio.html', pixel_tests=True, |
| 190 drt_output=['Content-Type: audio/wav\n', |
| 191 'Content-Transfer-Encoding: base64\n', |
| 192 'YXVkaW8td2F2', |
| 193 '\n', |
| 194 '#EOF\n', |
| 195 '#EOF\n']) |
194 | 196 |
195 class MockTestShellTest(MockDRTTest): | 197 def test_virtual(self): |
196 def extra_args(self, pixel_tests): | 198 self.assertTest('virtual/passes/text.html', True) |
197 if pixel_tests: | |
198 return ['--pixel-tests=/tmp/png_result0.png'] | |
199 return [] | |
200 | |
201 def make_drt(self, options, args, host, stdin, stdout, stderr): | |
202 options.test_shell = True | |
203 | |
204 # We have to set these by hand because --platform test won't trigger | |
205 # the Chromium code paths. | |
206 options.pixel_path = '/tmp/png_result0.png' | |
207 options.pixel_tests = True | |
208 | |
209 return mock_drt.MockTestShell(options, args, host, stdin, stdout, stderr
) | |
210 | |
211 def input_line(self, port, test_name, checksum=None): | |
212 url = port.create_driver(0).test_to_uri(test_name) | |
213 if checksum: | |
214 return url + ' 6000 ' + checksum + '\n' | |
215 return url + ' 6000\n' | |
216 | |
217 def expected_output(self, port, test_name, pixel_tests, text_output, expecte
d_checksum): | |
218 url = port.create_driver(0).test_to_uri(test_name) | |
219 output = ['#URL:%s\n' % url] | |
220 if expected_checksum: | |
221 output.append('#MD5:%s\n' % expected_checksum) | |
222 if text_output: | |
223 output.append(text_output) | |
224 if not text_output.endswith('\n'): | |
225 output.append('\n') | |
226 output.append('#EOF\n') | |
227 return output | |
228 | |
229 def test_pixeltest__fails(self): | |
230 host = MockSystemHost() | |
231 url = '#URL:file://' | |
232 url = url + '%s/failures/expected/image_checksum.html' % PortFactory(hos
t).get('test').layout_tests_dir() | |
233 self.assertTest('failures/expected/image_checksum.html', pixel_tests=Tru
e, | |
234 expected_checksum='image_checksum', | |
235 drt_output=[url + '\n', | |
236 '#MD5:image_checksum-checksum\n', | |
237 'image_checksum-txt', | |
238 '\n', | |
239 '#EOF\n'], | |
240 host=host) | |
241 self.assertEqual(host.filesystem.written_files, | |
242 {'/tmp/png_result0.png': 'image_checksum\x8a-pngtEXtchecksum\x00imag
e_checksum-checksum'}) | |
243 | |
244 def test_test_shell_parse_options(self): | |
245 options, args = mock_drt.parse_options(['--platform', 'mac', '--test-she
ll', | |
246 '--pixel-tests=/tmp/png_result0.png']) | |
247 self.assertTrue(options.test_shell) | |
248 self.assertTrue(options.pixel_tests) | |
249 self.assertEqual(options.pixel_path, '/tmp/png_result0.png') | |
OLD | NEW |