def testCreatePermissionsDataSource(self): expected_extensions = [ { 'anchor': 'custom-anchor', 'description': 'host permissions', 'extension_types': ['platform_app', 'extension'], 'literal_name': True, 'name': 'match pattern', 'channel': 'stable' }, { 'anchor': 'activeTab', 'description': 'active tab', 'extension_types': ['extension'], 'name': 'activeTab', 'channel': 'stable' }, { 'anchor': 'alarms', 'description': 'generic description', 'extension_types': ['platform_app', 'extension'], 'name': 'alarms', 'channel': 'stable' }, ] expected_apps = [ { 'anchor': 'custom-anchor', 'description': 'host permissions', 'extension_types': ['platform_app', 'extension'], 'literal_name': True, 'name': 'match pattern', 'channel': 'stable' }, { 'anchor': 'alarms', 'description': 'generic description', 'extension_types': ['platform_app', 'extension'], 'name': 'alarms', 'channel': 'stable' }, { 'anchor': 'cookies', 'description': 'generic description', 'extension_types': ['platform_app'], 'name': 'cookies', 'channel': 'stable' }, ] test_file_system = TestFileSystem({ 'api': { '_api_features.json': json.dumps(_API_FEATURES), '_manifest_features.json': '{}', '_permission_features.json': json.dumps(_PERMISSION_FEATURES), }, 'docs': { 'templates': { 'json': { 'manifest.json': '{}', 'permissions.json': json.dumps(_PERMISSIONS_JSON), }, 'private': { 'permissions': _PERMISSIONS_PARTIALS }, } } }, relative_to=CHROME_EXTENSIONS) permissions_data_source = PermissionsDataSource( ServerInstance.ForTest(test_file_system), None) actual_extensions = permissions_data_source.get('declare_extensions') actual_apps = permissions_data_source.get('declare_apps') # Normalise all test data. # - Sort keys. Since the tests don't use OrderedDicts we can't make # assertions about the order, which is unfortunate. Oh well. # - Render all of the Handlerbar instances so that we can use ==. # Motemplates don't implement __eq__, but they probably should. for lst in (actual_apps, actual_extensions, expected_apps, expected_extensions): lst.sort(key=itemgetter('name')) for mapping in lst: for key, value in mapping.iteritems(): if isinstance(value, Motemplate): mapping[key] = value.Render().text self.assertEqual(expected_extensions, actual_extensions) self.assertEqual(expected_apps, actual_apps)
def testCreatePermissionsDataSource(self): expected_extensions = [ { 'anchor': 'custom-anchor', 'description': 'host permissions', 'literal_name': True, 'name': 'match pattern', 'platforms': ['apps', 'extensions'] }, { 'anchor': 'activeTab', 'description': 'active tab', 'name': 'activeTab', 'platforms': ['extensions'], }, { 'anchor': 'alarms', 'description': 'generic description', 'name': 'alarms', 'platforms': ['apps', 'extensions'], }, ] expected_apps = [ { 'anchor': 'custom-anchor', 'description': 'host permissions', 'literal_name': True, 'name': 'match pattern', 'platforms': ['apps', 'extensions'], }, { 'anchor': 'alarms', 'description': 'generic description', 'name': 'alarms', 'platforms': ['apps', 'extensions'], }, { 'anchor': 'cookies', 'description': 'generic description', 'name': 'cookies', 'platforms': ['apps'], }, ] test_file_system = TestFileSystem({ 'api': { '_api_features.json': json.dumps(_API_FEATURES), '_manifest_features.json': '{}', '_permission_features.json': json.dumps(_PERMISSION_FEATURES), }, 'docs': { 'templates': { 'json': { 'manifest.json': '{}', 'permissions.json': json.dumps(_PERMISSIONS_JSON), }, 'private': { 'permissions': _PERMISSIONS_PARTIALS }, } } }) permissions_data_source = PermissionsDataSource( ServerInstance.ForTest(test_file_system), None) actual_extensions = permissions_data_source.get('declare_extensions') actual_apps = permissions_data_source.get('declare_apps') # Normalise all test data. # - Sort keys. Since the tests don't use OrderedDicts we can't make # assertions about the order, which is unfortunate. Oh well. # - Render all of the Handlerbar instances so that we can use ==. # Handlebars don't implement __eq__, but they probably should. for lst in (actual_apps, actual_extensions, expected_apps, expected_extensions): lst.sort(key=itemgetter('name')) for mapping in lst: for key, value in mapping.iteritems(): if isinstance(value, Handlebar): mapping[key] = value.Render().text self.assertEqual(expected_extensions, actual_extensions) self.assertEqual(expected_apps, actual_apps)
def testCreatePermissionsDataSource(self): expected_extensions = [ { 'name': 'activeTab', 'anchor': 'activeTab', 'platforms': ['extension'], 'description': 'partial active_tab.html' }, { 'name': 'alarms', 'anchor': 'alarms', 'platforms': ['app', 'extension'], 'description': 'partial alarms.html' }, { 'name': 'background', 'anchor': 'background', 'platforms': ['extension'], 'description': 'partial background.html' }, { 'name': 'match pattern', 'anchor': 'custom-anchor', 'literal_name': True, 'description': 'partial host_permissions.html', 'platforms': ['app', 'extension'] } ] expected_apps = [ { 'name': 'alarms', 'anchor': 'alarms', 'platforms': ['app', 'extension'], 'description': 'partial alarms.html' }, { 'name': 'audioCapture', 'anchor': 'audioCapture', 'description': 'partial audio_capture.html', 'platforms': ['app'] }, { 'anchor': 'cookies', 'name': 'cookies', 'description': 'partial permissions/generic_description', 'platforms': ['app'] }, { 'name': 'match pattern', 'anchor': 'custom-anchor', 'literal_name': True, 'description': 'partial host_permissions.html', 'platforms': ['app', 'extension'] } ] permissions_data_source = PermissionsDataSource( CompiledFileSystem.Factory(file_system, ObjectStoreCreator.ForTest()), file_system, '_api_features.json', '_permission_features.json', 'permissions.json') permissions_data_source.SetTemplateDataSource( FakeTemplateDataSource.Factory()) self.assertEqual( expected_extensions, permissions_data_source.get('declare_extensions')) self.assertEqual( expected_apps, permissions_data_source.get('declare_apps'))
def testCreatePermissionsDataSource(self): expected_extensions = [ { "anchor": "custom-anchor", "description": "host permissions", "extension_types": ["platform_app", "extension"], "literal_name": True, "name": "match pattern", "channel": "stable", }, { "anchor": "activeTab", "description": "active tab", "extension_types": ["extension"], "name": "activeTab", "channel": "stable", }, { "anchor": "alarms", "description": "generic description", "extension_types": ["platform_app", "extension"], "name": "alarms", "channel": "stable", }, ] expected_apps = [ { "anchor": "custom-anchor", "description": "host permissions", "extension_types": ["platform_app", "extension"], "literal_name": True, "name": "match pattern", "channel": "stable", }, { "anchor": "alarms", "description": "generic description", "extension_types": ["platform_app", "extension"], "name": "alarms", "channel": "stable", }, { "anchor": "cookies", "description": "generic description", "extension_types": ["platform_app"], "name": "cookies", "channel": "stable", }, ] test_file_system = TestFileSystem( { "api": { "_api_features.json": json.dumps(_API_FEATURES), "_manifest_features.json": "{}", "_permission_features.json": json.dumps(_PERMISSION_FEATURES), }, "docs": { "templates": { "json": {"manifest.json": "{}", "permissions.json": json.dumps(_PERMISSIONS_JSON)}, "private": {"permissions": _PERMISSIONS_PARTIALS}, } }, }, relative_to=CHROME_EXTENSIONS, ) permissions_data_source = PermissionsDataSource(ServerInstance.ForTest(test_file_system), None) actual_extensions = permissions_data_source.get("declare_extensions") actual_apps = permissions_data_source.get("declare_apps") # Normalise all test data. # - Sort keys. Since the tests don't use OrderedDicts we can't make # assertions about the order, which is unfortunate. Oh well. # - Render all of the Handlerbar instances so that we can use ==. # Handlebars don't implement __eq__, but they probably should. for lst in (actual_apps, actual_extensions, expected_apps, expected_extensions): lst.sort(key=itemgetter("name")) for mapping in lst: for key, value in mapping.iteritems(): if isinstance(value, Handlebar): mapping[key] = value.Render().text self.assertEqual(expected_extensions, actual_extensions) self.assertEqual(expected_apps, actual_apps)