2 # Copyright (C) 2010 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
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 """Unit tests for update_webgl_conformance_tests."""
33 from webkitpy.to_be_moved import update_webgl_conformance_tests as webgl
36 def construct_script(name):
37 return "<script src=\"" + name + "\"></script>\n"
40 def construct_style(name):
41 return "<link rel=\"stylesheet\" href=\"" + name + "\">"
44 class TestTranslation(unittest.TestCase):
45 def assert_unchanged(self, text):
46 self.assertEqual(text, webgl.translate_khronos_test(text))
48 def assert_translate(self, input, output):
49 self.assertEqual(output, webgl.translate_khronos_test(input))
51 def test_simple_unchanged(self):
52 self.assert_unchanged("")
53 self.assert_unchanged("<html></html>")
55 def test_header_strip(self):
56 single_line_header = "<!-- single line header. -->"
57 multi_line_header = """<!-- this is a multi-line
58 header. it should all be removed too.
60 text = "<html></html>"
61 self.assert_translate(single_line_header, "")
62 self.assert_translate(single_line_header + text, text)
63 self.assert_translate(multi_line_header + text, text)
65 def dont_strip_other_headers(self):
66 self.assert_unchanged("<html>\n<!-- don't remove comments on other lines. -->\n</html>")
68 def test_include_rewriting(self):
69 # Mappings to None are unchanged
71 "../resources/js-test-style.css": "../../js/resources/js-test-style.css",
73 "resources/stylesheet.css": None,
74 "../resources/style.css": None,
77 "../resources/js-test-pre.js": "../../js/resources/js-test-pre.js",
78 "../resources/js-test-post.js": "../../js/resources/js-test-post.js",
79 "../resources/desktop-gl-constants.js": "resources/desktop-gl-constants.js",
81 "resources/shadow-offset.js": None,
82 "../resources/js-test-post-async.js": None,
87 for input, output in styles.items():
88 input_text += construct_style(input)
89 output_text += construct_style(output if output else input)
90 for input, output in scripts.items():
91 input_text += construct_script(input)
92 output_text += construct_script(output if output else input)
94 head = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">\n<html>\n<head>\n'
95 foot = '</head>\n<body>\n</body>\n</html>'
96 input_text = head + input_text + foot
97 output_text = head + output_text + foot
98 self.assert_translate(input_text, output_text)
101 if __name__ == '__main__':