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

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

Issue 54603010: Docserver: Implement the content providers infrastructure, where a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
(Empty)
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 json
7 import unittest
8
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
14
15
16 _HOST = 'https://developer.chrome.com'
17
18
19 _CONTENT_PROVIDERS = {
20 'apples': {
21 'default': True,
22 'chroot': 'apples',
23 'serveFrom': 'apples-dir',
24 'type': 'host',
25 },
26 'bananas': {
27 'serveFrom': '',
28 'type': 'host',
29 },
30 'tomatoes': {
31 'chroot': 'tomatoes/are/a',
32 'serveFrom': 'tomatoes-dir/are/a',
33 'type': 'host',
34 },
35 }
36
37
38 _FILE_SYSTEM_DATA = {
39 'docs': {
40 'templates': {
41 'json': {
42 'content_providers.json': json.dumps(_CONTENT_PROVIDERS),
43 },
44 },
45 },
46 'apples': {
47 'gala.txt': 'gala apples',
48 'green': {
49 'granny smith.txt': 'granny smith apples',
50 },
51 },
52 'tomatoes': {
53 'are': {
54 'a': {
55 'vegetable.txt': 'no they aren\'t',
56 'fruit': {
57 'cherry.txt': 'cherry tomatoes',
58 },
59 },
60 },
61 },
62 }
63
64
65 class ContentProvidersTest(unittest.TestCase):
66 def setUp(self):
67 self._content_providers = ContentProviders(
68 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()),
69 TestFileSystem(_FILE_SYSTEM_DATA))
70
71 def testDefaultProvider(self):
72 provider = self._content_providers.GetDefault()
73 self.assertEqual(
74 'gala apples',
75 provider.GetContentInfo(_HOST, 'gala.txt').Get().content)
76 self.assertEqual(
77 'granny smith apples',
78 provider.GetContentInfo(_HOST, 'green/granny smith.txt').Get().content)
79
80 def testSimpleRootPath(self):
81 provider = self._content_providers.GetByName('apples')
82 self.assertEqual(
83 'gala apples',
84 provider.GetContentInfo(_HOST, 'gala.txt').Get().content)
85 self.assertEqual(
86 'granny smith apples',
87 provider.GetContentInfo(_HOST, 'green/granny smith.txt').Get().content)
88
89 def testComplexRootPath(self):
90 provider = self._content_providers.GetByName('tomatoes')
91 self.assertEqual(
92 'no they aren\'t',
93 provider.GetContentInfo(_HOST, 'vegetable.txt').Get().content)
94 self.assertEqual(
95 'cherry tomatoes',
96 provider.GetContentInfo(_HOST, 'fruit/cherry.txt').Get().content)
97
98 def testEmptyRootPath(self):
99 provider = self._content_providers.GetByName('bananas')
100 self.assertEqual(
101 'gala apples',
102 provider.GetContentInfo(_HOST, 'apples/gala.txt').Get().content)
103
104 def testSimpleServlet(self):
105 provider, path = self._content_providers.GetByServlet('apples-dir')
106 self.assertEqual('apples', provider.name)
107 self.assertEqual('', path)
108 provider, path = self._content_providers.GetByServlet(
109 'apples-dir/are/forever')
110 self.assertEqual('apples', provider.name)
111 self.assertEqual('are/forever', path)
112
113 def testComplexServlet(self):
114 provider, path = self._content_providers.GetByServlet('tomatoes-dir/are/a')
115 self.assertEqual('tomatoes', provider.name)
116 self.assertEqual('', path)
117 provider, path = self._content_providers.GetByServlet(
118 'tomatoes-dir/are/a/fruit/they/are')
119 self.assertEqual('tomatoes', provider.name)
120 self.assertEqual('fruit/they/are', path)
121
122 def testEmptyStringServlet(self):
123 provider, path = self._content_providers.GetByServlet('tomatoes-dir/are')
124 self.assertEqual('bananas', provider.name)
125 self.assertEqual('tomatoes-dir/are', path)
126 provider, path = self._content_providers.GetByServlet('')
127 self.assertEqual('bananas', provider.name)
128 self.assertEqual('', path)
129
130 @DisableLogging('error')
131 def testProviderNotFound(self):
132 self.assertEqual(None, self._content_providers.GetByName('cabbages'))
133
134
135 if __name__ == '__main__':
136 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698