| 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 content_providers import ContentProviders | 10 from content_providers import ContentProviders |
| 11 from extensions_paths import EXTENSIONS |
| 11 from object_store_creator import ObjectStoreCreator | 12 from object_store_creator import ObjectStoreCreator |
| 12 from test_file_system import TestFileSystem | 13 from test_file_system import TestFileSystem |
| 13 from test_util import DisableLogging | 14 from test_util import DisableLogging |
| 14 | 15 |
| 15 | 16 |
| 16 _HOST = 'https://developer.chrome.com' | 17 _HOST = 'https://developer.chrome.com' |
| 17 | 18 |
| 18 | 19 |
| 19 _CONTENT_PROVIDERS = { | 20 _CONTENT_PROVIDERS = { |
| 20 'apples': { | 21 'apples': { |
| 21 'chromium': { | 22 'chromium': { |
| 22 'dir': 'apples' | 23 'dir': 'chrome/common/extensions/apples' |
| 23 }, | 24 }, |
| 24 'serveFrom': 'apples-dir', | 25 'serveFrom': 'apples-dir', |
| 25 }, | 26 }, |
| 26 'bananas': { | 27 'bananas': { |
| 27 'serveFrom': '', | 28 'serveFrom': '', |
| 28 'chromium': { | 29 'chromium': { |
| 29 'dir': '' | 30 'dir': 'chrome/common/extensions' |
| 30 }, | 31 }, |
| 31 }, | 32 }, |
| 32 'github-provider': { | 33 'github-provider': { |
| 33 'serveFrom': 'gh', | 34 'serveFrom': 'gh', |
| 34 'github': { | 35 'github': { |
| 36 'dir': 'chrome/common/extensions', |
| 35 'owner': 'GoogleChrome', | 37 'owner': 'GoogleChrome', |
| 36 'repo': 'hello-world', | 38 'repo': 'hello-world', |
| 37 }, | 39 }, |
| 38 }, | 40 }, |
| 39 'github-provider-with-dir': { | 41 'github-provider-with-dir': { |
| 40 'serveFrom': 'gh2', | 42 'serveFrom': 'gh2', |
| 41 'github': { | 43 'github': { |
| 42 'dir': 'tomatoes/are/a', | 44 'dir': 'chrome/common/extensions/tomatoes/are/a', |
| 43 'owner': 'SomeOwner', | 45 'owner': 'SomeOwner', |
| 44 'repo': 'some-repo', | 46 'repo': 'some-repo', |
| 45 }, | 47 }, |
| 46 }, | 48 }, |
| 47 'tomatoes': { | 49 'tomatoes': { |
| 48 'serveFrom': 'tomatoes-dir/are/a', | 50 'serveFrom': 'tomatoes-dir/are/a', |
| 49 'chromium': { | 51 'chromium': { |
| 50 'dir': 'tomatoes/are/a' | 52 'dir': 'chrome/common/extensions/tomatoes/are/a' |
| 51 }, | 53 }, |
| 52 }, | 54 }, |
| 53 } | 55 } |
| 54 | 56 |
| 55 | 57 |
| 56 _FILE_SYSTEM_DATA = { | 58 _FILE_SYSTEM_DATA = { |
| 57 'docs': { | 59 'docs': { |
| 58 'templates': { | 60 'templates': { |
| 59 'json': { | 61 'json': { |
| 60 'content_providers.json': json.dumps(_CONTENT_PROVIDERS), | 62 'content_providers.json': json.dumps(_CONTENT_PROVIDERS), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return self._file_system | 96 return self._file_system |
| 95 | 97 |
| 96 def GetAndReset(self): | 98 def GetAndReset(self): |
| 97 calls = self._calls | 99 calls = self._calls |
| 98 self._calls = [] | 100 self._calls = [] |
| 99 return calls | 101 return calls |
| 100 | 102 |
| 101 | 103 |
| 102 class ContentProvidersTest(unittest.TestCase): | 104 class ContentProvidersTest(unittest.TestCase): |
| 103 def setUp(self): | 105 def setUp(self): |
| 104 test_file_system = TestFileSystem(_FILE_SYSTEM_DATA) | 106 test_file_system = TestFileSystem(_FILE_SYSTEM_DATA, relative_to=EXTENSIONS) |
| 105 self._github_fs_provider = _MockGithubFileSystemProvider(test_file_system) | 107 self._github_fs_provider = _MockGithubFileSystemProvider(test_file_system) |
| 106 self._content_providers = ContentProviders( | 108 self._content_providers = ContentProviders( |
| 107 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), | 109 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), |
| 108 test_file_system, | 110 test_file_system, |
| 109 self._github_fs_provider) | 111 self._github_fs_provider) |
| 110 | 112 |
| 111 def testSimpleRootPath(self): | 113 def testSimpleRootPath(self): |
| 112 provider = self._content_providers.GetByName('apples') | 114 provider = self._content_providers.GetByName('apples') |
| 113 self.assertEqual( | 115 self.assertEqual( |
| 114 'gala apples', | 116 'gala apples', |
| 115 provider.GetContentAndType(_HOST, 'gala.txt').Get().content) | 117 provider.GetContentAndType(_HOST, 'gala.txt').Get().content) |
| 116 self.assertEqual( | 118 self.assertEqual( |
| 117 'granny smith apples', | 119 'granny smith apples', |
| 118 provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get() | 120 provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get() |
| 119 .content) | 121 .content) |
| 120 | 122 |
| 121 def testComplexRootPath(self): | 123 def testComplexRootPath(self): |
| 122 provider = self._content_providers.GetByName('tomatoes') | 124 provider = self._content_providers.GetByName('tomatoes') |
| 123 self.assertEqual( | 125 self.assertEqual( |
| 124 'no they aren\'t', | 126 'no they aren\'t', |
| 125 provider.GetContentAndType(_HOST, 'vegetable.txt').Get().content) | 127 provider.GetContentAndType(_HOST, 'vegetable.txt').Get().content) |
| 126 self.assertEqual( | 128 self.assertEqual( |
| 127 'cherry tomatoes', | 129 'cherry tomatoes', |
| 128 provider.GetContentAndType(_HOST, 'fruit/cherry.txt').Get().content) | 130 provider.GetContentAndType(_HOST, 'fruit/cherry.txt').Get().content) |
| 129 | 131 |
| 130 def testEmptyRootPath(self): | 132 def testParentRootPath(self): |
| 131 provider = self._content_providers.GetByName('bananas') | 133 provider = self._content_providers.GetByName('bananas') |
| 132 self.assertEqual( | 134 self.assertEqual( |
| 133 'gala apples', | 135 'gala apples', |
| 134 provider.GetContentAndType(_HOST, 'apples/gala.txt').Get().content) | 136 provider.GetContentAndType(_HOST, 'apples/gala.txt').Get().content) |
| 135 | 137 |
| 136 def testSimpleServlet(self): | 138 def testSimpleServlet(self): |
| 137 provider, path = self._content_providers.GetByServeFrom('apples-dir') | 139 provider, path = self._content_providers.GetByServeFrom('apples-dir') |
| 138 self.assertEqual('apples', provider.name) | 140 self.assertEqual('apples', provider.name) |
| 139 self.assertEqual('', path) | 141 self.assertEqual('', path) |
| 140 provider, path = self._content_providers.GetByServeFrom( | 142 provider, path = self._content_providers.GetByServeFrom( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 self.assertEqual('github-provider-with-dir', provider.name) | 183 self.assertEqual('github-provider-with-dir', provider.name) |
| 182 self.assertEqual('fruit/cherry.txt', path) | 184 self.assertEqual('fruit/cherry.txt', path) |
| 183 self.assertEqual([('SomeOwner', 'some-repo')], | 185 self.assertEqual([('SomeOwner', 'some-repo')], |
| 184 self._github_fs_provider.GetAndReset()) | 186 self._github_fs_provider.GetAndReset()) |
| 185 self.assertEqual( | 187 self.assertEqual( |
| 186 'cherry tomatoes', | 188 'cherry tomatoes', |
| 187 provider.GetContentAndType(_HOST, path).Get().content) | 189 provider.GetContentAndType(_HOST, path).Get().content) |
| 188 | 190 |
| 189 if __name__ == '__main__': | 191 if __name__ == '__main__': |
| 190 unittest.main() | 192 unittest.main() |
| OLD | NEW |