cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / mock_file_system_test.py
blob813751f8be9dbf924c251801202079b58b8bfa4c
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 from copy import deepcopy
7 from file_system import FileNotFoundError, StatInfo
8 from mock_file_system import MockFileSystem
9 from test_file_system import TestFileSystem
10 import unittest
12 _TEST_DATA = {
13 '404.html': '404.html contents',
14 'apps': {
15 'a11y.html': 'a11y.html contents',
16 'about_apps.html': 'about_apps.html contents',
17 'fakedir': {
18 'file.html': 'file.html contents'
21 'extensions': {
22 'activeTab.html': 'activeTab.html contents',
23 'alarms.html': 'alarms.html contents'
27 def _Get(fn):
28 '''Returns a function which calls Future.Get on the result of |fn|.
29 '''
30 return lambda *args: fn(*args).Get()
32 class MockFileSystemTest(unittest.TestCase):
33 def testCheckAndReset(self):
34 fs = MockFileSystem(TestFileSystem(deepcopy(_TEST_DATA)))
36 self.assertTrue(*fs.CheckAndReset())
37 self.assertFalse(*fs.CheckAndReset(read_count=1))
38 self.assertFalse(*fs.CheckAndReset(stat_count=1))
40 future = fs.ReadSingle('apps/')
41 self.assertTrue(*fs.CheckAndReset(read_count=1))
42 future.Get()
43 self.assertTrue(*fs.CheckAndReset(read_resolve_count=1))
44 self.assertFalse(*fs.CheckAndReset(read_count=1))
45 self.assertTrue(*fs.CheckAndReset())
47 future = fs.ReadSingle('apps/')
48 self.assertFalse(*fs.CheckAndReset(read_count=2))
49 future.Get()
50 self.assertFalse(*fs.CheckAndReset(read_resolve_count=2))
52 fs.ReadSingle('extensions/').Get()
53 fs.ReadSingle('extensions/').Get()
54 self.assertTrue(*fs.CheckAndReset(read_count=2, read_resolve_count=2))
55 self.assertFalse(*fs.CheckAndReset(read_count=2, read_resolve_count=2))
56 self.assertTrue(*fs.CheckAndReset())
58 fs.ReadSingle('404.html').Get()
59 self.assertTrue(*fs.CheckAndReset(read_count=1, read_resolve_count=1))
60 future = fs.Read(['notfound.html', 'apps/'])
61 self.assertTrue(*fs.CheckAndReset(read_count=1))
62 self.assertRaises(FileNotFoundError, future.Get)
63 self.assertTrue(*fs.CheckAndReset(read_resolve_count=0))
65 fs.Stat('404.html')
66 fs.Stat('404.html')
67 fs.Stat('apps/')
68 self.assertFalse(*fs.CheckAndReset(stat_count=42))
69 self.assertFalse(*fs.CheckAndReset(stat_count=42))
70 self.assertTrue(*fs.CheckAndReset())
72 fs.ReadSingle('404.html').Get()
73 fs.Stat('404.html')
74 fs.Stat('apps/')
75 self.assertTrue(
76 *fs.CheckAndReset(read_count=1, read_resolve_count=1, stat_count=2))
77 self.assertTrue(*fs.CheckAndReset())
79 def testUpdates(self):
80 fs = MockFileSystem(TestFileSystem(deepcopy(_TEST_DATA)))
82 self.assertEqual(StatInfo('0', child_versions={
83 '404.html': '0',
84 'apps/': '0',
85 'extensions/': '0'
86 }), fs.Stat(''))
87 self.assertEqual(StatInfo('0'), fs.Stat('404.html'))
88 self.assertEqual(StatInfo('0', child_versions={
89 'a11y.html': '0',
90 'about_apps.html': '0',
91 'fakedir/': '0',
92 }), fs.Stat('apps/'))
93 self.assertEqual('404.html contents', fs.ReadSingle('404.html').Get())
95 fs.Update({
96 '404.html': 'New version!'
99 self.assertEqual(StatInfo('1', child_versions={
100 '404.html': '1',
101 'apps/': '0',
102 'extensions/': '0'
103 }), fs.Stat(''))
104 self.assertEqual(StatInfo('1'), fs.Stat('404.html'))
105 self.assertEqual(StatInfo('0', child_versions={
106 'a11y.html': '0',
107 'about_apps.html': '0',
108 'fakedir/': '0',
109 }), fs.Stat('apps/'))
110 self.assertEqual('New version!', fs.ReadSingle('404.html').Get())
112 fs.Update({
113 '404.html': 'Newer version!',
114 'apps': {
115 'fakedir': {
116 'file.html': 'yo'
121 self.assertEqual(StatInfo('2', child_versions={
122 '404.html': '2',
123 'apps/': '2',
124 'extensions/': '0'
125 }), fs.Stat(''))
126 self.assertEqual(StatInfo('2'), fs.Stat('404.html'))
127 self.assertEqual(StatInfo('2', child_versions={
128 'a11y.html': '0',
129 'about_apps.html': '0',
130 'fakedir/': '2',
131 }), fs.Stat('apps/'))
132 self.assertEqual(StatInfo('0'), fs.Stat('apps/a11y.html'))
133 self.assertEqual(StatInfo('2', child_versions={
134 'file.html': '2'
135 }), fs.Stat('apps/fakedir/'))
136 self.assertEqual(StatInfo('2'), fs.Stat('apps/fakedir/file.html'))
137 self.assertEqual(StatInfo('0', child_versions={
138 'activeTab.html': '0',
139 'alarms.html': '0'
140 }), fs.Stat('extensions/'))
141 self.assertEqual('Newer version!', fs.ReadSingle('404.html').Get())
142 self.assertEqual('yo', fs.ReadSingle('apps/fakedir/file.html').Get())
144 if __name__ == '__main__':
145 unittest.main()