extract_reference_link_unittest.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2011 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. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. import unittest2 as unittest
  25. from webkitpy.layout_tests.reftests import extract_reference_link
  26. class ExtractLinkMatchTest(unittest.TestCase):
  27. def test_getExtractMatch(self):
  28. html_1 = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  29. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  30. <html xmlns="http://www.w3.org/1999/xhtml">
  31. <head>
  32. <title>CSS Test: DESCRIPTION OF TEST</title>
  33. <link rel="author" title="NAME_OF_AUTHOR"
  34. href="mailto:EMAIL OR http://CONTACT_PAGE"/>
  35. <link rel="help" href="RELEVANT_SPEC_SECTION"/>
  36. <link rel="match" href="green-box-ref.xht" />
  37. <link rel="match" href="blue-box-ref.xht" />
  38. <link rel="mismatch" href="red-box-notref.xht" />
  39. <link rel="mismatch" href="red-box-notref.xht" />
  40. <meta name="flags" content="TOKENS" />
  41. <meta name="assert" content="TEST ASSERTION"/>
  42. <style type="text/css"><![CDATA[
  43. CSS FOR TEST
  44. ]]></style>
  45. </head>
  46. <body>
  47. CONTENT OF TEST
  48. </body>
  49. </html>
  50. """
  51. matches, mismatches = extract_reference_link.get_reference_link(html_1)
  52. self.assertItemsEqual(matches,
  53. ["green-box-ref.xht", "blue-box-ref.xht"])
  54. self.assertItemsEqual(mismatches,
  55. ["red-box-notref.xht", "red-box-notref.xht"])
  56. html_2 = ""
  57. empty_tuple_1 = extract_reference_link.get_reference_link(html_2)
  58. self.assertEqual(empty_tuple_1, ([], []))
  59. # Link does not have a "ref" attribute.
  60. html_3 = """<link href="RELEVANT_SPEC_SECTION"/>"""
  61. empty_tuple_2 = extract_reference_link.get_reference_link(html_3)
  62. self.assertEqual(empty_tuple_2, ([], []))
  63. # Link does not have a "href" attribute.
  64. html_4 = """<link rel="match"/>"""
  65. empty_tuple_3 = extract_reference_link.get_reference_link(html_4)
  66. self.assertEqual(empty_tuple_3, ([], []))
  67. # Link does not have a "/" at the end.
  68. html_5 = """<link rel="help" href="RELEVANT_SPEC_SECTION">"""
  69. empty_tuple_4 = extract_reference_link.get_reference_link(html_5)
  70. self.assertEqual(empty_tuple_4, ([], []))