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.
8 from chroot_file_system import ChrootFileSystem
9 from file_system import FileNotFoundError, StatInfo
10 from test_file_system import TestFileSystem
13 def _SortListValues(dict_):
14 for value in dict_.itervalues():
15 if isinstance(value, list):
20 class ChrootFileSystemTest(unittest.TestCase):
23 self._test_fs = TestFileSystem({
24 '404.html': '404.html contents',
26 'a11y.html': 'a11y.html contents',
27 'about_apps.html': 'about_apps.html contents',
29 'file.html': 'file.html contents',
33 'activeTab.html': 'activeTab.html contents',
34 'alarms.html': 'alarms.html contents',
37 'csp.html': 'csp.html contents',
38 'usb.html': 'usb.html contents',
40 'sockets.html': 'sockets.html contents',
46 for prefix in ('', '/'):
47 for suffix in ('', '/'):
48 chroot_fs = ChrootFileSystem(self._test_fs,
49 prefix + 'extensions/manifest' + suffix)
51 'moremanifest/usb.html': 'usb.html contents',
52 '': ['moremanifest/', 'sockets.html', ],
53 'moremanifest/': ['csp.html', 'usb.html'],
54 'sockets.html': 'sockets.html contents',
55 }, _SortListValues(chroot_fs.Read(
56 ('moremanifest/usb.html', '', 'moremanifest/', 'sockets.html')
59 def testEmptyRoot(self):
60 chroot_fs = ChrootFileSystem(self._test_fs, '')
61 self.assertEqual('404.html contents',
62 chroot_fs.ReadSingle('404.html').Get())
65 self._test_fs.IncrementStat('extensions/manifest/', by=2)
66 self._test_fs.IncrementStat('extensions/manifest/moremanifest/csp.html')
67 for prefix in ('', '/'):
68 for suffix in ('', '/'):
69 chroot_fs = ChrootFileSystem(self._test_fs,
70 prefix + 'extensions' + suffix)
71 self.assertEqual(StatInfo('0', child_versions={
72 'activeTab.html': '0',
75 }), chroot_fs.Stat(''))
76 self.assertEqual(StatInfo('0'), chroot_fs.Stat('activeTab.html'))
77 self.assertEqual(StatInfo('2', child_versions={
80 }), chroot_fs.Stat('manifest/'))
81 self.assertEqual(StatInfo('0'), chroot_fs.Stat('manifest/sockets.html'))
82 self.assertEqual(StatInfo('0', child_versions={
85 }), chroot_fs.Stat('manifest/moremanifest/'))
86 self.assertEqual(StatInfo('1'),
87 chroot_fs.Stat('manifest/moremanifest/csp.html'))
88 self.assertEqual(StatInfo('0'),
89 chroot_fs.Stat('manifest/moremanifest/usb.html'))
91 def testIdentity(self):
92 chroot_fs1 = ChrootFileSystem(self._test_fs, '1')
93 chroot_fs1b = ChrootFileSystem(self._test_fs, '1')
94 chroot_fs2 = ChrootFileSystem(self._test_fs, '2')
95 self.assertNotEqual(self._test_fs.GetIdentity(), chroot_fs1.GetIdentity())
96 self.assertNotEqual(self._test_fs.GetIdentity(), chroot_fs2.GetIdentity())
97 self.assertNotEqual(chroot_fs1.GetIdentity(), chroot_fs2.GetIdentity())
98 self.assertEqual(chroot_fs1.GetIdentity(), chroot_fs1b.GetIdentity())
101 if __name__ == '__main__':