Home | History | Annotate | Download | only in layout_tests
      1 #!/usr/bin/python
      2 # Copyright (C) 2010 Google Inc. All rights reserved.
      3 #
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions are
      6 # met:
      7 #
      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
     13 # distribution.
     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.
     17 #
     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.
     29 
     30 """Unit tests for update_webgl_conformance_tests."""
     31 
     32 import unittest
     33 from webkitpy.layout_tests import update_webgl_conformance_tests as webgl
     34 
     35 
     36 def construct_script(name):
     37     return "<script src=\"" + name + "\"></script>\n"
     38 
     39 
     40 def construct_style(name):
     41     return "<link rel=\"stylesheet\" href=\"" + name + "\">"
     42 
     43 
     44 class TestTranslation(unittest.TestCase):
     45     def assert_unchanged(self, text):
     46         self.assertEqual(text, webgl.translate_khronos_test(text))
     47 
     48     def assert_translate(self, input, output):
     49         self.assertEqual(output, webgl.translate_khronos_test(input))
     50 
     51     def test_simple_unchanged(self):
     52         self.assert_unchanged("")
     53         self.assert_unchanged("<html></html>")
     54 
     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.
     59                 -->"""
     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)
     64 
     65     def dont_strip_other_headers(self):
     66         self.assert_unchanged("<html>\n<!-- don't remove comments on other lines. -->\n</html>")
     67 
     68     def test_include_rewriting(self):
     69         # Mappings to None are unchanged
     70         styles = {
     71             "../resources/js-test-style.css": "../../js/resources/js-test-style.css",
     72             "fail.css": None,
     73             "resources/stylesheet.css": None,
     74             "../resources/style.css": None,
     75         }
     76         scripts = {
     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",
     80 
     81             "resources/shadow-offset.js": None,
     82             "../resources/js-test-post-async.js": None,
     83         }
     84 
     85         input_text = ""
     86         output_text = ""
     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)
     93 
     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)
     99 
    100 
    101 if __name__ == '__main__':
    102     unittest.main()
    103