| Index: chrome/common/extensions/docs/server2/content_providers_test.py
|
| diff --git a/chrome/common/extensions/docs/server2/content_providers_test.py b/chrome/common/extensions/docs/server2/content_providers_test.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..4e56b72dd64e2735dfdd844e109b2ff15f044265
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/docs/server2/content_providers_test.py
|
| @@ -0,0 +1,136 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2013 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import json
|
| +import unittest
|
| +
|
| +from compiled_file_system import CompiledFileSystem
|
| +from content_providers import ContentProviders
|
| +from object_store_creator import ObjectStoreCreator
|
| +from test_file_system import TestFileSystem
|
| +from test_util import DisableLogging
|
| +
|
| +
|
| +_HOST = 'https://developer.chrome.com'
|
| +
|
| +
|
| +_CONTENT_PROVIDERS = {
|
| + 'apples': {
|
| + 'default': True,
|
| + 'chroot': 'apples',
|
| + 'serveFrom': 'apples-dir',
|
| + 'type': 'host',
|
| + },
|
| + 'bananas': {
|
| + 'serveFrom': '',
|
| + 'type': 'host',
|
| + },
|
| + 'tomatoes': {
|
| + 'chroot': 'tomatoes/are/a',
|
| + 'serveFrom': 'tomatoes-dir/are/a',
|
| + 'type': 'host',
|
| + },
|
| +}
|
| +
|
| +
|
| +_FILE_SYSTEM_DATA = {
|
| + 'docs': {
|
| + 'templates': {
|
| + 'json': {
|
| + 'content_providers.json': json.dumps(_CONTENT_PROVIDERS),
|
| + },
|
| + },
|
| + },
|
| + 'apples': {
|
| + 'gala.txt': 'gala apples',
|
| + 'green': {
|
| + 'granny smith.txt': 'granny smith apples',
|
| + },
|
| + },
|
| + 'tomatoes': {
|
| + 'are': {
|
| + 'a': {
|
| + 'vegetable.txt': 'no they aren\'t',
|
| + 'fruit': {
|
| + 'cherry.txt': 'cherry tomatoes',
|
| + },
|
| + },
|
| + },
|
| + },
|
| +}
|
| +
|
| +
|
| +class ContentProvidersTest(unittest.TestCase):
|
| + def setUp(self):
|
| + self._content_providers = ContentProviders(
|
| + CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()),
|
| + TestFileSystem(_FILE_SYSTEM_DATA))
|
| +
|
| + def testDefaultProvider(self):
|
| + provider = self._content_providers.GetDefault()
|
| + self.assertEqual(
|
| + 'gala apples',
|
| + provider.GetContentInfo(_HOST, 'gala.txt').Get().content)
|
| + self.assertEqual(
|
| + 'granny smith apples',
|
| + provider.GetContentInfo(_HOST, 'green/granny smith.txt').Get().content)
|
| +
|
| + def testSimpleRootPath(self):
|
| + provider = self._content_providers.GetByName('apples')
|
| + self.assertEqual(
|
| + 'gala apples',
|
| + provider.GetContentInfo(_HOST, 'gala.txt').Get().content)
|
| + self.assertEqual(
|
| + 'granny smith apples',
|
| + provider.GetContentInfo(_HOST, 'green/granny smith.txt').Get().content)
|
| +
|
| + def testComplexRootPath(self):
|
| + provider = self._content_providers.GetByName('tomatoes')
|
| + self.assertEqual(
|
| + 'no they aren\'t',
|
| + provider.GetContentInfo(_HOST, 'vegetable.txt').Get().content)
|
| + self.assertEqual(
|
| + 'cherry tomatoes',
|
| + provider.GetContentInfo(_HOST, 'fruit/cherry.txt').Get().content)
|
| +
|
| + def testEmptyRootPath(self):
|
| + provider = self._content_providers.GetByName('bananas')
|
| + self.assertEqual(
|
| + 'gala apples',
|
| + provider.GetContentInfo(_HOST, 'apples/gala.txt').Get().content)
|
| +
|
| + def testSimpleServlet(self):
|
| + provider, path = self._content_providers.GetByServlet('apples-dir')
|
| + self.assertEqual('apples', provider.name)
|
| + self.assertEqual('', path)
|
| + provider, path = self._content_providers.GetByServlet(
|
| + 'apples-dir/are/forever')
|
| + self.assertEqual('apples', provider.name)
|
| + self.assertEqual('are/forever', path)
|
| +
|
| + def testComplexServlet(self):
|
| + provider, path = self._content_providers.GetByServlet('tomatoes-dir/are/a')
|
| + self.assertEqual('tomatoes', provider.name)
|
| + self.assertEqual('', path)
|
| + provider, path = self._content_providers.GetByServlet(
|
| + 'tomatoes-dir/are/a/fruit/they/are')
|
| + self.assertEqual('tomatoes', provider.name)
|
| + self.assertEqual('fruit/they/are', path)
|
| +
|
| + def testEmptyStringServlet(self):
|
| + provider, path = self._content_providers.GetByServlet('tomatoes-dir/are')
|
| + self.assertEqual('bananas', provider.name)
|
| + self.assertEqual('tomatoes-dir/are', path)
|
| + provider, path = self._content_providers.GetByServlet('')
|
| + self.assertEqual('bananas', provider.name)
|
| + self.assertEqual('', path)
|
| +
|
| + @DisableLogging('error')
|
| + def testProviderNotFound(self):
|
| + self.assertEqual(None, self._content_providers.GetByName('cabbages'))
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|