| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from extensions_paths import EXAMPLES, PUBLIC_TEMPLATES, STATIC_DOCS | 8 from extensions_paths import EXAMPLES, PUBLIC_TEMPLATES, STATIC_DOCS |
| 9 from local_file_system import LocalFileSystem | 9 from local_file_system import LocalFileSystem |
| 10 from render_servlet import RenderServlet | 10 from render_servlet import RenderServlet |
| 11 from server_instance import ServerInstance | 11 from server_instance import ServerInstance |
| 12 from servlet import Request, Response | 12 from servlet import Request, Response |
| 13 from test_util import ReadFile | 13 from test_util import ReadFile |
| 14 | 14 |
| 15 | 15 |
| 16 class _RenderServletDelegate(RenderServlet.Delegate): | 16 class _RenderServletDelegate(RenderServlet.Delegate): |
| 17 def CreateServerInstance(self): | 17 def CreateServerInstance(self): |
| 18 return ServerInstance.ForTest(LocalFileSystem.Create()) | 18 return ServerInstance.ForTest(LocalFileSystem.Create()) |
| 19 | 19 |
| 20 | 20 |
| 21 class RenderServletTest(unittest.TestCase): | 21 class RenderServletTest(unittest.TestCase): |
| 22 def _Render(self, path): | 22 def _Render(self, path, headers=None): |
| 23 return RenderServlet(Request.ForTest(path), | 23 return RenderServlet(Request.ForTest(path, headers=headers), |
| 24 _RenderServletDelegate()).Get() | 24 _RenderServletDelegate()).Get() |
| 25 | 25 |
| 26 def testExtensionAppRedirect(self): | 26 def testExtensionAppRedirect(self): |
| 27 self.assertEqual( | 27 self.assertEqual( |
| 28 Response.Redirect('/apps/storage', permanent=False), | 28 Response.Redirect('/apps/storage', permanent=False), |
| 29 self._Render('storage')) | 29 self._Render('storage')) |
| 30 | 30 |
| 31 def testChannelRedirect(self): | 31 def testChannelRedirect(self): |
| 32 for channel in ('stable', 'beta', 'dev', 'trunk'): | 32 for channel in ('stable', 'beta', 'dev', 'trunk'): |
| 33 self.assertEqual( | 33 self.assertEqual( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 def testOtherRedirectsJsonRedirect(self): | 103 def testOtherRedirectsJsonRedirect(self): |
| 104 response = self._Render('apps/webview_tag') | 104 response = self._Render('apps/webview_tag') |
| 105 self.assertEqual(('/apps/tags/webview', False), | 105 self.assertEqual(('/apps/tags/webview', False), |
| 106 response.GetRedirect()) | 106 response.GetRedirect()) |
| 107 | 107 |
| 108 def testDirectories(self): | 108 def testDirectories(self): |
| 109 # Directories should be redirected to a URL that doesn't end in a '/' | 109 # Directories should be redirected to a URL that doesn't end in a '/' |
| 110 # whether or not that exists. | 110 # whether or not that exists. |
| 111 self.assertEqual(('/dir', False), self._Render('dir/').GetRedirect()) | 111 self.assertEqual(('/dir', False), self._Render('dir/').GetRedirect()) |
| 112 | 112 |
| 113 def testEtags(self): |
| 114 def test_path(path, content_type): |
| 115 # Render without etag. |
| 116 response = self._Render(path) |
| 117 self.assertEqual(200, response.status) |
| 118 etag = response.headers.get('ETag') |
| 119 self.assertTrue(etag is not None) |
| 120 |
| 121 # Render with an If-None-Match which doesn't match. |
| 122 response = self._Render(path, headers={ |
| 123 'If-None-Match': '"fake etag"', |
| 124 }) |
| 125 self.assertEqual(200, response.status) |
| 126 self.assertEqual(content_type, response.headers.get('Content-Type')) |
| 127 self.assertEqual(etag, response.headers.get('ETag')) |
| 128 |
| 129 # Render with the correct matching If-None-Match. |
| 130 response = self._Render(path, headers={ |
| 131 'If-None-Match': etag, |
| 132 }) |
| 133 self.assertEqual(304, response.status) |
| 134 self.assertEqual('Not Modified', response.content.ToString()) |
| 135 self.assertEqual(content_type, response.headers.get('Content-Type')) |
| 136 self.assertEqual(etag, response.headers.get('ETag')) |
| 137 |
| 138 # Test with a static path and a dynamic path. |
| 139 test_path('static/css/out/site.css', 'text/css; charset=utf-8') |
| 140 test_path('extensions/storage', 'text/html; charset=utf-8') |
| 141 |
| 113 | 142 |
| 114 if __name__ == '__main__': | 143 if __name__ == '__main__': |
| 115 unittest.main() | 144 unittest.main() |
| OLD | NEW |