| 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): |
| 11 def setUp(self): | 11 def setUp(self): |
| 12 self.model = model.Model() | 12 self.model = model.Model() |
| 13 self.permissions_json = CachedLoad('test/permissions.json') | 13 self.permissions_json = CachedLoad('test/permissions.json') |
| 14 self.model.AddNamespace(self.permissions_json[0], | 14 self.model.AddNamespace(self.permissions_json[0], |
| 15 'path/to/permissions.json') | 15 'path/to/permissions.json') |
| 16 self.permissions = self.model.namespaces.get('permissions') | 16 self.permissions = self.model.namespaces.get('permissions') |
| 17 self.windows_json = CachedLoad('test/windows.json') | 17 self.windows_json = CachedLoad('test/windows.json') |
| 18 self.model.AddNamespace(self.windows_json[0], | 18 self.model.AddNamespace(self.windows_json[0], |
| 19 'path/to/window.json') | 19 'path/to/window.json') |
| 20 self.windows = self.model.namespaces.get('windows') | 20 self.windows = self.model.namespaces.get('windows') |
| 21 self.tabs_json = CachedLoad('test/tabs.json') | 21 self.tabs_json = CachedLoad('test/tabs.json') |
| 22 self.model.AddNamespace(self.tabs_json[0], | 22 self.model.AddNamespace(self.tabs_json[0], |
| 23 'path/to/tabs.json') | 23 'path/to/tabs.json') |
| 24 self.tabs = self.model.namespaces.get('tabs') | 24 self.tabs = self.model.namespaces.get('tabs') |
| 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 testNamespaceNoCompile(self): | |
| 31 self.permissions_json[0]['namespace'] = 'something' | |
| 32 self.permissions_json[0]['nocompile'] = True | |
| 33 self.model.AddNamespace(self.permissions_json[0], | |
| 34 'path/to/something.json') | |
| 35 self.assertEquals(3, len(self.model.namespaces)) | |
| 36 | |
| 37 def testHasFunctions(self): | 30 def testHasFunctions(self): |
| 38 self.assertEquals(["contains", "getAll", "remove", "request"], | 31 self.assertEquals(["contains", "getAll", "remove", "request"], |
| 39 sorted(self.permissions.functions.keys())) | 32 sorted(self.permissions.functions.keys())) |
| 40 | 33 |
| 41 def testFunctionNoCompile(self): | |
| 42 # tabs.json has 2 functions marked as nocompile (connect, sendRequest) | |
| 43 self.assertEquals(["captureVisibleTab", "create", "detectLanguage", | |
| 44 "executeScript", "get", "getAllInWindow", "getCurrent", | |
| 45 "getSelected", "highlight", "insertCSS", "move", "query", "reload", | |
| 46 "remove", "update"], | |
| 47 sorted(self.tabs.functions.keys()) | |
| 48 ) | |
| 49 | |
| 50 def testHasTypes(self): | 34 def testHasTypes(self): |
| 51 self.assertEquals(['Tab'], self.tabs.types.keys()) | 35 self.assertEquals(['Tab'], self.tabs.types.keys()) |
| 52 self.assertEquals(['Permissions'], self.permissions.types.keys()) | 36 self.assertEquals(['Permissions'], self.permissions.types.keys()) |
| 53 self.assertEquals(['Window'], self.windows.types.keys()) | 37 self.assertEquals(['Window'], self.windows.types.keys()) |
| 54 | 38 |
| 55 def testHasProperties(self): | 39 def testHasProperties(self): |
| 56 self.assertEquals(["active", "fav_icon_url", "highlighted", "id", | 40 self.assertEquals(["active", "fav_icon_url", "highlighted", "id", |
| 57 "incognito", "index", "pinned", "selected", "status", "title", "url", | 41 "incognito", "index", "pinned", "selected", "status", "title", "url", |
| 58 "window_id"], | 42 "window_id"], |
| 59 sorted(self.tabs.types['Tab'].properties.keys())) | 43 sorted(self.tabs.types['Tab'].properties.keys())) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 'FOOBar': 'foo_bar', | 97 'FOOBar': 'foo_bar', |
| 114 'foo.bar': 'foo_bar', | 98 'foo.bar': 'foo_bar', |
| 115 'foo.BAR': 'foo_bar', | 99 'foo.BAR': 'foo_bar', |
| 116 'foo.barBAZ': 'foo_bar_baz' | 100 'foo.barBAZ': 'foo_bar_baz' |
| 117 } | 101 } |
| 118 for name in expectations: | 102 for name in expectations: |
| 119 self.assertEquals(expectations[name], model.UnixName(name)); | 103 self.assertEquals(expectations[name], model.UnixName(name)); |
| 120 | 104 |
| 121 if __name__ == '__main__': | 105 if __name__ == '__main__': |
| 122 unittest.main() | 106 unittest.main() |
| OLD | NEW |