Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/common/extensions/docs/server2/render_servlet_test.py

Issue 311793002: Docserver: Fix broken redirect on code.google.com/chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: also test http Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, headers=None): 22 def _Render(self, path, headers=None, host=None):
23 return RenderServlet(Request.ForTest(path, headers=headers), 23 return RenderServlet(Request.ForTest(path, headers=headers, host=host),
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(
34 Response.Redirect('/extensions/storage', permanent=True), 34 Response.Redirect('/extensions/storage', permanent=True),
35 self._Render('%s/extensions/storage' % channel)) 35 self._Render('%s/extensions/storage' % channel))
36 36
37 def testOldHostsRedirect(self):
38 self.assertEqual(
39 Response.Redirect('https://developer.chrome.com/extensions',
40 permanent=False),
41 self._Render('/chrome/extensions', host='http://code.google.com'))
42 self.assertEqual(
43 Response.Redirect('https://developer.chrome.com/extensions',
44 permanent=False),
45 self._Render('/chrome/extensions', host='https://code.google.com'))
46
37 def testNotFound(self): 47 def testNotFound(self):
38 def create_404_response(real_path): 48 def create_404_response(real_path):
39 real_404 = self._Render(real_path) 49 real_404 = self._Render(real_path)
40 self.assertEqual(200, real_404.status) 50 self.assertEqual(200, real_404.status)
41 real_404.status = 404 51 real_404.status = 404
42 return real_404 52 return real_404
43 53
44 root_404 = create_404_response('404') 54 root_404 = create_404_response('404')
45 extensions_404 = create_404_response('extensions/404') 55 extensions_404 = create_404_response('extensions/404')
46 apps_404 = create_404_response('apps/404') 56 apps_404 = create_404_response('apps/404')
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 self.assertEqual(content_type, response.headers.get('Content-Type')) 146 self.assertEqual(content_type, response.headers.get('Content-Type'))
137 self.assertEqual(etag, response.headers.get('ETag')) 147 self.assertEqual(etag, response.headers.get('ETag'))
138 148
139 # Test with a static path and a dynamic path. 149 # Test with a static path and a dynamic path.
140 test_path('static/css/out/site.css', 'text/css; charset=utf-8') 150 test_path('static/css/out/site.css', 'text/css; charset=utf-8')
141 test_path('extensions/storage', 'text/html; charset=utf-8') 151 test_path('extensions/storage', 'text/html; charset=utf-8')
142 152
143 153
144 if __name__ == '__main__': 154 if __name__ == '__main__':
145 unittest.main() 155 unittest.main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/render_servlet.py ('k') | chrome/common/extensions/docs/server2/servlet.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698