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