| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 import json | 6 import json |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 from compiled_file_system import CompiledFileSystem | 9 from compiled_file_system import CompiledFileSystem |
| 10 from features_bundle import FeaturesBundle |
| 10 from object_store_creator import ObjectStoreCreator | 11 from object_store_creator import ObjectStoreCreator |
| 11 from permissions_data_source import PermissionsDataSource | 12 from permissions_data_source import PermissionsDataSource |
| 12 from test_file_system import TestFileSystem | 13 from test_file_system import TestFileSystem |
| 13 | 14 |
| 14 class FakeTemplateDataSource(object): | 15 class FakeTemplateDataSource(object): |
| 15 class Factory(): | 16 class Factory(): |
| 16 def Create(self, *args): | 17 def Create(self, *args): |
| 17 return FakeTemplateDataSource() | 18 return FakeTemplateDataSource() |
| 18 def get(self, key): | 19 def get(self, key): |
| 19 return 'partial ' + key | 20 return 'partial ' + key |
| 20 | 21 |
| 21 file_system = TestFileSystem({ | 22 file_system = TestFileSystem({ |
| 22 'permissions.json': json.dumps({ | 23 'permissions.json': json.dumps({ |
| 23 'host-permissions': { | 24 'host-permissions': { |
| 24 'name': 'match pattern', | 25 'name': 'match pattern', |
| 25 'anchor': 'custom-anchor', | 26 'anchor': 'custom-anchor', |
| 26 'platforms': ['app', 'extension'], | 27 'platforms': ['apps', 'extensions'], |
| 27 'partial': 'host_permissions.html', | 28 'partial': 'host_permissions.html', |
| 28 'literal_name': True | 29 'literal_name': True |
| 29 }, | 30 }, |
| 30 'activeTab': { | 31 'activeTab': { |
| 31 'partial': 'active_tab.html' | 32 'partial': 'active_tab.html' |
| 32 }, | 33 }, |
| 33 'alarms': { | 34 'alarms': { |
| 34 'partial': 'alarms.html' | 35 'partial': 'alarms.html' |
| 35 }, | 36 }, |
| 36 'audioCapture': { | 37 'audioCapture': { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 70 } |
| 70 }) | 71 }) |
| 71 }) | 72 }) |
| 72 | 73 |
| 73 class PermissionsDataSourceTest(unittest.TestCase): | 74 class PermissionsDataSourceTest(unittest.TestCase): |
| 74 def testCreatePermissionsDataSource(self): | 75 def testCreatePermissionsDataSource(self): |
| 75 expected_extensions = [ | 76 expected_extensions = [ |
| 76 { | 77 { |
| 77 'name': 'activeTab', | 78 'name': 'activeTab', |
| 78 'anchor': 'activeTab', | 79 'anchor': 'activeTab', |
| 79 'platforms': ['extension'], | 80 'platforms': ['extensions'], |
| 80 'description': 'partial active_tab.html' | 81 'description': 'partial active_tab.html' |
| 81 }, | 82 }, |
| 82 { | 83 { |
| 83 'name': 'alarms', | 84 'name': 'alarms', |
| 84 'anchor': 'alarms', | 85 'anchor': 'alarms', |
| 85 'platforms': ['app', 'extension'], | 86 'platforms': ['apps', 'extensions'], |
| 86 'description': 'partial alarms.html' | 87 'description': 'partial alarms.html' |
| 87 }, | 88 }, |
| 88 { | 89 { |
| 89 'name': 'background', | 90 'name': 'background', |
| 90 'anchor': 'background', | 91 'anchor': 'background', |
| 91 'platforms': ['extension'], | 92 'platforms': ['extensions'], |
| 92 'description': 'partial background.html' | 93 'description': 'partial background.html' |
| 93 }, | 94 }, |
| 94 { | 95 { |
| 95 'name': 'match pattern', | 96 'name': 'match pattern', |
| 96 'anchor': 'custom-anchor', | 97 'anchor': 'custom-anchor', |
| 97 'literal_name': True, | 98 'literal_name': True, |
| 98 'description': 'partial host_permissions.html', | 99 'description': 'partial host_permissions.html', |
| 99 'platforms': ['app', 'extension'] | 100 'platforms': ['apps', 'extensions'] |
| 100 } | 101 } |
| 101 ] | 102 ] |
| 102 | 103 |
| 103 expected_apps = [ | 104 expected_apps = [ |
| 104 { | 105 { |
| 105 'name': 'alarms', | 106 'name': 'alarms', |
| 106 'anchor': 'alarms', | 107 'anchor': 'alarms', |
| 107 'platforms': ['app', 'extension'], | 108 'platforms': ['apps', 'extensions'], |
| 108 'description': 'partial alarms.html' | 109 'description': 'partial alarms.html' |
| 109 }, | 110 }, |
| 110 { | 111 { |
| 111 'name': 'audioCapture', | 112 'name': 'audioCapture', |
| 112 'anchor': 'audioCapture', | 113 'anchor': 'audioCapture', |
| 113 'description': 'partial audio_capture.html', | 114 'description': 'partial audio_capture.html', |
| 114 'platforms': ['app'] | 115 'platforms': ['apps'] |
| 115 }, | 116 }, |
| 116 { | 117 { |
| 117 'anchor': 'cookies', | 118 'anchor': 'cookies', |
| 118 'name': 'cookies', | 119 'name': 'cookies', |
| 119 'description': 'partial permissions/generic_description', | 120 'description': 'partial permissions/generic_description', |
| 120 'platforms': ['app'] | 121 'platforms': ['apps'] |
| 121 }, | 122 }, |
| 122 { | 123 { |
| 123 'name': 'match pattern', | 124 'name': 'match pattern', |
| 124 'anchor': 'custom-anchor', | 125 'anchor': 'custom-anchor', |
| 125 'literal_name': True, | 126 'literal_name': True, |
| 126 'description': 'partial host_permissions.html', | 127 'description': 'partial host_permissions.html', |
| 127 'platforms': ['app', 'extension'] | 128 'platforms': ['apps', 'extensions'] |
| 128 } | 129 } |
| 129 ] | 130 ] |
| 130 | 131 |
| 131 permissions_data_source = PermissionsDataSource( | 132 permissions_data_source = PermissionsDataSource( |
| 132 CompiledFileSystem.Factory(file_system, ObjectStoreCreator.ForTest()), | 133 FeaturesBundle( |
| 133 file_system, | 134 file_system, |
| 134 '_api_features.json', | 135 CompiledFileSystem.Factory(file_system, ObjectStoreCreator.ForTest()), |
| 135 '_permission_features.json', | 136 { |
| 136 'permissions.json') | 137 'api': ('_api_features.json',), |
| 138 'permission': ('_permission_features.json', 'permissions.json'), |
| 139 })) |
| 137 | 140 |
| 138 permissions_data_source.SetTemplateDataSource( | 141 permissions_data_source.SetTemplateDataSource( |
| 139 FakeTemplateDataSource.Factory()) | 142 FakeTemplateDataSource.Factory()) |
| 140 | 143 |
| 141 self.assertEqual( | 144 self.assertEqual( |
| 142 expected_extensions, | 145 expected_extensions, |
| 143 permissions_data_source.get('declare_extensions')) | 146 permissions_data_source.get('declare_extensions')) |
| 144 self.assertEqual( | 147 self.assertEqual( |
| 145 expected_apps, | 148 expected_apps, |
| 146 permissions_data_source.get('declare_apps')) | 149 permissions_data_source.get('declare_apps')) |
| 147 | 150 |
| 148 if __name__ == '__main__': | 151 if __name__ == '__main__': |
| 149 unittest.main() | 152 unittest.main() |
| OLD | NEW |