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.
9 from compiled_file_system import CompiledFileSystem
10 from content_providers import ContentProviders
11 from object_store_creator import ObjectStoreCreator
12 from test_file_system import TestFileSystem
13 from test_util import DisableLogging
16 _HOST = 'https://developer.chrome.com'
19 _CONTENT_PROVIDERS = {
24 'serveFrom': 'apples-dir',
33 'serveFrom': 'tomatoes-dir/are/a',
35 'dir': 'tomatoes/are/a'
45 'content_providers.json': json.dumps(_CONTENT_PROVIDERS),
50 'gala.txt': 'gala apples',
52 'granny smith.txt': 'granny smith apples',
58 'vegetable.txt': 'no they aren\'t',
60 'cherry.txt': 'cherry tomatoes',
68 class ContentProvidersTest(unittest.TestCase):
70 self._content_providers = ContentProviders(
71 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()),
72 TestFileSystem(_FILE_SYSTEM_DATA))
74 def testSimpleRootPath(self):
75 provider = self._content_providers.GetByName('apples')
78 provider.GetContentAndType(_HOST, 'gala.txt').Get().content)
80 'granny smith apples',
81 provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get()
84 def testComplexRootPath(self):
85 provider = self._content_providers.GetByName('tomatoes')
88 provider.GetContentAndType(_HOST, 'vegetable.txt').Get().content)
91 provider.GetContentAndType(_HOST, 'fruit/cherry.txt').Get().content)
93 def testEmptyRootPath(self):
94 provider = self._content_providers.GetByName('bananas')
97 provider.GetContentAndType(_HOST, 'apples/gala.txt').Get().content)
99 def testSimpleServlet(self):
100 provider, path = self._content_providers.GetByServeFrom('apples-dir')
101 self.assertEqual('apples', provider.name)
102 self.assertEqual('', path)
103 provider, path = self._content_providers.GetByServeFrom(
104 'apples-dir/are/forever')
105 self.assertEqual('apples', provider.name)
106 self.assertEqual('are/forever', path)
108 def testComplexServlet(self):
109 provider, path = self._content_providers.GetByServeFrom(
110 'tomatoes-dir/are/a')
111 self.assertEqual('tomatoes', provider.name)
112 self.assertEqual('', path)
113 provider, path = self._content_providers.GetByServeFrom(
114 'tomatoes-dir/are/a/fruit/they/are')
115 self.assertEqual('tomatoes', provider.name)
116 self.assertEqual('fruit/they/are', path)
118 def testEmptyStringServlet(self):
119 provider, path = self._content_providers.GetByServeFrom('tomatoes-dir/are')
120 self.assertEqual('bananas', provider.name)
121 self.assertEqual('tomatoes-dir/are', path)
122 provider, path = self._content_providers.GetByServeFrom('')
123 self.assertEqual('bananas', provider.name)
124 self.assertEqual('', path)
126 @DisableLogging('error')
127 def testProviderNotFound(self):
128 self.assertEqual(None, self._content_providers.GetByName('cabbages'))
131 if __name__ == '__main__':