initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / common / net / layouttestresults_unittest.py
1 # Copyright (c) 2010, Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
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
12 # distribution.
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.
16 #
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.
28
29 import unittest
30
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
36
37
38 class ORWTResultsHTMLParserTest(unittest.TestCase):
39     _example_results_html = """
40 <html>
41 <head>
42 <title>Layout Test Results</title>
43 </head>
44 <body>
45 <p>Tests that had stderr output:</p>
46 <table>
47 <tr>
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>
50 </tr>
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>
53 </tr>
54 </table><p>Tests that had no expected results (probably new):</p>
55 <table>
56 <tr>
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>
59 </tr>
60 </table></body>
61 </html>
62 """
63
64     _example_results_html_with_failing_tests = """
65 <html>
66 <head>
67 <title>Layout Test Results</title>
68 </head>
69 <body>
70 <p>Tests where results did not match expected results:</p>
71 <table>
72 <tr>
73 <td><a href="http://trac.webkit.org/export/91245/trunk/LayoutTests/compositing/plugins/composited-plugin.html">compositing/plugins/composited-plugin.html</a></td>
74 <td>
75 <a href="compositing/plugins/composited-plugin-expected.txt">expected</a>
76 </td>
77 <td>
78 <a href="compositing/plugins/composited-plugin-actual.txt">actual</a>
79 </td>
80 <td>
81 <a href="compositing/plugins/composited-plugin-diffs.txt">diff</a>
82 </td>
83 <td>
84 <a href="compositing/plugins/composited-plugin-pretty-diff.html">pretty diff</a>
85 </td>
86 </tr>
87 </table>
88 <p>Tests that had stderr output:</p>
89 <table>
90 <tr>
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>
93 </tr>
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>
96 </tr>
97 </table><p>Tests that had no expected results (probably new):</p>
98 <table>
99 <tr>
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>
102 </tr>
103 </table></body>
104 </html>
105 """
106
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)]
111
112         results = ORWTResultsHTMLParser.parse_results_html(self._example_results_html)
113         self.assertEqual(expected_results, results)
114
115
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)
123
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)
127
128
129 class LayoutTestResultsTest(unittest.TestCase):
130
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)
136
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)
142
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)