| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import StringIO | 5 import StringIO |
| 6 import gzip | 6 import gzip |
| 7 import imp | 7 import imp |
| 8 import os.path | 8 import os.path |
| 9 import shutil | 9 import shutil |
| 10 import sys | 10 import sys |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 def setUp(self): | 26 def setUp(self): |
| 27 """Creates a tree of temporary directories and files of the form described | 27 """Creates a tree of temporary directories and files of the form described |
| 28 below. | 28 below. |
| 29 | 29 |
| 30 parent_dir | 30 parent_dir |
| 31 hello_dir | 31 hello_dir |
| 32 hello_subdir | 32 hello_subdir |
| 33 hello_file | 33 hello_file |
| 34 other_dir | 34 other_dir |
| 35 other_file | 35 other_file |
| 36 apps |
| 37 app.dart |
| 36 """ | 38 """ |
| 37 self.parent_dir = tempfile.mkdtemp() | 39 self.parent_dir = tempfile.mkdtemp() |
| 38 self.parent_file = tempfile.NamedTemporaryFile(delete=False, | 40 self.parent_file = tempfile.NamedTemporaryFile(delete=False, |
| 39 dir=self.parent_dir) | 41 dir=self.parent_dir) |
| 40 self.hello_dir = tempfile.mkdtemp(dir=self.parent_dir) | 42 self.hello_dir = tempfile.mkdtemp(dir=self.parent_dir) |
| 41 self.hello_subdir = tempfile.mkdtemp(dir=self.hello_dir) | 43 self.hello_subdir = tempfile.mkdtemp(dir=self.hello_dir) |
| 42 self.hello_file = tempfile.NamedTemporaryFile(delete=False, | 44 self.hello_file = tempfile.NamedTemporaryFile(delete=False, |
| 43 dir=self.hello_subdir) | 45 dir=self.hello_subdir) |
| 44 self.hello_file.write('hello') | 46 self.hello_file.write('hello') |
| 45 self.hello_file.close() | 47 self.hello_file.close() |
| 46 | 48 |
| 47 self.other_dir = tempfile.mkdtemp(dir=self.parent_dir) | 49 self.other_dir = tempfile.mkdtemp(dir=self.parent_dir) |
| 48 self.other_file = tempfile.NamedTemporaryFile(delete=False, | 50 self.other_file = tempfile.NamedTemporaryFile(delete=False, |
| 49 dir=self.other_dir) | 51 dir=self.other_dir) |
| 52 self.other_file.close() |
| 53 |
| 54 self.apps_dir = tempfile.mkdtemp(dir=self.parent_dir) |
| 55 self.dart_app_path = os.path.join(self.apps_dir, 'app.dart') |
| 56 open(self.dart_app_path, 'w').close() |
| 50 | 57 |
| 51 def tearDown(self): | 58 def tearDown(self): |
| 52 shutil.rmtree(self.parent_dir) | 59 shutil.rmtree(self.parent_dir) |
| 53 | 60 |
| 54 def test_mappings(self): | 61 def test_mappings(self): |
| 55 """Maps two directories and verifies that the server serves files placed | 62 """Maps two directories and verifies that the server serves files placed |
| 56 there. | 63 there. |
| 57 """ | 64 """ |
| 58 mappings = [ | 65 mappings = [ |
| 59 ('hello/', [self.hello_dir]), | 66 ('hello/', [self.hello_dir]), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 hello_response = urllib2.urlopen(server_address + 'hello/' + | 135 hello_response = urllib2.urlopen(server_address + 'hello/' + |
| 129 hello_relpath) | 136 hello_relpath) |
| 130 self.assertEquals(200, hello_response.getcode()) | 137 self.assertEquals(200, hello_response.getcode()) |
| 131 self.assertTrue('Content-Encoding' in hello_response.info()) | 138 self.assertTrue('Content-Encoding' in hello_response.info()) |
| 132 self.assertEquals('gzip', hello_response.info().get('Content-Encoding')) | 139 self.assertEquals('gzip', hello_response.info().get('Content-Encoding')) |
| 133 | 140 |
| 134 content = gzip.GzipFile( | 141 content = gzip.GzipFile( |
| 135 fileobj=StringIO.StringIO(hello_response.read())).read() | 142 fileobj=StringIO.StringIO(hello_response.read())).read() |
| 136 self.assertEquals('hello', content) | 143 self.assertEquals('hello', content) |
| 137 | 144 |
| 145 def test_dart_mime_type(self): |
| 146 """Verifies that files of '.dart' extension are served with MIME type |
| 147 'application/dart'. |
| 148 """ |
| 149 mappings = [ |
| 150 ('', [self.apps_dir]), |
| 151 ] |
| 152 server_address = ('http://%s:%u/' % |
| 153 http_server.start_http_server(mappings)) |
| 154 |
| 155 app_relpath = os.path.relpath(self.dart_app_path, self.apps_dir) |
| 156 hello_response = urllib2.urlopen(server_address + app_relpath) |
| 157 self.assertEquals(200, hello_response.getcode()) |
| 158 self.assertTrue('Content-Type' in hello_response.info()) |
| 159 self.assertEquals('application/dart', |
| 160 hello_response.info().get('Content-Type')) |
| 161 |
| 138 | 162 |
| 139 if __name__ == "__main__": | 163 if __name__ == "__main__": |
| 140 unittest.main() | 164 unittest.main() |
| OLD | NEW |