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 10 matching lines...) Expand all Loading... |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Unit tests for MockDRT.""" | 29 """Unit tests for MockDRT.""" |
30 | 30 |
| 31 import io |
31 import sys | 32 import sys |
32 import unittest | 33 import unittest |
33 | 34 |
34 from webkitpy.common import newstringio | |
35 from webkitpy.common.system.systemhost_mock import MockSystemHost | 35 from webkitpy.common.system.systemhost_mock import MockSystemHost |
36 from webkitpy.layout_tests.port import mock_drt | 36 from webkitpy.layout_tests.port import mock_drt |
37 from webkitpy.layout_tests.port import port_testcase | 37 from webkitpy.layout_tests.port import port_testcase |
38 from webkitpy.layout_tests.port import test | 38 from webkitpy.layout_tests.port import test |
39 from webkitpy.layout_tests.port.factory import PortFactory | 39 from webkitpy.layout_tests.port.factory import PortFactory |
40 from webkitpy.tool import mocktool | 40 from webkitpy.tool import mocktool |
41 | 41 |
42 | 42 |
43 mock_options = mocktool.MockOptions(configuration='Release') | 43 mock_options = mocktool.MockOptions(configuration='Release') |
44 | 44 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_out
put=None, host=None, expected_text=None): | 121 def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_out
put=None, host=None, expected_text=None): |
122 port_name = 'test' | 122 port_name = 'test' |
123 host = host or MockSystemHost() | 123 host = host or MockSystemHost() |
124 test.add_unit_tests_to_mock_filesystem(host.filesystem) | 124 test.add_unit_tests_to_mock_filesystem(host.filesystem) |
125 port = PortFactory(host).get(port_name) | 125 port = PortFactory(host).get(port_name) |
126 drt_input, drt_output = self.make_input_output(port, test_name, | 126 drt_input, drt_output = self.make_input_output(port, test_name, |
127 pixel_tests, expected_checksum, drt_output, drt_input=None, expected
_text=expected_text) | 127 pixel_tests, expected_checksum, drt_output, drt_input=None, expected
_text=expected_text) |
128 | 128 |
129 args = ['--dump-render-tree', '--platform', port_name, '-'] | 129 args = ['--dump-render-tree', '--platform', port_name, '-'] |
130 stdin = newstringio.StringIO(drt_input) | 130 stdin = io.BytesIO(drt_input) |
131 stdout = newstringio.StringIO() | 131 stdout = io.BytesIO() |
132 stderr = newstringio.StringIO() | 132 stderr = io.BytesIO() |
133 options, args = mock_drt.parse_options(args) | 133 options, args = mock_drt.parse_options(args) |
134 | 134 |
135 drt = self.make_drt(options, args, host, stdin, stdout, stderr) | 135 drt = self.make_drt(options, args, host, stdin, stdout, stderr) |
136 res = drt.run() | 136 res = drt.run() |
137 | 137 |
138 self.assertEqual(res, 0) | 138 self.assertEqual(res, 0) |
139 | 139 |
140 # We use the StringIO.buflist here instead of getvalue() because | 140 self.assertEqual(stdout.getvalue(), ''.join(drt_output)) |
141 # the StringIO might be a mix of unicode/ascii and 8-bit strings. | |
142 self.assertEqual(stdout.buflist, drt_output) | |
143 self.assertEqual(stderr.getvalue(), '#EOF\n') | 141 self.assertEqual(stderr.getvalue(), '#EOF\n') |
144 | 142 |
145 def test_main(self): | 143 def test_main(self): |
146 host = MockSystemHost() | 144 host = MockSystemHost() |
147 test.add_unit_tests_to_mock_filesystem(host.filesystem) | 145 test.add_unit_tests_to_mock_filesystem(host.filesystem) |
148 stdin = newstringio.StringIO() | 146 stdin = io.BytesIO() |
149 stdout = newstringio.StringIO() | 147 stdout = io.BytesIO() |
150 stderr = newstringio.StringIO() | 148 stderr = io.BytesIO() |
151 res = mock_drt.main(['--dump-render-tree', '--platform', 'test', '-'], | 149 res = mock_drt.main(['--dump-render-tree', '--platform', 'test', '-'], |
152 host, stdin, stdout, stderr) | 150 host, stdin, stdout, stderr) |
153 self.assertEqual(res, 0) | 151 self.assertEqual(res, 0) |
154 self.assertEqual(stdout.getvalue(), '') | 152 self.assertEqual(stdout.getvalue(), '') |
155 self.assertEqual(stderr.getvalue(), '') | 153 self.assertEqual(stderr.getvalue(), '') |
156 self.assertEqual(host.filesystem.written_files, {}) | 154 self.assertEqual(host.filesystem.written_files, {}) |
157 | 155 |
158 def test_pixeltest_passes(self): | 156 def test_pixeltest_passes(self): |
159 # This also tests that we handle HTTP: test URLs properly. | 157 # This also tests that we handle HTTP: test URLs properly. |
160 self.assertTest('http/tests/passes/text.html', True) | 158 self.assertTest('http/tests/passes/text.html', True) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 self.assertTest('passes/audio.html', pixel_tests=True, | 190 self.assertTest('passes/audio.html', pixel_tests=True, |
193 drt_output=['Content-Type: audio/wav\n', | 191 drt_output=['Content-Type: audio/wav\n', |
194 'Content-Transfer-Encoding: base64\n', | 192 'Content-Transfer-Encoding: base64\n', |
195 'YXVkaW8td2F2', | 193 'YXVkaW8td2F2', |
196 '\n', | 194 '\n', |
197 '#EOF\n', | 195 '#EOF\n', |
198 '#EOF\n']) | 196 '#EOF\n']) |
199 | 197 |
200 def test_virtual(self): | 198 def test_virtual(self): |
201 self.assertTest('virtual/passes/text.html', True) | 199 self.assertTest('virtual/passes/text.html', True) |
OLD | NEW |