Home | History | Annotate | Download | only in net
      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
     32 from webkitpy.common.system.outputcapture import OutputCapture
     33 from webkitpy.layout_tests.layout_package import test_results
     34 from webkitpy.layout_tests.layout_package import test_failures
     35 from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup
     36 
     37 
     38 class LayoutTestResultsTest(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     def test_set_failure_limit_count(self):
     65         results = LayoutTestResults([])
     66         self.assertEquals(results.failure_limit_count(), None)
     67         results.set_failure_limit_count(10)
     68         self.assertEquals(results.failure_limit_count(), 10)
     69 
     70     def test_parse_layout_test_results(self):
     71         failures = [test_failures.FailureMissingResult(), test_failures.FailureMissingImageHash(), test_failures.FailureMissingImage()]
     72         testname = 'fast/repaint/no-caret-repaint-in-non-content-editable-element.html'
     73         expected_results = [test_results.TestResult(testname, failures)]
     74 
     75         results = LayoutTestResults._parse_results_html(self._example_results_html)
     76         self.assertEqual(expected_results, results)
     77 
     78     def test_results_from_string(self):
     79         self.assertEqual(LayoutTestResults.results_from_string(None), None)
     80         self.assertEqual(LayoutTestResults.results_from_string(""), None)
     81         results = LayoutTestResults.results_from_string(self._example_results_html)
     82         self.assertEqual(len(results.failing_tests()), 0)
     83 
     84     def test_failures_from_fail_row(self):
     85         row = BeautifulSoup("<tr><td><a>test.hml</a></td><td><a>expected image</a></td><td><a>25%</a></td></tr>")
     86         test_name = unicode(row.find("a").string)
     87         # Even if the caller has already found the test name, findAll inside _failures_from_fail_row will see it again.
     88         failures = OutputCapture().assert_outputs(self, LayoutTestResults._failures_from_fail_row, [row])
     89         self.assertEqual(len(failures), 1)
     90         self.assertEqual(type(sorted(failures)[0]), test_failures.FailureImageHashMismatch)
     91 
     92         row = BeautifulSoup("<tr><td><a>test.hml</a><a>foo</a></td></tr>")
     93         expected_stderr = "Unhandled link text in results.html parsing: foo.  Please file a bug against webkitpy.\n"
     94         OutputCapture().assert_outputs(self, LayoutTestResults._failures_from_fail_row, [row], expected_stderr=expected_stderr)
     95