def setUp(self): object_store_creator = ObjectStoreCreator.ForTest() compiled_fs_factory = CompiledFileSystem.Factory(object_store_creator) self._mock_file_system = MockFileSystem(TestFileSystem(_TEST_DATA)) features_bundle = FeaturesBundle(self._mock_file_system, compiled_fs_factory, object_store_creator) self._api_models = APIModels(features_bundle, compiled_fs_factory, self._mock_file_system)
def setUp(self): object_store_creator = ObjectStoreCreator.ForTest() compiled_fs_factory = CompiledFileSystem.Factory(object_store_creator) self._mock_file_system = MockFileSystem( TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS)) features_bundle = FeaturesBundle(self._mock_file_system, compiled_fs_factory, object_store_creator, 'extensions') self._api_models = APIModels(features_bundle, compiled_fs_factory, self._mock_file_system, object_store_creator, 'extensions')
def GetAPIModels(self, platform): if self._platform_data[platform].api_models is None: # TODO(danielj41): Filter APIModels data here rather than passing the # platform. self._platform_data[platform].api_models = APIModels( self.GetFeaturesBundle(platform), self._compiled_fs_factory, self._host_fs_at_trunk, self._object_store_creator, platform) return self._platform_data[platform].api_models
def GetAPIModels(self, platform): if self._platform_data[platform].api_models is None: # TODO(danielj41): Filter APIModels data here rather than passing the # platform. self._platform_data[platform].api_models = APIModels( self.GetFeaturesBundle(platform), self._compiled_fs_factory, self._host_fs_at_master, self._object_store_creator, platform, SchemaProcessorFactory( Future( callback=lambda: self.GetReferenceResolver(platform)), Future(callback=lambda: self.GetAPIModels(platform)), Future(callback=lambda: self.GetFeaturesBundle(platform)), self._compiled_fs_factory, self._host_fs_at_master)) return self._platform_data[platform].api_models
class APIModelsTest(unittest.TestCase): def setUp(self): object_store_creator = ObjectStoreCreator.ForTest() compiled_fs_factory = CompiledFileSystem.Factory(object_store_creator) self._mock_file_system = MockFileSystem( TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS)) features_bundle = FeaturesBundle(self._mock_file_system, compiled_fs_factory, object_store_creator, 'extensions') self._api_models = APIModels(features_bundle, compiled_fs_factory, self._mock_file_system, object_store_creator, 'extensions', SchemaProcessorFactoryForTest()) def testGetNames(self): # Both 'app' and 'app.runtime' appear here because 'app.runtime' has # noparent:true, but 'app.runtime.foo' etc doesn't so it's a sub-feature of # 'app.runtime' not a separate API. 'devtools.inspectedWindow' is an API # because there is no 'devtools'. self.assertEqual([ 'alarms', 'app', 'app.runtime', 'declarativeWebRequest', 'devtools.inspectedWindow', 'input', 'storage' ], sorted(self._api_models.GetNames())) def testGetModel(self): def get_model_name(api_name): return self._api_models.GetModel(api_name).Get().name self.assertEqual('devtools.inspectedWindow', get_model_name('devtools.inspectedWindow')) self.assertEqual('devtools.inspectedWindow', get_model_name('devtools/inspected_window.json')) self.assertEqual( 'devtools.inspectedWindow', get_model_name(CHROME_API + 'devtools/inspected_window.json')) self.assertEqual('alarms', get_model_name('alarms')) self.assertEqual('alarms', get_model_name('alarms.idl')) self.assertEqual('alarms', get_model_name(CHROME_API + 'alarms.idl')) self.assertEqual('input.ime', get_model_name('input.ime')) self.assertEqual('input.ime', get_model_name('input_ime.json')) self.assertEqual('input.ime', get_model_name(CHROME_API + 'input_ime.json')) self.assertEqual('pageAction', get_model_name('pageAction')) self.assertEqual('pageAction', get_model_name('page_action.json')) self.assertEqual('pageAction', get_model_name(CHROME_API + 'page_action.json')) def testGetNonexistentModel(self): self.assertRaises( FileNotFoundError, self._api_models.GetModel('declarativeWebRequest').Get) self.assertRaises( FileNotFoundError, self._api_models.GetModel('declarative_web_request.json').Get) self.assertRaises( FileNotFoundError, self._api_models.GetModel(CHROME_API + 'declarative_web_request.json').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('notfound').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('notfound.json').Get) self.assertRaises( FileNotFoundError, self._api_models.GetModel(CHROME_API + 'notfound.json').Get) self.assertRaises( FileNotFoundError, self._api_models.GetModel(CHROME_API + 'alarms.json').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('storage').Get) self.assertRaises( FileNotFoundError, self._api_models.GetModel(CHROME_API + 'storage.json').Get) self.assertRaises( FileNotFoundError, self._api_models.GetModel(CHROME_API + 'storage.idl').Get) def testSingleFile(self): # 2 stats (1 for JSON and 1 for IDL) for each available API path. # 1 read (for IDL file which existed). future = self._api_models.GetModel('alarms') self.assertTrue(*self._mock_file_system.CheckAndReset( read_count=1, stat_count=len(API_PATHS) * 2)) # 1 read-resolve (for the IDL file). # # The important part here and above is that it's only doing a single read; # any more would break the contract that only a single file is accessed - # see the SingleFile annotation in api_models._CreateAPIModel. future.Get() self.assertTrue(*self._mock_file_system.CheckAndReset( read_resolve_count=1)) # 2 stats (1 for JSON and 1 for IDL) for each available API path. # No reads (still cached). future = self._api_models.GetModel('alarms') self.assertTrue(*self._mock_file_system.CheckAndReset( stat_count=len(API_PATHS) * 2)) future.Get() self.assertTrue(*self._mock_file_system.CheckAndReset())
def __init__(self, object_store_creator, compiled_fs_factory, branch_utility, host_file_system_provider, github_file_system_provider, gcs_file_system_provider, base_path='/'): ''' |object_store_creator| The ObjectStoreCreator used to create almost all caches. |compiled_fs_factory| Factory used to create CompiledFileSystems, a higher-level cache type than ObjectStores. This can usually be derived from just |object_store_creator| but under special circumstances a different implementation needs to be passed in. |branch_utility| Has knowledge of Chrome branches, channels, and versions. |host_file_system_provider| Creates FileSystem instances which host the server at alternative revisions. |github_file_system_provider| Creates FileSystem instances backed by GitHub. |base_path| The path which all HTML is generated relative to. Usually this is / but some servlets need to override this. ''' self.object_store_creator = object_store_creator self.compiled_fs_factory = compiled_fs_factory self.host_file_system_provider = host_file_system_provider host_fs_at_trunk = host_file_system_provider.GetTrunk() self.github_file_system_provider = github_file_system_provider self.gcs_file_system_provider = gcs_file_system_provider assert base_path.startswith('/') and base_path.endswith('/') self.base_path = base_path self.host_file_system_iterator = HostFileSystemIterator( host_file_system_provider, branch_utility) self.features_bundle = FeaturesBundle( host_fs_at_trunk, self.compiled_fs_factory, self.object_store_creator) self.api_models = APIModels( self.features_bundle, self.compiled_fs_factory, host_fs_at_trunk) self.availability_finder = AvailabilityFinder( branch_utility, compiled_fs_factory, self.host_file_system_iterator, host_fs_at_trunk, object_store_creator) self.api_categorizer = APICategorizer( host_fs_at_trunk, compiled_fs_factory) self.api_data_source_factory = APIDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, self.availability_finder, self.api_models, self.features_bundle, self.object_store_creator) self.ref_resolver_factory = ReferenceResolver.Factory( self.api_data_source_factory, self.api_models, object_store_creator) self.api_data_source_factory.SetReferenceResolverFactory( self.ref_resolver_factory) # Note: samples are super slow in the dev server because it doesn't support # async fetch, so disable them. if IsDevServer(): extension_samples_fs = EmptyDirFileSystem() app_samples_fs = EmptyDirFileSystem() else: extension_samples_fs = host_fs_at_trunk # TODO(kalman): Re-enable the apps samples, see http://crbug.com/344097. app_samples_fs = EmptyDirFileSystem() #app_samples_fs = github_file_system_provider.Create( # 'GoogleChrome', 'chrome-app-samples') self.samples_data_source_factory = SamplesDataSource.Factory( extension_samples_fs, app_samples_fs, CompiledFileSystem.Factory(object_store_creator), self.ref_resolver_factory, base_path) self.api_data_source_factory.SetSamplesDataSourceFactory( self.samples_data_source_factory) self.content_providers = ContentProviders( object_store_creator, self.compiled_fs_factory, host_fs_at_trunk, self.github_file_system_provider, self.gcs_file_system_provider) # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, # then factor out the DataSource creation into a factory method, so that # the entire ServerInstance doesn't need to be passed in here. self.template_renderer = TemplateRenderer(self) # TODO(kalman): It may be better for |document_renderer| to construct a # TemplateDataSource itself rather than depending on template_renderer, but # for that the above todo should be addressed. self.document_renderer = DocumentRenderer( TableOfContentsRenderer(host_fs_at_trunk, compiled_fs_factory, self.template_renderer), self.ref_resolver_factory.Create())
def __init__(self, object_store_creator, compiled_fs_factory, branch_utility, host_file_system_provider, github_file_system_provider, base_path='/'): ''' |object_store_creator| The ObjectStoreCreator used to create almost all caches. |compiled_fs_factory| Factory used to create CompiledFileSystems, a higher-level cache type than ObjectStores. This can usually be derived from just |object_store_creator| but under special circumstances a different implementation needs to be passed in. |branch_utility| Has knowledge of Chrome branches, channels, and versions. |host_file_system_provider| Creates FileSystem instances which host the server at alternative revisions. |github_file_system_provider| Creates FileSystem instances backed by GitHub. |base_path| The path which all HTML is generated relative to. Usually this is / but some servlets need to override this. ''' self.object_store_creator = object_store_creator self.compiled_fs_factory = compiled_fs_factory self.host_file_system_provider = host_file_system_provider host_fs_at_trunk = host_file_system_provider.GetTrunk() self.github_file_system_provider = github_file_system_provider assert base_path.startswith('/') and base_path.endswith('/') self.base_path = base_path self.host_file_system_iterator = HostFileSystemIterator( host_file_system_provider, branch_utility) self.features_bundle = FeaturesBundle(host_fs_at_trunk, self.compiled_fs_factory, self.object_store_creator) self.api_models = APIModels(self.features_bundle, self.compiled_fs_factory, host_fs_at_trunk) self.availability_finder = AvailabilityFinder( branch_utility, compiled_fs_factory, self.host_file_system_iterator, host_fs_at_trunk, object_store_creator) self.api_list_data_source_factory = APIListDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, self.features_bundle, self.object_store_creator) self.api_data_source_factory = APIDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, svn_constants.API_PATH, self.availability_finder, branch_utility) self.ref_resolver_factory = ReferenceResolver.Factory( self.api_data_source_factory, self.api_models, object_store_creator) self.api_data_source_factory.SetReferenceResolverFactory( self.ref_resolver_factory) # Note: samples are super slow in the dev server because it doesn't support # async fetch, so disable them. if IsDevServer(): extension_samples_fs = EmptyDirFileSystem() app_samples_fs = EmptyDirFileSystem() else: extension_samples_fs = host_fs_at_trunk app_samples_fs = github_file_system_provider.Create( 'GoogleChrome', 'chrome-app-samples') self.samples_data_source_factory = SamplesDataSource.Factory( extension_samples_fs, app_samples_fs, CompiledFileSystem.Factory(object_store_creator), self.ref_resolver_factory, svn_constants.EXAMPLES_PATH, base_path) self.api_data_source_factory.SetSamplesDataSourceFactory( self.samples_data_source_factory) self.intro_data_source_factory = IntroDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, self.ref_resolver_factory, [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) self.path_canonicalizer = PathCanonicalizer(self.compiled_fs_factory, host_fs_at_trunk) self.content_providers = ContentProviders( self.compiled_fs_factory, host_fs_at_trunk, self.github_file_system_provider) # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, # then factor out the DataSource creation into a factory method, so that # the entire ServerInstance doesn't need to be passed in here. self.template_renderer = TemplateRenderer(self) self.strings_json_path = svn_constants.STRINGS_JSON_PATH self.manifest_json_path = svn_constants.MANIFEST_JSON_PATH self.manifest_features_path = svn_constants.MANIFEST_FEATURES_PATH
class APIModelsTest(unittest.TestCase): def setUp(self): object_store_creator = ObjectStoreCreator.ForTest() compiled_fs_factory = CompiledFileSystem.Factory(object_store_creator) self._mock_file_system = MockFileSystem(TestFileSystem(_TEST_DATA)) features_bundle = FeaturesBundle(self._mock_file_system, compiled_fs_factory, object_store_creator) self._api_models = APIModels(features_bundle, compiled_fs_factory, self._mock_file_system) def testGetNames(self): # Both 'app' and 'app.runtime' appear here because 'app.runtime' has # noparent:true, but 'app.runtime.experimental' etc doesn't so it's a # sub-feature of 'app.runtime' not a separate API. # 'devtools.inspectedWindow' is an API because there is no 'devtools'. self.assertEqual([ 'alarms', 'app', 'app.runtime', 'declarativeWebRequest', 'devtools.inspectedWindow', 'experimental.accessibility', 'storage' ], sorted(self._api_models.GetNames())) def testGetModel(self): def get_model_name(api_name): return self._api_models.GetModel(api_name).Get().name self.assertEqual('devtools.inspectedWindow', get_model_name('devtools.inspectedWindow')) self.assertEqual('devtools.inspectedWindow', get_model_name('devtools/inspected_window.json')) self.assertEqual('devtools.inspectedWindow', get_model_name('api/devtools/inspected_window.json')) self.assertEqual('alarms', get_model_name('alarms')) self.assertEqual('alarms', get_model_name('alarms.idl')) self.assertEqual('alarms', get_model_name('api/alarms.idl')) self.assertEqual('declarativeWebRequest', get_model_name('declarativeWebRequest')) self.assertEqual('declarativeWebRequest', get_model_name('declarative_web_request.json')) self.assertEqual('declarativeWebRequest', get_model_name('api/declarative_web_request.json')) self.assertEqual('experimental.accessibility', get_model_name('experimental.accessibility')) self.assertEqual('experimental.accessibility', get_model_name('experimental_accessibility.json')) self.assertEqual('experimental.accessibility', get_model_name('api/experimental_accessibility.json')) self.assertEqual('pageAction', get_model_name('pageAction')) self.assertEqual('pageAction', get_model_name('page_action.json')) self.assertEqual('pageAction', get_model_name('api/page_action.json')) def testGetNonexistentModel(self): self.assertRaises(FileNotFoundError, self._api_models.GetModel('notfound').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('notfound.json').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('api/notfound.json').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('api/alarms.json').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('storage').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('api/storage.json').Get) self.assertRaises(FileNotFoundError, self._api_models.GetModel('api/storage.idl').Get) def testSingleFile(self): # 2 stats (1 for JSON and 1 for IDL), 1 read (for IDL file which existed). future = self._api_models.GetModel('alarms') self.assertTrue( *self._mock_file_system.CheckAndReset(read_count=1, stat_count=2)) # 1 read-resolve (for the IDL file). # # The important part here and above is that it's only doing a single read; # any more would break the contract that only a single file is accessed - # see the SingleFile annotation in api_models._CreateAPIModel. future.Get() self.assertTrue(*self._mock_file_system.CheckAndReset( read_resolve_count=1)) # 2 stats (1 for JSON and 1 for IDL), no reads (still cached). future = self._api_models.GetModel('alarms') self.assertTrue(*self._mock_file_system.CheckAndReset(stat_count=2)) future.Get() self.assertTrue(*self._mock_file_system.CheckAndReset())