- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / pywebsocket / src / test / test_http_header_util.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2011, Google Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
10 #     * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
15 # distribution.
16 #     * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33 """Tests for http_header_util module."""
34
35
36 import unittest
37
38 from mod_pywebsocket import http_header_util
39
40
41 class UnitTest(unittest.TestCase):
42     """A unittest for http_header_util module."""
43
44     def test_parse_relative_uri(self):
45         host, port, resource = http_header_util.parse_uri('/ws/test')
46         self.assertEqual(None, host)
47         self.assertEqual(None, port)
48         self.assertEqual('/ws/test', resource)
49
50     def test_parse_absolute_uri(self):
51         host, port, resource = http_header_util.parse_uri(
52             'ws://localhost:10080/ws/test')
53         self.assertEqual('localhost', host)
54         self.assertEqual(10080, port)
55         self.assertEqual('/ws/test', resource)
56
57         host, port, resource = http_header_util.parse_uri(
58             'ws://example.com/ws/test')
59         self.assertEqual('example.com', host)
60         self.assertEqual(80, port)
61         self.assertEqual('/ws/test', resource)
62
63         host, port, resource = http_header_util.parse_uri(
64             'wss://example.com/')
65         self.assertEqual('example.com', host)
66         self.assertEqual(443, port)
67         self.assertEqual('/', resource)
68
69         host, port, resource = http_header_util.parse_uri(
70             'ws://example.com:8080')
71         self.assertEqual('example.com', host)
72         self.assertEqual(8080, port)
73         self.assertEqual('/', resource)
74
75     def test_parse_invalid_uri(self):
76         host, port, resource = http_header_util.parse_uri('ws:///')
77         self.assertEqual(None, resource)
78
79         host, port, resource = http_header_util.parse_uri('ws://localhost:')
80         self.assertEqual(None, resource)
81
82         host, port, resource = http_header_util.parse_uri('ws://localhost:/ws')
83         self.assertEqual(None, resource)
84
85
86 if __name__ == '__main__':
87     unittest.main()
88
89
90 # vi:sts=4 sw=4 et