OLD | NEW |
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): |
(...skipping 19 matching lines...) Expand all Loading... |
30 self.permissions_json[0]['namespace'] = 'something' | 30 self.permissions_json[0]['namespace'] = 'something' |
31 self.permissions_json[0]['nocompile'] = True | 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): | |
41 del (self.permissions_json[0]['functions'][0]['parameters'][0]) | |
42 self.assertRaises(AssertionError, self.model.AddNamespace, | |
43 self.permissions_json[0], 'path/to/something.json') | |
44 | |
45 def testFunctionNoCompile(self): | 40 def testFunctionNoCompile(self): |
46 # tabs.json has 2 functions marked as nocompile (connect, sendRequest) | 41 # tabs.json has 2 functions marked as nocompile (connect, sendRequest) |
47 self.assertEquals(["captureVisibleTab", "create", "detectLanguage", | 42 self.assertEquals(["captureVisibleTab", "create", "detectLanguage", |
48 "executeScript", "get", "getAllInWindow", "getCurrent", | 43 "executeScript", "get", "getAllInWindow", "getCurrent", |
49 "getSelected", "highlight", "insertCSS", "move", "query", "reload", | 44 "getSelected", "highlight", "insertCSS", "move", "query", "reload", |
50 "remove", "update"], | 45 "remove", "update"], |
51 sorted(self.tabs.functions.keys()) | 46 sorted(self.tabs.functions.keys()) |
52 ) | 47 ) |
53 | 48 |
54 def testHasTypes(self): | 49 def testHasTypes(self): |
55 self.assertEquals(['Tab'], self.tabs.types.keys()) | 50 self.assertEquals(['Tab'], self.tabs.types.keys()) |
56 self.assertEquals(['Permissions'], self.permissions.types.keys()) | 51 self.assertEquals(['Permissions'], self.permissions.types.keys()) |
57 self.assertEquals(['Window'], self.windows.types.keys()) | 52 self.assertEquals(['Window'], self.windows.types.keys()) |
58 | 53 |
59 def testHasProperties(self): | 54 def testHasProperties(self): |
60 self.assertEquals(["active", "favIconUrl", "highlighted", "id", | 55 self.assertEquals(["active", "fav_icon_url", "highlighted", "id", |
61 "incognito", "index", "pinned", "selected", "status", "title", "url", | 56 "incognito", "index", "pinned", "selected", "status", "title", "url", |
62 "windowId"], | 57 "window_id"], |
63 sorted(self.tabs.types['Tab'].properties.keys())) | 58 sorted(self.tabs.types['Tab'].properties.keys())) |
64 | 59 |
65 def testProperties(self): | 60 def testProperties(self): |
66 string_prop = self.tabs.types['Tab'].properties['status'] | 61 string_prop = self.tabs.types['Tab'].properties['status'] |
67 self.assertEquals(model.PropertyType.STRING, string_prop.type_) | 62 self.assertEquals(model.PropertyType.STRING, string_prop.type_) |
68 integer_prop = self.tabs.types['Tab'].properties['id'] | 63 integer_prop = self.tabs.types['Tab'].properties['id'] |
69 self.assertEquals(model.PropertyType.INTEGER, integer_prop.type_) | 64 self.assertEquals(model.PropertyType.INTEGER, integer_prop.type_) |
70 array_prop = self.windows.types['Window'].properties['tabs'] | 65 array_prop = self.windows.types['Window'].properties['tabs'] |
71 self.assertEquals(model.PropertyType.ARRAY, array_prop.type_) | 66 self.assertEquals(model.PropertyType.ARRAY, array_prop.type_) |
72 self.assertEquals(model.PropertyType.REF, array_prop.item_type.type_) | 67 self.assertEquals(model.PropertyType.REF, array_prop.item_type.type_) |
73 self.assertEquals('Tab', array_prop.item_type.ref_type) | 68 self.assertEquals('Tab', array_prop.item_type.ref_type) |
74 object_prop = self.tabs.functions['query'].params[0] | 69 object_prop = self.tabs.functions['query'].params[0] |
75 self.assertEquals(model.PropertyType.OBJECT, object_prop.type_) | 70 self.assertEquals(model.PropertyType.OBJECT, object_prop.type_) |
76 self.assertEquals( | 71 self.assertEquals( |
77 ["active", "highlighted", "pinned", "status", "title", "url", | 72 ["active", "highlighted", "pinned", "status", "title", "url", |
78 "windowId", "windowType"], | 73 "window_id", "window_type"], |
79 sorted(object_prop.properties.keys())) | 74 sorted(object_prop.properties.keys())) |
80 | 75 |
81 def testChoices(self): | 76 def testChoices(self): |
82 self.assertEquals(model.PropertyType.CHOICES, | 77 self.assertEquals(model.PropertyType.CHOICES, |
83 self.tabs.functions['move'].params[0].type_) | 78 self.tabs.functions['move'].params[0].type_) |
84 | 79 |
85 def testPropertyNotImplemented(self): | 80 def testPropertyNotImplemented(self): |
86 (self.permissions_json[0]['types'][0] | 81 (self.permissions_json[0]['types'][0] |
87 ['properties']['permissions']['type']) = 'something' | 82 ['properties']['permissions']['type']) = 'something' |
88 self.assertRaises(NotImplementedError, self.model.AddNamespace, | 83 self.assertRaises(model.ParseException, self.model.AddNamespace, |
89 self.permissions_json[0], 'path/to/something.json') | 84 self.permissions_json[0], 'path/to/something.json') |
90 | 85 |
91 def testDescription(self): | 86 def testDescription(self): |
92 self.assertFalse( | 87 self.assertFalse( |
93 self.permissions.functions['contains'].params[0].description) | 88 self.permissions.functions['contains'].params[0].description) |
94 self.assertEquals('True if the extension has the specified permissions.', | 89 self.assertEquals('True if the extension has the specified permissions.', |
95 self.permissions.functions['contains'].callback.params[0].description) | 90 self.permissions.functions['contains'].callback.params[0].description) |
96 | 91 |
97 def testPropertyUnixName(self): | 92 def testPropertyUnixName(self): |
98 param = self.tabs.functions['move'].params[0] | 93 param = self.tabs.functions['move'].params[0] |
99 self.assertEquals('tab_ids', param.unix_name) | 94 self.assertEquals('tab_ids', param.unix_name) |
100 self.assertRaises(AttributeError, | 95 self.assertRaises(AttributeError, |
101 param.choices[model.PropertyType.INTEGER].GetUnixName) | 96 param.choices[model.PropertyType.INTEGER].GetUnixName) |
102 param.choices[model.PropertyType.INTEGER].unix_name = 'asdf' | 97 param.choices[model.PropertyType.INTEGER].unix_name = 'asdf' |
103 param.choices[model.PropertyType.INTEGER].unix_name = 'tab_ids_integer' | 98 param.choices[model.PropertyType.INTEGER].unix_name = 'tab_ids_integer' |
104 self.assertEquals('tab_ids_integer', | 99 self.assertEquals('tab_ids_integer', |
105 param.choices[model.PropertyType.INTEGER].unix_name) | 100 param.choices[model.PropertyType.INTEGER].unix_name) |
106 self.assertRaises(AttributeError, | 101 self.assertRaises(AttributeError, |
107 param.choices[model.PropertyType.INTEGER].SetUnixName, 'breakage') | 102 param.choices[model.PropertyType.INTEGER].SetUnixName, 'breakage') |
108 | 103 |
109 if __name__ == '__main__': | 104 if __name__ == '__main__': |
110 unittest.main() | 105 unittest.main() |
OLD | NEW |