- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / chroot_file_system_test.py
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.
5
6 import unittest
7
8 from chroot_file_system import ChrootFileSystem
9 from file_system import FileNotFoundError, StatInfo
10 from test_file_system import TestFileSystem
11
12
13 def _SortListValues(dict_):
14   for value in dict_.itervalues():
15     if isinstance(value, list):
16       value.sort()
17   return dict_
18
19
20 class ChrootFileSystemTest(unittest.TestCase):
21
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',
30         },
31       },
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',
39           },
40           'sockets.html': 'sockets.html contents',
41         },
42       },
43     })
44
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()))
58
59   def testEmptyRoot(self):
60     chroot_fs = ChrootFileSystem(self._test_fs, '')
61     self.assertEqual('404.html contents',
62                      chroot_fs.ReadSingle('404.html').Get())
63
64   def testStat(self):
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',
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/': '0',
79           'sockets.html': '0',
80         }), chroot_fs.Stat('manifest/'))
81         self.assertEqual(StatInfo('0'), chroot_fs.Stat('manifest/sockets.html'))
82         self.assertEqual(StatInfo('0', 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'))
90
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())
99
100
101 if __name__ == '__main__':
102   unittest.main()