| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 from json_schema import CachedLoad | 6 from json_schema import CachedLoad |
| 7 import model | 7 import model |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 class ModelTest(unittest.TestCase): | 10 class ModelTest(unittest.TestCase): |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 def testNamespaces(self): | 26 def testNamespaces(self): |
| 27 self.assertEquals(3, len(self.model.namespaces)) | 27 self.assertEquals(3, len(self.model.namespaces)) |
| 28 self.assertTrue(self.permissions) | 28 self.assertTrue(self.permissions) |
| 29 | 29 |
| 30 def testHasFunctions(self): | 30 def testHasFunctions(self): |
| 31 self.assertEquals(["contains", "getAll", "remove", "request"], | 31 self.assertEquals(["contains", "getAll", "remove", "request"], |
| 32 sorted(self.permissions.functions.keys())) | 32 sorted(self.permissions.functions.keys())) |
| 33 | 33 |
| 34 def testHasTypes(self): | 34 def testHasTypes(self): |
| 35 self.assertEquals(['tabs.Tab'], self.tabs.types.keys()) | 35 self.assertEquals(['Tab'], self.tabs.types.keys()) |
| 36 self.assertEquals(['permissions.Permissions'], | 36 self.assertEquals(['Permissions'], self.permissions.types.keys()) |
| 37 self.permissions.types.keys()) | 37 self.assertEquals(['Window'], self.windows.types.keys()) |
| 38 self.assertEquals(['windows.Window'], self.windows.types.keys()) | |
| 39 | 38 |
| 40 def testHasProperties(self): | 39 def testHasProperties(self): |
| 41 self.assertEquals(["active", "favIconUrl", "highlighted", "id", | 40 self.assertEquals(["active", "favIconUrl", "highlighted", "id", |
| 42 "incognito", "index", "pinned", "selected", "status", "title", "url", | 41 "incognito", "index", "pinned", "selected", "status", "title", "url", |
| 43 "windowId"], | 42 "windowId"], |
| 44 sorted(self.tabs.types['tabs.Tab'].properties.keys())) | 43 sorted(self.tabs.types['Tab'].properties.keys())) |
| 45 | 44 |
| 46 def testProperties(self): | 45 def testProperties(self): |
| 47 string_prop = self.tabs.types['tabs.Tab'].properties['status'] | 46 string_prop = self.tabs.types['Tab'].properties['status'] |
| 48 self.assertEquals(model.PropertyType.STRING, string_prop.type_) | 47 self.assertEquals(model.PropertyType.STRING, |
| 49 integer_prop = self.tabs.types['tabs.Tab'].properties['id'] | 48 string_prop.type_.property_type) |
| 50 self.assertEquals(model.PropertyType.INTEGER, integer_prop.type_) | 49 integer_prop = self.tabs.types['Tab'].properties['id'] |
| 51 array_prop = self.windows.types['windows.Window'].properties['tabs'] | 50 self.assertEquals(model.PropertyType.INTEGER, |
| 52 self.assertEquals(model.PropertyType.ARRAY, array_prop.type_) | 51 integer_prop.type_.property_type) |
| 53 self.assertEquals(model.PropertyType.REF, array_prop.item_type.type_) | 52 array_prop = self.windows.types['Window'].properties['tabs'] |
| 54 self.assertEquals('tabs.Tab', array_prop.item_type.ref_type) | 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) |
| 55 object_prop = self.tabs.functions['query'].params[0] | 58 object_prop = self.tabs.functions['query'].params[0] |
| 56 self.assertEquals(model.PropertyType.OBJECT, object_prop.type_) | 59 self.assertEquals(model.PropertyType.OBJECT, |
| 60 object_prop.type_.property_type) |
| 57 self.assertEquals( | 61 self.assertEquals( |
| 58 ["active", "highlighted", "pinned", "status", "title", "url", | 62 ["active", "highlighted", "pinned", "status", "title", "url", |
| 59 "windowId", "windowType"], | 63 "windowId", "windowType"], |
| 60 sorted(object_prop.properties.keys())) | 64 sorted(object_prop.type_.properties.keys())) |
| 61 | 65 |
| 62 def testChoices(self): | 66 def testChoices(self): |
| 63 self.assertEquals(model.PropertyType.CHOICES, | 67 self.assertEquals(model.PropertyType.CHOICES, |
| 64 self.tabs.functions['move'].params[0].type_) | 68 self.tabs.functions['move'].params[0].type_.property_type) |
| 65 | 69 |
| 66 def testPropertyNotImplemented(self): | 70 def testPropertyNotImplemented(self): |
| 67 (self.permissions_json[0]['types'][0] | 71 (self.permissions_json[0]['types'][0] |
| 68 ['properties']['permissions']['type']) = 'something' | 72 ['properties']['permissions']['type']) = 'something' |
| 69 self.assertRaises(NotImplementedError, self.model.AddNamespace, | 73 self.assertRaises(model.ParseException, self.model.AddNamespace, |
| 70 self.permissions_json[0], 'path/to/something.json') | 74 self.permissions_json[0], 'path/to/something.json') |
| 71 | 75 |
| 72 def testDescription(self): | 76 def testDescription(self): |
| 73 self.assertFalse( | 77 self.assertFalse( |
| 74 self.permissions.functions['contains'].params[0].description) | 78 self.permissions.functions['contains'].params[0].description) |
| 75 self.assertEquals('True if the extension has the specified permissions.', | 79 self.assertEquals('True if the extension has the specified permissions.', |
| 76 self.permissions.functions['contains'].callback.params[0].description) | 80 self.permissions.functions['contains'].callback.params[0].description) |
| 77 | 81 |
| 78 def testPropertyUnixName(self): | 82 def testPropertyUnixName(self): |
| 79 param = self.tabs.functions['move'].params[0] | 83 param = self.tabs.functions['move'].params[0] |
| 80 self.assertEquals('tab_ids', param.unix_name) | 84 self.assertEquals('tab_ids', param.unix_name) |
| 81 param.choices[model.PropertyType.INTEGER].unix_name = 'asdf' | |
| 82 param.choices[model.PropertyType.INTEGER].unix_name = 'tab_ids_integer' | |
| 83 self.assertEquals('tab_ids_integer', | |
| 84 param.choices[model.PropertyType.INTEGER].unix_name) | |
| 85 self.assertRaises(AttributeError, | |
| 86 param.choices[model.PropertyType.INTEGER].SetUnixName, 'breakage') | |
| 87 | 85 |
| 88 def testUnixName(self): | 86 def testUnixName(self): |
| 89 expectations = { | 87 expectations = { |
| 90 'foo': 'foo', | 88 'foo': 'foo', |
| 91 'fooBar': 'foo_bar', | 89 'fooBar': 'foo_bar', |
| 92 'fooBarBaz': 'foo_bar_baz', | 90 'fooBarBaz': 'foo_bar_baz', |
| 93 'fooBARBaz': 'foo_bar_baz', | 91 'fooBARBaz': 'foo_bar_baz', |
| 94 'fooBAR': 'foo_bar', | 92 'fooBAR': 'foo_bar', |
| 95 'FOO': 'foo', | 93 'FOO': 'foo', |
| 96 'FOOBar': 'foo_bar', | 94 'FOOBar': 'foo_bar', |
| 97 'foo.bar': 'foo_bar', | 95 'foo.bar': 'foo_bar', |
| 98 'foo.BAR': 'foo_bar', | 96 'foo.BAR': 'foo_bar', |
| 99 'foo.barBAZ': 'foo_bar_baz' | 97 'foo.barBAZ': 'foo_bar_baz' |
| 100 } | 98 } |
| 101 for name in expectations: | 99 for name in expectations: |
| 102 self.assertEquals(expectations[name], model.UnixName(name)); | 100 self.assertEquals(expectations[name], model.UnixName(name)); |
| 103 | 101 |
| 104 if __name__ == '__main__': | 102 if __name__ == '__main__': |
| 105 unittest.main() | 103 unittest.main() |
| OLD | NEW |