Add a NavigationThrottle to the public content/ interface
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / chained_compiled_file_system_test.py
blob33fd91cc0468b042950abb50c1f5e63ddd1c0801
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.
6 import unittest
8 from chained_compiled_file_system import ChainedCompiledFileSystem
9 from compiled_file_system import CompiledFileSystem
10 from object_store_creator import ObjectStoreCreator
11 from test_file_system import TestFileSystem
13 _TEST_DATA_BASE = {
14 'a.txt': 'base a.txt',
15 'dir': {
16 'b.txt': 'base b.txt'
20 _TEST_DATA_NEW = {
21 'a.txt': 'new a.txt',
22 'new.txt': 'a new file',
23 'dir': {
24 'b.txt': 'new b.txt',
25 'new.txt': 'new file in dir',
29 identity = lambda _, x: x
31 class ChainedCompiledFileSystemTest(unittest.TestCase):
32 def setUp(self):
33 object_store_creator = ObjectStoreCreator(start_empty=False)
34 base_file_system = TestFileSystem(_TEST_DATA_BASE, identity='base')
35 self._base_compiled_fs = CompiledFileSystem.Factory(
36 object_store_creator).Create(base_file_system,
37 identity,
38 ChainedCompiledFileSystemTest)
39 chained_factory = ChainedCompiledFileSystem.Factory([base_file_system],
40 object_store_creator)
41 self._new_file_system = TestFileSystem(_TEST_DATA_NEW, identity='new')
42 self._chained_compiled_fs = chained_factory.Create(
43 self._new_file_system, identity, ChainedCompiledFileSystemTest)
45 def testGetFromFile(self):
46 self.assertEqual(self._chained_compiled_fs.GetFromFile('a.txt').Get(),
47 self._base_compiled_fs.GetFromFile('a.txt').Get())
48 self.assertEqual(self._chained_compiled_fs.GetFromFile('new.txt').Get(),
49 'a new file')
50 self.assertEqual(self._chained_compiled_fs.GetFromFile('dir/new.txt').Get(),
51 'new file in dir')
52 self._new_file_system.IncrementStat('a.txt')
53 self.assertNotEqual(self._chained_compiled_fs.GetFromFile('a.txt').Get(),
54 self._base_compiled_fs.GetFromFile('a.txt').Get())
55 self.assertEqual(self._chained_compiled_fs.GetFromFile('a.txt').Get(),
56 self._new_file_system.ReadSingle('a.txt').Get())
58 def testGetFromFileListing(self):
59 self.assertEqual(self._chained_compiled_fs.GetFromFileListing('dir/').Get(),
60 self._base_compiled_fs.GetFromFileListing('dir/').Get())
61 self._new_file_system.IncrementStat('dir/new.txt')
62 self.assertNotEqual(
63 self._chained_compiled_fs.GetFromFileListing('dir/').Get(),
64 self._base_compiled_fs.GetFromFileListing('dir/').Get())
65 self.assertEqual(
66 self._chained_compiled_fs.GetFromFileListing('dir/').Get(),
67 self._new_file_system.ReadSingle('dir/').Get())
69 if __name__ == '__main__':
70 unittest.main()