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

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

Issue 54603010: Docserver: Implement the content providers infrastructure, where a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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 | Annotate | Revision Log
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 local_file_system import LocalFileSystem 8 from local_file_system import LocalFileSystem
9 from render_servlet import RenderServlet 9 from render_servlet import RenderServlet
10 from server_instance import ServerInstance 10 from server_instance import ServerInstance
11 from servlet import Request, Response 11 from servlet import Request, Response
12 from test_util import DisableLogging, ReadFile 12 from test_util import DisableLogging, ReadFile
13 13
14
14 class _RenderServletDelegate(RenderServlet.Delegate): 15 class _RenderServletDelegate(RenderServlet.Delegate):
15 def CreateServerInstance(self): 16 def CreateServerInstance(self):
16 return ServerInstance.ForTest(LocalFileSystem.Create()) 17 return ServerInstance.ForTest(LocalFileSystem.Create())
17 18
19
18 class RenderServletTest(unittest.TestCase): 20 class RenderServletTest(unittest.TestCase):
21 def _Render(self, path):
22 return RenderServlet(Request.ForTest(path),
23 _RenderServletDelegate()).Get()
24
19 def testExtensionAppRedirect(self): 25 def testExtensionAppRedirect(self):
20 request = Request.ForTest('storage.html')
21 self.assertEqual( 26 self.assertEqual(
22 Response.Redirect('/extensions/storage.html', permanent=False), 27 Response.Redirect('/extensions/storage.html', permanent=False),
23 RenderServlet(request, _RenderServletDelegate()).Get()) 28 self._Render('storage.html'))
24 29
25 def testChannelRedirect(self): 30 def testChannelRedirect(self):
26 request = Request.ForTest('stable/extensions/storage.html')
27 self.assertEqual( 31 self.assertEqual(
28 Response.Redirect('/extensions/storage.html', permanent=True), 32 Response.Redirect('/extensions/storage.html', permanent=True),
29 RenderServlet(request, _RenderServletDelegate()).Get()) 33 self._Render('stable/extensions/storage.html'))
30 34
31 @DisableLogging('warning')
32 def testNotFound(self): 35 def testNotFound(self):
33 request = Request.ForTest('extensions/not_found.html') 36 def create_404_response(real_path):
34 response = RenderServlet(request, _RenderServletDelegate()).Get() 37 real_404 = self._Render(real_path)
35 self.assertEqual(404, response.status) 38 self.assertEqual(200, real_404.status)
39 real_404.status = 404
40 return real_404
41
42 root_404 = create_404_response('404.html')
43 extensions_404 = create_404_response('extensions/404.html')
44 apps_404 = create_404_response('apps/404.html')
45 # Note: would test that root_404 != extensions and apps but it's not
46 # necessarily true.
47 self.assertNotEqual(extensions_404, apps_404)
48
49 self.assertEqual(root_404, self._Render('not_found.html'))
50 self.assertEqual(root_404, self._Render('not_found/not_found.html'))
51
52 self.assertEqual(extensions_404, self._Render('extensions/not_found.html'))
53 self.assertEqual(
54 extensions_404, self._Render('extensions/manifest/not_found.html'))
55 self.assertEqual(
56 extensions_404,
57 self._Render('extensions/manifest/not_found/not_found.html'))
58
59 self.assertEqual(apps_404, self._Render('apps/not_found.html'))
60 self.assertEqual(apps_404, self._Render('apps/manifest/not_found.html'))
61 self.assertEqual(
62 apps_404, self._Render('apps/manifest/not_found/not_found.html'))
36 63
37 def testSampleFile(self): 64 def testSampleFile(self):
38 sample_file = 'extensions/talking_alarm_clock/background.js' 65 sample_file = 'extensions/talking_alarm_clock/background.js'
39 request = Request.ForTest('extensions/examples/%s' % sample_file) 66 response = self._Render('extensions/examples/%s' % sample_file)
40 response = RenderServlet(request, _RenderServletDelegate()).Get()
41 self.assertEqual(200, response.status) 67 self.assertEqual(200, response.status)
42 content_type = response.headers.get('content-type') 68 content_type = response.headers.get('content-type')
43 self.assertTrue(content_type == 'application/javascript' or 69 self.assertTrue(content_type == 'application/javascript' or
44 content_type == 'application/x-javascript') 70 content_type == 'application/x-javascript')
45 self.assertEqual(ReadFile('docs/examples/%s' % sample_file), 71 self.assertEqual(ReadFile('docs/examples/%s' % sample_file),
46 response.content.ToString()) 72 response.content.ToString())
47 73
48 def testSampleZip(self): 74 def testSampleZip(self):
49 sample_dir = 'extensions/talking_alarm_clock' 75 sample_dir = 'extensions/talking_alarm_clock'
50 request = Request.ForTest('extensions/examples/%s.zip' % sample_dir) 76 response = self._Render('extensions/examples/%s.zip' % sample_dir)
51 response = RenderServlet(request, _RenderServletDelegate()).Get()
52 self.assertEqual(200, response.status) 77 self.assertEqual(200, response.status)
53 self.assertEqual('application/zip', response.headers.get('content-type')) 78 self.assertEqual('application/zip', response.headers.get('content-type'))
54 79
55 def testStaticFile(self): 80 def testStaticFile(self):
56 static_file = 'css/site.css' 81 static_file = 'css/site.css'
57 request = Request.ForTest('static/%s' % static_file) 82 response = self._Render('static/%s' % static_file)
58 response = RenderServlet(request, _RenderServletDelegate()).Get()
59 self.assertEqual(200, response.status) 83 self.assertEqual(200, response.status)
60 self.assertEqual('text/css', response.headers.get('content-type')) 84 self.assertEqual('text/css', response.headers.get('content-type'))
61 self.assertEqual(ReadFile('docs/static/%s' % static_file), 85 self.assertEqual(ReadFile('docs/static/%s' % static_file),
62 response.content.ToString()) 86 response.content.ToString())
63 87
64 def testHtmlTemplate(self): 88 def testHtmlTemplate(self):
65 html_file = 'extensions/storage.html' 89 html_file = 'extensions/storage.html'
66 request = Request.ForTest(html_file) 90 response = self._Render(html_file)
67 response = RenderServlet(request, _RenderServletDelegate()).Get()
68 self.assertEqual(200, response.status) 91 self.assertEqual(200, response.status)
69 self.assertEqual('text/html', response.headers.get('content-type')) 92 self.assertEqual('text/html', response.headers.get('content-type'))
70 # Can't really test rendering all that well. 93 # Can't really test rendering all that well.
71 self.assertTrue(len(response.content) > 94 self.assertTrue(len(response.content) >
72 len(ReadFile('docs/templates/public/%s' % html_file))) 95 len(ReadFile('docs/templates/public/%s' % html_file)))
73 96
97 def testDevelopersGoogleComRedirect(self):
98 def assert_redirect(request_path):
99 response = self._Render(request_path)
100 self.assertEqual(('//developers.google.com/chrome', False),
101 response.GetRedirect())
102 assert_redirect('')
103 assert_redirect('index.html')
104
105 def testIndexRedirect(self):
106 response = self._Render('extensions')
107 self.assertEqual(('/extensions/index.html', False),
108 response.GetRedirect())
109
110 def testOtherRedirectsJsonRedirect(self):
111 response = self._Render('apps/webview_tag.html')
112 self.assertEqual(('/apps/tags/webview.html', False),
113 response.GetRedirect())
114
115
74 if __name__ == '__main__': 116 if __name__ == '__main__':
75 unittest.main() 117 unittest.main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/render_servlet.py ('k') | chrome/common/extensions/docs/server2/server_instance.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698