1 # Copyright (c) 2010, Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 from webkitpy.common.net.layouttestresults import LayoutTestResults, ORWTResultsHTMLParser
32 from webkitpy.common.system.outputcapture import OutputCapture
33 from webkitpy.layout_tests.models import test_results
34 from webkitpy.layout_tests.models import test_failures
35 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup
38 class ORWTResultsHTMLParserTest(unittest.TestCase):
39 _example_results_html = """
42 <title>Layout Test Results</title>
45 <p>Tests that had stderr output:</p>
48 <td><a href="/var/lib/buildbot/build/gtk-linux-64-release/build/LayoutTests/accessibility/aria-activedescendant-crash.html">accessibility/aria-activedescendant-crash.html</a></td>
49 <td><a href="accessibility/aria-activedescendant-crash-stderr.txt">stderr</a></td>
51 <td><a href="/var/lib/buildbot/build/gtk-linux-64-release/build/LayoutTests/http/tests/security/canvas-remote-read-svg-image.html">http/tests/security/canvas-remote-read-svg-image.html</a></td>
52 <td><a href="http/tests/security/canvas-remote-read-svg-image-stderr.txt">stderr</a></td>
54 </table><p>Tests that had no expected results (probably new):</p>
57 <td><a href="/var/lib/buildbot/build/gtk-linux-64-release/build/LayoutTests/fast/repaint/no-caret-repaint-in-non-content-editable-element.html">fast/repaint/no-caret-repaint-in-non-content-editable-element.html</a></td>
58 <td><a href="fast/repaint/no-caret-repaint-in-non-content-editable-element-actual.txt">result</a></td>
64 _example_results_html_with_failing_tests = """
67 <title>Layout Test Results</title>
70 <p>Tests where results did not match expected results:</p>
73 <td><a href="http://trac.webkit.org/export/91245/trunk/LayoutTests/compositing/plugins/composited-plugin.html">compositing/plugins/composited-plugin.html</a></td>
75 <a href="compositing/plugins/composited-plugin-expected.txt">expected</a>
78 <a href="compositing/plugins/composited-plugin-actual.txt">actual</a>
81 <a href="compositing/plugins/composited-plugin-diffs.txt">diff</a>
84 <a href="compositing/plugins/composited-plugin-pretty-diff.html">pretty diff</a>
88 <p>Tests that had stderr output:</p>
91 <td><a href="/var/lib/buildbot/build/gtk-linux-64-release/build/LayoutTests/accessibility/aria-activedescendant-crash.html">accessibility/aria-activedescendant-crash.html</a></td>
92 <td><a href="accessibility/aria-activedescendant-crash-stderr.txt">stderr</a></td>
94 <td><a href="/var/lib/buildbot/build/gtk-linux-64-release/build/LayoutTests/http/tests/security/canvas-remote-read-svg-image.html">http/tests/security/canvas-remote-read-svg-image.html</a></td>
95 <td><a href="http/tests/security/canvas-remote-read-svg-image-stderr.txt">stderr</a></td>
97 </table><p>Tests that had no expected results (probably new):</p>
100 <td><a href="/var/lib/buildbot/build/gtk-linux-64-release/build/LayoutTests/fast/repaint/no-caret-repaint-in-non-content-editable-element.html">fast/repaint/no-caret-repaint-in-non-content-editable-element.html</a></td>
101 <td><a href="fast/repaint/no-caret-repaint-in-non-content-editable-element-actual.txt">result</a></td>
107 def test_parse_layout_test_results(self):
108 failures = [test_failures.FailureMissingResult(), test_failures.FailureMissingImageHash(), test_failures.FailureMissingImage()]
109 testname = 'fast/repaint/no-caret-repaint-in-non-content-editable-element.html'
110 expected_results = [test_results.TestResult(testname, failures)]
112 results = ORWTResultsHTMLParser.parse_results_html(self._example_results_html)
113 self.assertEqual(expected_results, results)
116 def test_failures_from_fail_row(self):
117 row = BeautifulSoup("<tr><td><a>test.hml</a></td><td><a>expected image</a></td><td><a>25%</a></td></tr>")
118 test_name = unicode(row.find("a").string)
119 # Even if the caller has already found the test name, findAll inside _failures_from_fail_row will see it again.
120 failures = OutputCapture().assert_outputs(self, ORWTResultsHTMLParser._failures_from_fail_row, [row])
121 self.assertEqual(len(failures), 1)
122 self.assertEqual(type(sorted(failures)[0]), test_failures.FailureImageHashMismatch)
124 row = BeautifulSoup("<tr><td><a>test.hml</a><a>foo</a></td></tr>")
125 expected_stderr = "Unhandled link text in results.html parsing: foo. Please file a bug against webkitpy.\n"
126 OutputCapture().assert_outputs(self, ORWTResultsHTMLParser._failures_from_fail_row, [row], expected_stderr=expected_stderr)
129 class LayoutTestResultsTest(unittest.TestCase):
131 def test_set_failure_limit_count(self):
132 results = LayoutTestResults([])
133 self.assertEquals(results.failure_limit_count(), None)
134 results.set_failure_limit_count(10)
135 self.assertEquals(results.failure_limit_count(), 10)
137 def test_results_from_string(self):
138 self.assertEqual(LayoutTestResults.results_from_string(None), None)
139 self.assertEqual(LayoutTestResults.results_from_string(""), None)
140 results = LayoutTestResults.results_from_string(ORWTResultsHTMLParserTest._example_results_html)
141 self.assertEqual(len(results.failing_tests()), 0)
143 def test_tests_matching_failure_types(self):
144 results = LayoutTestResults.results_from_string(ORWTResultsHTMLParserTest._example_results_html_with_failing_tests)
145 failing_tests = results.tests_matching_failure_types([test_failures.FailureTextMismatch])
146 self.assertEqual(len(results.failing_tests()), 1)