| 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 local_file_system import LocalFileSystem | 9 from local_file_system import LocalFileSystem |
| 9 from render_servlet import RenderServlet | 10 from render_servlet import RenderServlet |
| 10 from server_instance import ServerInstance | 11 from server_instance import ServerInstance |
| 11 from servlet import Request, Response | 12 from servlet import Request, Response |
| 12 from test_util import DisableLogging, ReadFile | 13 from test_util import DisableLogging, ReadFile |
| 13 | 14 |
| 14 | 15 |
| 15 class _RenderServletDelegate(RenderServlet.Delegate): | 16 class _RenderServletDelegate(RenderServlet.Delegate): |
| 16 def CreateServerInstance(self): | 17 def CreateServerInstance(self): |
| 17 return ServerInstance.ForTest(LocalFileSystem.Create()) | 18 return ServerInstance.ForTest(LocalFileSystem.Create()) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 self.assertEqual( | 62 self.assertEqual( |
| 62 apps_404, self._Render('apps/manifest/not_found/not_found.html')) | 63 apps_404, self._Render('apps/manifest/not_found/not_found.html')) |
| 63 | 64 |
| 64 def testSampleFile(self): | 65 def testSampleFile(self): |
| 65 sample_file = 'extensions/talking_alarm_clock/background.js' | 66 sample_file = 'extensions/talking_alarm_clock/background.js' |
| 66 response = self._Render('extensions/examples/%s' % sample_file) | 67 response = self._Render('extensions/examples/%s' % sample_file) |
| 67 self.assertEqual(200, response.status) | 68 self.assertEqual(200, response.status) |
| 68 self.assertTrue(response.headers['Content-Type'] in ( | 69 self.assertTrue(response.headers['Content-Type'] in ( |
| 69 'application/javascript; charset=utf-8', | 70 'application/javascript; charset=utf-8', |
| 70 'application/x-javascript; charset=utf-8')) | 71 'application/x-javascript; charset=utf-8')) |
| 71 self.assertEqual(ReadFile('docs/examples/%s' % sample_file), | 72 self.assertEqual(ReadFile('%s/%s' % (EXAMPLES, sample_file)), |
| 72 response.content.ToString()) | 73 response.content.ToString()) |
| 73 | 74 |
| 74 def testSampleZip(self): | 75 def testSampleZip(self): |
| 75 sample_dir = 'extensions/talking_alarm_clock' | 76 sample_dir = 'extensions/talking_alarm_clock' |
| 76 response = self._Render('extensions/examples/%s.zip' % sample_dir) | 77 response = self._Render('extensions/examples/%s.zip' % sample_dir) |
| 77 self.assertEqual(200, response.status) | 78 self.assertEqual(200, response.status) |
| 78 self.assertEqual('application/zip', response.headers['Content-Type']) | 79 self.assertEqual('application/zip', response.headers['Content-Type']) |
| 79 | 80 |
| 80 def testStaticFile(self): | 81 def testStaticFile(self): |
| 81 static_file = 'css/site.css' | 82 static_file = 'css/site.css' |
| 82 response = self._Render('static/%s' % static_file) | 83 response = self._Render('static/%s' % static_file) |
| 83 self.assertEqual(200, response.status) | 84 self.assertEqual(200, response.status) |
| 84 self.assertEqual('text/css; charset=utf-8', | 85 self.assertEqual('text/css; charset=utf-8', |
| 85 response.headers['Content-Type']) | 86 response.headers['Content-Type']) |
| 86 self.assertEqual(ReadFile('docs/static/%s' % static_file), | 87 self.assertEqual(ReadFile('%s/%s' % (STATIC_DOCS, static_file)), |
| 87 response.content.ToString()) | 88 response.content.ToString()) |
| 88 | 89 |
| 89 def testHtmlTemplate(self): | 90 def testHtmlTemplate(self): |
| 90 html_file = 'extensions/storage.html' | 91 html_file = 'extensions/storage.html' |
| 91 response = self._Render(html_file) | 92 response = self._Render(html_file) |
| 92 self.assertEqual(200, response.status) | 93 self.assertEqual(200, response.status) |
| 93 self.assertEqual('text/html; charset=utf-8', | 94 self.assertEqual('text/html; charset=utf-8', |
| 94 response.headers.get('Content-Type')) | 95 response.headers.get('Content-Type')) |
| 95 # Can't really test rendering all that well. | 96 # Can't really test rendering all that well. |
| 96 self.assertTrue(len(response.content) > | 97 self.assertTrue(len(response.content) > |
| 97 len(ReadFile('docs/templates/public/%s' % html_file))) | 98 len(ReadFile('%s/%s' % (PUBLIC_TEMPLATES, html_file)))) |
| 98 | 99 |
| 99 def testDevelopersGoogleComRedirect(self): | 100 def testDevelopersGoogleComRedirect(self): |
| 100 def assert_redirect(request_path): | 101 def assert_redirect(request_path): |
| 101 response = self._Render(request_path) | 102 response = self._Render(request_path) |
| 102 self.assertEqual(('//developers.google.com/chrome', False), | 103 self.assertEqual(('//developers.google.com/chrome', False), |
| 103 response.GetRedirect()) | 104 response.GetRedirect()) |
| 104 assert_redirect('') | 105 assert_redirect('') |
| 105 assert_redirect('index.html') | 106 assert_redirect('index.html') |
| 106 | 107 |
| 107 def testIndexRedirect(self): | 108 def testIndexRedirect(self): |
| 108 response = self._Render('extensions') | 109 response = self._Render('extensions') |
| 109 self.assertEqual(('/extensions/index.html', False), | 110 self.assertEqual(('/extensions/index.html', False), |
| 110 response.GetRedirect()) | 111 response.GetRedirect()) |
| 111 | 112 |
| 112 def testOtherRedirectsJsonRedirect(self): | 113 def testOtherRedirectsJsonRedirect(self): |
| 113 response = self._Render('apps/webview_tag.html') | 114 response = self._Render('apps/webview_tag.html') |
| 114 self.assertEqual(('/apps/tags/webview.html', False), | 115 self.assertEqual(('/apps/tags/webview.html', False), |
| 115 response.GetRedirect()) | 116 response.GetRedirect()) |
| 116 | 117 |
| 117 | 118 |
| 118 if __name__ == '__main__': | 119 if __name__ == '__main__': |
| 119 unittest.main() | 120 unittest.main() |
| OLD | NEW |