2 # Copyright (C) 2011 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 name of Google Inc. 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 """Unit tests for MockDRT."""
34 from webkitpy.common import newstringio
36 from webkitpy.layout_tests.port import mock_drt
37 from webkitpy.layout_tests.port import factory
38 from webkitpy.layout_tests.port import port_testcase
41 class MockDRTPortTest(port_testcase.PortTestCase):
43 return mock_drt.MockDRTPort()
46 class MockDRTTest(unittest.TestCase):
48 # We base our tests on the mac-snowleopard port.
49 self._port = factory.get('mac-snowleopard')
50 self._layout_tests_dir = self._port.layout_tests_dir()
52 def to_path(self, test_name):
53 return self._port._filesystem.join(self._layout_tests_dir, test_name)
55 def input_line(self, test_name, checksum=None):
56 url = self._port.filename_to_uri(self.to_path(test_name))
58 return url + "'" + checksum + '\n'
61 def make_drt(self, input_string, args=None, extra_args=None):
62 args = args or ['--platform', 'mac-snowleopard', '-']
63 extra_args = extra_args or []
65 stdin = newstringio.StringIO(input_string)
66 stdout = newstringio.StringIO()
67 stderr = newstringio.StringIO()
68 options, args = mock_drt.parse_options(args)
69 drt = mock_drt.MockDRT(options, args, stdin, stdout, stderr)
70 return (drt, stdout, stderr)
72 def make_input_output(self, test_name, pixel_tests):
73 path = self.to_path(test_name)
74 expected_checksum = None
76 expected_checksum = self._port.expected_checksum(path)
77 drt_input = self.input_line(test_name, expected_checksum)
78 text_output = self._port.expected_text(path)
82 "Content-Type: text/plain\n"
87 "#EOF\n") % (text_output, expected_checksum, expected_checksum)
90 "Content-Type: text/plain\n"
92 "#EOF\n") % text_output
94 return (drt_input, drt_output)
96 def assertTest(self, test_name, pixel_tests):
97 drt_input, drt_output = self.make_input_output(test_name, pixel_tests)
100 extra_args = ['--pixel-tests']
101 drt, stdout, stderr = self.make_drt(drt_input, extra_args)
103 self.assertEqual(res, 0)
104 self.assertEqual(stdout.getvalue(), drt_output)
105 self.assertEqual(stderr.getvalue(), '')
107 def test_pixeltest(self):
108 self.assertTest('fast/html/keygen.html', True)
110 def test_textonly(self):
111 self.assertTest('fast/html/article-element.html', False)
114 if __name__ == '__main__':