1 #!/usr/bin/env python 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 4 # found in the LICENSE file. 5 import unittest 6 7 from api_categorizer import APICategorizer 8 from compiled_file_system import CompiledFileSystem 9 from extensions_paths import CHROME_EXTENSIONS 10 from object_store_creator import ObjectStoreCreator 11 from test_file_system import TestFileSystem 12 13 14 def _ToTestData(obj): 15 '''Transforms |obj| into test data by turning a list of files into an object 16 mapping that file to its contents (derived from its name). 17 ''' 18 return dict((name, name) for name in obj) 19 20 21 _TEST_DATA = { 22 'api': { 23 '_api_features.json': '{}', 24 '_manifest_features.json': '{}', 25 '_permission_features.json': '{}', 26 }, 27 'docs': { 28 'templates': { 29 'json': { 30 'api_availabilities.json': '{}', 31 'manifest.json': '{}', 32 'permissions.json': '{}', 33 }, 34 'public': { 35 'apps': _ToTestData([ 36 'alarms.html', 37 'app_window.html', 38 'experimental_bluetooth.html', 39 'experimental_power.html', 40 'storage.html', 41 'sockets_udp.html' 42 ]), 43 'extensions': _ToTestData([ 44 'alarms.html', 45 'browserAction.html', 46 'experimental_history.html', 47 'experimental_power.html', 48 'infobars.html', 49 'storage.html', 50 'sockets_udp.html' 51 ]), 52 }, 53 }, 54 } 55 } 56 57 58 class APICategorizerTest(unittest.TestCase): 59 def setUp(self): 60 self._test_file_system = TestFileSystem( 61 _TEST_DATA, relative_to=CHROME_EXTENSIONS) 62 self._compiled_file_system = CompiledFileSystem.Factory( 63 ObjectStoreCreator.ForTest()) 64 65 def testGetAPICategory(self): 66 def assertGetEqual(expected, category, only_on=None): 67 for platform in ('apps', 'extensions'): 68 get_category = APICategorizer( 69 self._test_file_system, 70 self._compiled_file_system, 71 platform if only_on is None else only_on).GetCategory(category) 72 self.assertEqual(expected, get_category) 73 74 assertGetEqual('chrome', 'alarms') 75 assertGetEqual('private', 'musicManagerPrivate') 76 assertGetEqual('private', 'notDocumentedApi') 77 assertGetEqual('experimental', 'experimental.bluetooth', only_on='apps') 78 assertGetEqual('experimental', 'experimental.history', only_on='extensions') 79 80 81 if __name__ == '__main__': 82 unittest.main() 83