cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / schema_processor_test.py
blob9be4172945f649859414b23469c9797476b0438d
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.
6 import unittest
7 from copy import deepcopy
9 from schema_processor import SchemaProcessor
10 from future import Future
11 from object_store_creator import ObjectStoreCreator
12 from host_file_system_provider import HostFileSystemProvider
13 from compiled_file_system import CompiledFileSystem
15 class _FakeReferenceResolver():
16 def GetRefModel(self, ref, api_list):
17 return None, None
19 class _FakeAPIModels():
20 def GetNames(self):
21 return []
23 class _FakeFeaturesBundle():
24 def GetAPIFeatures(self):
25 return Future(value={})
27 class SchemaUtilTest(unittest.TestCase):
28 def testRemoveNoDocs(self):
29 expected_nodoc = [
31 'name': 'B',
32 'list': [
34 'name': 'B2'
39 'name': 'D',
40 'nodoc': False
43 'name': 'E',
44 'items1': [
46 'name': 'E1',
47 'items': [
49 'name': 'E1.3'
54 'name': 'E2'
60 nodoc_data = [
62 'name': 'A',
63 'nodoc': True
66 'name': 'B',
67 'list': [
69 'name': 'B1',
70 'nodoc': True
73 'name': 'B2'
76 'name': 'B3',
77 'nodoc': True
82 'name': 'C',
83 'nodoc': True
86 'name': 'D',
87 'nodoc': False
90 'name': 'E',
91 'dict': {
92 'name': 'Ed',
93 'nodoc': True
95 'items1': [
97 'name': 'E1',
98 'items': [
100 'name': 'E1.1',
101 'nodoc': True
104 'name': 'E1.2',
105 'nodoc': True
108 'name': 'E1.3'
113 'name': 'E2'
116 'name': 'E3',
117 'nodoc': True
123 object_store_creator = ObjectStoreCreator(start_empty=False)
124 host_file_system_provider = HostFileSystemProvider(object_store_creator)
125 schema_processor = SchemaProcessor(_FakeReferenceResolver(),
126 _FakeAPIModels(),
127 _FakeFeaturesBundle(),
128 CompiledFileSystem.Factory(
129 object_store_creator),
130 host_file_system_provider.GetMaster(),
131 True)
132 schema_processor._RemoveNoDocs(nodoc_data)
133 self.assertEquals(expected_nodoc, nodoc_data)
135 def testInlineDocs(self):
136 schema = {
137 'namespace': 'storage',
138 'properties': {
139 'key2': {
140 'description': 'second key',
141 '$ref': 'Key'
143 'key1': {
144 'description': 'first key',
145 '$ref': 'Key'
148 'types': [
150 'inline_doc': True,
151 'type': 'string',
152 'id': 'Key', # Should be inlined into both properties and be removed
153 # from types.
154 'description': 'This is a key.', # This description should disappear.
155 'marker': True # This should appear three times in the output.
158 'items': {
159 '$ref': 'Key'
161 'type': 'array',
162 'id': 'KeyList',
163 'description': 'A list of keys'
168 expected_schema = {
169 'namespace': 'storage',
170 'properties': {
171 'key2': {
172 'marker': True,
173 'type': 'string',
174 'description': 'second key'
176 'key1': {
177 'marker': True,
178 'type': 'string',
179 'description': 'first key'
182 'types': [
184 'items': {
185 'marker': True,
186 'type': 'string'
188 'type': 'array',
189 'id': 'KeyList',
190 'description': 'A list of keys'
195 object_store_creator = ObjectStoreCreator(start_empty=False)
196 host_file_system_provider = HostFileSystemProvider(object_store_creator)
197 schema_processor = SchemaProcessor(_FakeReferenceResolver(),
198 _FakeAPIModels(),
199 _FakeFeaturesBundle(),
200 CompiledFileSystem.Factory(
201 object_store_creator),
202 host_file_system_provider.GetMaster(),
203 False)
204 inlined_schema = deepcopy(schema)
205 schema_processor._InlineDocs(inlined_schema)
206 self.assertEqual(expected_schema, inlined_schema)
208 def testDetectInline(self):
209 schema = {
210 'types': [
212 'id': 'Key',
213 'items': {
214 '$ref': 'Value'
218 'id': 'Value',
219 'marker': True
224 expected_schema = {
225 'types': [
227 'id': 'Key',
228 'items': {
229 'marker': True,
235 object_store_creator = ObjectStoreCreator(start_empty=False)
236 host_file_system_provider = HostFileSystemProvider(object_store_creator)
237 schema_processor = SchemaProcessor(_FakeReferenceResolver(),
238 _FakeAPIModels(),
239 _FakeFeaturesBundle(),
240 CompiledFileSystem.Factory(
241 object_store_creator),
242 host_file_system_provider.GetMaster(),
243 False)
244 schema_processor._DetectInlineableTypes(schema)
245 schema_processor._InlineDocs(schema)
246 self.assertEqual(expected_schema, schema)
249 if __name__ == '__main__':
250 unittest.main()