| Index: chrome/common/extensions/docs/server2/chained_compiled_file_system_test.py
|
| diff --git a/chrome/common/extensions/docs/server2/chained_compiled_file_system_test.py b/chrome/common/extensions/docs/server2/chained_compiled_file_system_test.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..28847511942ced1b9a2eec217e70ff9470b2fe9a
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/docs/server2/chained_compiled_file_system_test.py
|
| @@ -0,0 +1,73 @@
|
| +#!/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 unittest
|
| +
|
| +from chained_compiled_file_system import ChainedCompiledFileSystem
|
| +from compiled_file_system import CompiledFileSystem
|
| +from object_store_creator import ObjectStoreCreator
|
| +from test_file_system import TestFileSystem
|
| +
|
| +_TEST_DATA_BASE = {
|
| + 'a.txt': 'base a.txt',
|
| + 'dir': {
|
| + 'b.txt': 'base b.txt'
|
| + },
|
| +}
|
| +
|
| +_TEST_DATA_NEW = {
|
| + 'a.txt': 'new a.txt',
|
| + 'new.txt': 'a new file',
|
| + 'dir': {
|
| + 'b.txt': 'new b.txt',
|
| + 'new.txt': 'new file in dir',
|
| + },
|
| +}
|
| +
|
| +class ChainedCompiledFileSystemTest(unittest.TestCase):
|
| + def setUp(self):
|
| + self._object_store_creator = ObjectStoreCreator(
|
| + 'chained', start_empty=False)
|
| + self._base_object_store_creator = ObjectStoreCreator(
|
| + 'base', start_empty=False)
|
| + base_file_system = TestFileSystem(_TEST_DATA_BASE)
|
| + self._base_factory = CompiledFileSystem.Factory(
|
| + base_file_system,
|
| + self._base_object_store_creator)
|
| + self._file_system = TestFileSystem(_TEST_DATA_NEW)
|
| + self._patched_factory = CompiledFileSystem.Factory(
|
| + self._file_system,
|
| + self._object_store_creator)
|
| + self._chained_factory = ChainedCompiledFileSystem.Factory(
|
| + [(self._patched_factory, self._file_system),
|
| + (self._base_factory, base_file_system)])
|
| + self._base_compiled_fs = self._base_factory.CreateIdentity(TestFileSystem)
|
| + self._chained_compiled_fs = self._chained_factory.CreateIdentity(
|
| + TestFileSystem)
|
| +
|
| + def testGetFromFile(self):
|
| + self.assertEqual(self._chained_compiled_fs.GetFromFile('a.txt'),
|
| + self._base_compiled_fs.GetFromFile('a.txt'))
|
| + self.assertEqual(self._chained_compiled_fs.GetFromFile('new.txt'),
|
| + 'a new file')
|
| + self.assertEqual(self._chained_compiled_fs.GetFromFile('dir/new.txt'),
|
| + 'new file in dir')
|
| + self._file_system.IncrementStat('a.txt')
|
| + self.assertNotEqual(self._chained_compiled_fs.GetFromFile('a.txt'),
|
| + self._base_compiled_fs.GetFromFile('a.txt'))
|
| + self.assertEqual(self._chained_compiled_fs.GetFromFile('a.txt'),
|
| + self._file_system.ReadSingle('a.txt'))
|
| +
|
| + def testGetFromFileListing(self):
|
| + self.assertEqual(self._chained_compiled_fs.GetFromFile('dir/'),
|
| + self._base_compiled_fs.GetFromFile('dir/'))
|
| + self._file_system.IncrementStat('dir/')
|
| + self.assertNotEqual(self._chained_compiled_fs.GetFromFileListing('dir/'),
|
| + self._base_compiled_fs.GetFromFileListing('dir/'))
|
| + self.assertEqual(self._chained_compiled_fs.GetFromFileListing('dir/'),
|
| + self._file_system.ReadSingle('dir/'))
|
| +
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|