Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / instance_servlet_test.py
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import unittest
7
8 from github_file_system_provider import GithubFileSystemProvider
9 from instance_servlet import InstanceServlet
10 from servlet import Request
11 from fail_on_access_file_system import FailOnAccessFileSystem
12 from test_branch_utility import TestBranchUtility
13 from test_util import DisableLogging
14
15 # NOTE(kalman): The ObjectStore created by the InstanceServlet is backed onto
16 # our fake AppEngine memcache/datastore, so the tests aren't isolated.
17 class _TestDelegate(InstanceServlet.Delegate):
18   def __init__(self, file_system_type):
19     self._file_system_type = file_system_type
20
21   def CreateBranchUtility(self, object_store_creator):
22     return TestBranchUtility.CreateWithCannedData()
23
24   def CreateGithubFileSystemProvider(self, object_store_creator):
25     return GithubFileSystemProvider.ForEmpty()
26
27 class InstanceServletTest(unittest.TestCase):
28   '''Tests that if the file systems underlying the docserver's data fail,
29   the instance servlet still returns 404s or 301s with a best-effort.
30   It should never return a 500 (i.e. crash).
31   '''
32
33   @DisableLogging('warning')
34   def testHostFileSystemNotAccessed(self):
35     delegate = _TestDelegate(FailOnAccessFileSystem)
36     constructor = InstanceServlet.GetConstructor(delegate_for_test=delegate)
37     def test_path(path, status=404):
38       response = constructor(Request.ForTest(path)).Get()
39       self.assertEqual(status, response.status)
40     test_path('extensions/storage.html')
41     test_path('apps/storage.html')
42     test_path('extensions/examples/foo.zip')
43     test_path('extensions/examples/foo.html')
44     test_path('static/foo.css')
45     test_path('beta/extensions/storage.html', status=301)
46     test_path('beta/apps/storage.html', status=301)
47     test_path('beta/extensions/examples/foo.zip', status=301)
48     test_path('beta/extensions/examples/foo.html', status=301)
49     test_path('beta/static/foo.css', status=301)
50
51 if __name__ == '__main__':
52   unittest.main()