2 # Copyright (c) 2012 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 from json_schema
import CachedLoad
10 class ModelTest(unittest
.TestCase
):
12 self
.model
= model
.Model()
13 self
.permissions_json
= CachedLoad('test/permissions.json')
14 self
.model
.AddNamespace(self
.permissions_json
[0],
15 'path/to/permissions.json')
16 self
.permissions
= self
.model
.namespaces
.get('permissions')
17 self
.windows_json
= CachedLoad('test/windows.json')
18 self
.model
.AddNamespace(self
.windows_json
[0],
19 'path/to/window.json')
20 self
.windows
= self
.model
.namespaces
.get('windows')
21 self
.tabs_json
= CachedLoad('test/tabs.json')
22 self
.model
.AddNamespace(self
.tabs_json
[0],
24 self
.tabs
= self
.model
.namespaces
.get('tabs')
26 def testNamespaces(self
):
27 self
.assertEquals(3, len(self
.model
.namespaces
))
28 self
.assertTrue(self
.permissions
)
30 def testHasFunctions(self
):
31 self
.assertEquals(["contains", "getAll", "remove", "request"],
32 sorted(self
.permissions
.functions
.keys()))
34 def testHasTypes(self
):
35 self
.assertEquals(['Tab'], self
.tabs
.types
.keys())
36 self
.assertEquals(['Permissions'], self
.permissions
.types
.keys())
37 self
.assertEquals(['Window'], self
.windows
.types
.keys())
39 def testHasProperties(self
):
40 self
.assertEquals(["active", "favIconUrl", "highlighted", "id",
41 "incognito", "index", "pinned", "selected", "status", "title", "url",
43 sorted(self
.tabs
.types
['Tab'].properties
.keys()))
45 def testProperties(self
):
46 string_prop
= self
.tabs
.types
['Tab'].properties
['status']
47 self
.assertEquals(model
.PropertyType
.STRING
,
48 string_prop
.type_
.property_type
)
49 integer_prop
= self
.tabs
.types
['Tab'].properties
['id']
50 self
.assertEquals(model
.PropertyType
.INTEGER
,
51 integer_prop
.type_
.property_type
)
52 array_prop
= self
.windows
.types
['Window'].properties
['tabs']
53 self
.assertEquals(model
.PropertyType
.ARRAY
,
54 array_prop
.type_
.property_type
)
55 self
.assertEquals(model
.PropertyType
.REF
,
56 array_prop
.type_
.item_type
.property_type
)
57 self
.assertEquals('tabs.Tab', array_prop
.type_
.item_type
.ref_type
)
58 object_prop
= self
.tabs
.functions
['query'].params
[0]
59 self
.assertEquals(model
.PropertyType
.OBJECT
,
60 object_prop
.type_
.property_type
)
62 ["active", "highlighted", "pinned", "status", "title", "url",
63 "windowId", "windowType"],
64 sorted(object_prop
.type_
.properties
.keys()))
66 def testChoices(self
):
67 self
.assertEquals(model
.PropertyType
.CHOICES
,
68 self
.tabs
.functions
['move'].params
[0].type_
.property_type
)
70 def testPropertyNotImplemented(self
):
71 (self
.permissions_json
[0]['types'][0]
72 ['properties']['permissions']['type']) = 'something'
73 self
.assertRaises(model
.ParseException
, self
.model
.AddNamespace
,
74 self
.permissions_json
[0], 'path/to/something.json')
76 def testDescription(self
):
78 self
.permissions
.functions
['contains'].params
[0].description
)
79 self
.assertEquals('True if the extension has the specified permissions.',
80 self
.permissions
.functions
['contains'].callback
.params
[0].description
)
82 def testPropertyUnixName(self
):
83 param
= self
.tabs
.functions
['move'].params
[0]
84 self
.assertEquals('tab_ids', param
.unix_name
)
86 def testUnixName(self
):
90 'fooBarBaz': 'foo_bar_baz',
91 'fooBARBaz': 'foo_bar_baz',
97 'foo.barBAZ': 'foo_bar_baz',
98 'foo_Bar_Baz_box': 'foo_bar_baz_box',
100 for name
in expectations
:
101 self
.assertEquals(expectations
[name
], model
.UnixName(name
));
103 if __name__
== '__main__':