cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / chroot_file_system_test.py
blob24160eab907b248f5b4fc9995b2b866b4ec91263
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 chroot_file_system import ChrootFileSystem
9 from file_system import StatInfo
10 from test_file_system import TestFileSystem
13 def _SortListValues(dict_):
14 for value in dict_.itervalues():
15 if isinstance(value, list):
16 value.sort()
17 return dict_
20 class ChrootFileSystemTest(unittest.TestCase):
22 def setUp(self):
23 self._test_fs = TestFileSystem({
24 '404.html': '404.html contents',
25 'apps': {
26 'a11y.html': 'a11y.html contents',
27 'about_apps.html': 'about_apps.html contents',
28 'fakedir': {
29 'file.html': 'file.html contents',
32 'extensions': {
33 'activeTab.html': 'activeTab.html contents',
34 'alarms.html': 'alarms.html contents',
35 'manifest': {
36 'moremanifest': {
37 'csp.html': 'csp.html contents',
38 'usb.html': 'usb.html contents',
40 'sockets.html': 'sockets.html contents',
45 def testRead(self):
46 for prefix in ('', '/'):
47 for suffix in ('', '/'):
48 chroot_fs = ChrootFileSystem(self._test_fs,
49 prefix + 'extensions/manifest' + suffix)
50 self.assertEqual({
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')
57 ).Get()))
59 def testEmptyRoot(self):
60 chroot_fs = ChrootFileSystem(self._test_fs, '')
61 self.assertEqual('404.html contents',
62 chroot_fs.ReadSingle('404.html').Get())
64 def testStat(self):
65 self._test_fs.IncrementStat('extensions/manifest/sockets.html', 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('2', child_versions={
72 'activeTab.html': '0',
73 'alarms.html': '0',
74 'manifest/': '2',
75 }), chroot_fs.Stat(''))
76 self.assertEqual(StatInfo('0'), chroot_fs.Stat('activeTab.html'))
77 self.assertEqual(StatInfo('2', child_versions={
78 'moremanifest/': '1',
79 'sockets.html': '2',
80 }), chroot_fs.Stat('manifest/'))
81 self.assertEqual(StatInfo('2'), chroot_fs.Stat('manifest/sockets.html'))
82 self.assertEqual(StatInfo('1', child_versions={
83 'csp.html': '1',
84 'usb.html': '0',
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__':
102 unittest.main()