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

Side by Side Diff: tools/json_schema_compiler/model_test.py

Issue 9309044: Supporting more APIs with json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: support for choices Created 8 years, 10 months 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import model 6 import model
7 import unittest 7 import unittest
8 8
9 class ModelTest(unittest.TestCase): 9 class ModelTest(unittest.TestCase):
10 def setUp(self): 10 def setUp(self):
11 self.model = model.Model() 11 self.model = model.Model()
12 self.permissions_json = json.loads(open('test/permissions.json').read()) 12 self.permissions_json = json.loads(open('test/permissions.json').read())
13 self.model.AddNamespace(self.permissions_json[0], 13 self.model.AddNamespace(self.permissions_json[0],
14 'path/to/permissions.json') 14 'path/to/permissions.json')
15 self.permissions = self.model.namespaces.get('permissions') 15 self.permissions = self.model.namespaces.get('permissions')
16 self.windows_json = json.loads(open('test/windows.json').read()) 16 self.windows_json = json.loads(open('test/windows.json').read())
17 self.model.AddNamespace(self.windows_json[0], 17 self.model.AddNamespace(self.windows_json[0],
18 'path/to/window.json') 18 'path/to/window.json')
19 self.windows = self.model.namespaces.get('windows') 19 self.windows = self.model.namespaces.get('windows')
20 self.tabs_json = json.loads(open('test/tabs.json').read()) 20 self.tabs_json = json.loads(open('test/tabs.json').read())
21 self.model.AddNamespace(self.tabs_json[0], 21 self.model.AddNamespace(self.tabs_json[0],
22 'path/to/tabs.json') 22 'path/to/tabs.json')
23 self.tabs = self.model.namespaces.get('tabs') 23 self.tabs = self.model.namespaces.get('tabs')
24 24
25 def testNamespaces(self): 25 def testNamespaces(self):
26 self.assertEquals(3, len(self.model.namespaces)) 26 self.assertEquals(3, len(self.model.namespaces))
27 self.assertTrue(self.permissions) 27 self.assertTrue(self.permissions)
28 28
29 def testNamespaceNocompile(self): 29 def testNamespaceNoCompile(self):
30 self.permissions_json[0]['namespace'] = 'something' 30 self.permissions_json[0]['namespace'] = 'something'
31 del self.permissions_json[0]['compile'] 31 self.permissions_json[0]['nocompile'] = True
32 self.model.AddNamespace(self.permissions_json[0], 32 self.model.AddNamespace(self.permissions_json[0],
33 'path/to/something.json') 33 'path/to/something.json')
34 self.assertEquals(3, len(self.model.namespaces)) 34 self.assertEquals(3, len(self.model.namespaces))
35 35
36 def testHasFunctions(self): 36 def testHasFunctions(self):
37 self.assertEquals(["contains", "getAll", "remove", "request"], 37 self.assertEquals(["contains", "getAll", "remove", "request"],
38 sorted(self.permissions.functions.keys())) 38 sorted(self.permissions.functions.keys()))
39 39
40 def testFunctionNoCallback(self): 40 def testFunctionNoCallback(self):
41 del (self.permissions_json[0]['functions'][0]['parameters'][0]) 41 del (self.permissions_json[0]['functions'][0]['parameters'][0])
42 self.assertRaises(AssertionError, self.model.AddNamespace, 42 self.assertRaises(AssertionError, self.model.AddNamespace,
43 self.permissions_json[0], 'path/to/something.json') 43 self.permissions_json[0], 'path/to/something.json')
44 44
45 def testFunctionNocompile(self): 45 def testFunctionNoCompile(self):
46 # tabs.json has 2 functions marked as nocompile (connect, sendRequest) 46 # tabs.json has 2 functions marked as nocompile (connect, sendRequest)
47 self.assertEquals(["captureVisibleTab", "create", "detectLanguage", 47 self.assertEquals(["captureVisibleTab", "create", "detectLanguage",
48 "executeScript", "get", "getAllInWindow", "getCurrent", 48 "executeScript", "get", "getAllInWindow", "getCurrent",
49 "getSelected", "highlight", "insertCSS", "move", "query", "reload", 49 "getSelected", "highlight", "insertCSS", "move", "query", "reload",
50 "remove", "update"], 50 "remove", "update"],
51 sorted(self.tabs.functions.keys()) 51 sorted(self.tabs.functions.keys())
52 ) 52 )
53 53
54 def testHasTypes(self): 54 def testHasTypes(self):
55 self.assertEquals(['Tab'], self.tabs.types.keys()) 55 self.assertEquals(['Tab'], self.tabs.types.keys())
(...skipping 14 matching lines...) Expand all
70 array_prop = self.windows.types['Window'].properties['tabs'] 70 array_prop = self.windows.types['Window'].properties['tabs']
71 self.assertEquals(model.PropertyType.ARRAY, array_prop.type_) 71 self.assertEquals(model.PropertyType.ARRAY, array_prop.type_)
72 self.assertEquals(model.PropertyType.REF, array_prop.item_type.type_) 72 self.assertEquals(model.PropertyType.REF, array_prop.item_type.type_)
73 self.assertEquals('Tab', array_prop.item_type.ref_type) 73 self.assertEquals('Tab', array_prop.item_type.ref_type)
74 object_prop = self.tabs.functions['query'].params[0] 74 object_prop = self.tabs.functions['query'].params[0]
75 self.assertEquals(model.PropertyType.OBJECT, object_prop.type_) 75 self.assertEquals(model.PropertyType.OBJECT, object_prop.type_)
76 self.assertEquals( 76 self.assertEquals(
77 ["active", "highlighted", "pinned", "status", "title", "url", 77 ["active", "highlighted", "pinned", "status", "title", "url",
78 "windowId", "windowType"], 78 "windowId", "windowType"],
79 sorted(object_prop.properties.keys())) 79 sorted(object_prop.properties.keys()))
80 # TODO(calamity): test choices 80
81 def testChoices(self):
82 self.assertEquals(model.PropertyType.CHOICES,
83 self.tabs.functions['move'].params[0].type_)
81 84
82 def testPropertyNotImplemented(self): 85 def testPropertyNotImplemented(self):
83 (self.permissions_json[0]['types'][0] 86 (self.permissions_json[0]['types'][0]
84 ['properties']['permissions']['type']) = 'something' 87 ['properties']['permissions']['type']) = 'something'
85 self.assertRaises(NotImplementedError, self.model.AddNamespace, 88 self.assertRaises(NotImplementedError, self.model.AddNamespace,
86 self.permissions_json[0], 'path/to/something.json') 89 self.permissions_json[0], 'path/to/something.json')
87 90
88 def testDescription(self): 91 def testDescription(self):
89 self.assertFalse( 92 self.assertFalse(
90 self.permissions.functions['contains'].params[0].description) 93 self.permissions.functions['contains'].params[0].description)
91 self.assertEquals('True if the extension has the specified permissions.', 94 self.assertEquals('True if the extension has the specified permissions.',
92 self.permissions.functions['contains'].callback.param.description) 95 self.permissions.functions['contains'].callback.params[0].description)
96
97 def testPropertyUnixName(self):
98 param = self.tabs.functions['move'].params[0]
99 self.assertEquals('tab_ids', param.unix_name)
100 self.assertRaises(AttributeError,
101 param.choices[model.PropertyType.INTEGER].GetUnixName)
102 param.choices[model.PropertyType.INTEGER].unix_name = 'asdf'
103 param.choices[model.PropertyType.INTEGER].unix_name = 'tab_ids_integer'
104 self.assertEquals('tab_ids_integer',
105 param.choices[model.PropertyType.INTEGER].unix_name)
106 self.assertRaises(AttributeError,
107 param.choices[model.PropertyType.INTEGER].SetUnixName, 'breakage')
93 108
94 if __name__ == '__main__': 109 if __name__ == '__main__':
95 unittest.main() 110 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698