cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / host_file_system_iterator_test.py
blob5ef4ab2c1f14e647b7e67710bb64a2e2c5cfb041
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 import unittest
9 from host_file_system_provider import HostFileSystemProvider
10 from host_file_system_iterator import HostFileSystemIterator
11 from object_store_creator import ObjectStoreCreator
12 from test_branch_utility import TestBranchUtility
13 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA
14 from test_file_system import TestFileSystem
17 def _GetIterationTracker(version):
18 '''Adds the ChannelInfo object from each iteration to a list, and signals the
19 loop to stop when |version| is reached.
20 '''
21 iterations = []
22 def callback(file_system, channel_info):
23 if channel_info.version == version:
24 return False
25 iterations.append(channel_info)
26 return True
27 return (iterations, callback)
30 class HostFileSystemIteratorTest(unittest.TestCase):
32 def setUp(self):
33 def host_file_system_constructor(branch, **optargs):
34 return TestFileSystem(deepcopy(CANNED_API_FILE_SYSTEM_DATA[branch]))
35 host_file_system_provider = HostFileSystemProvider(
36 ObjectStoreCreator.ForTest(),
37 constructor_for_test=host_file_system_constructor)
38 self._branch_utility = TestBranchUtility.CreateWithCannedData()
39 self._iterator = HostFileSystemIterator(
40 host_file_system_provider,
41 self._branch_utility)
43 def _GetStableChannelInfo(self,version):
44 return self._branch_utility.GetStableChannelInfo(version)
46 def _GetChannelInfo(self, channel_name):
47 return self._branch_utility.GetChannelInfo(channel_name)
49 def testAscending(self):
50 # Start at |stable| version 5, and move up towards |master|.
51 # Total: 28 file systems.
52 iterations, callback = _GetIterationTracker(0)
53 self.assertEqual(
54 self._iterator.Ascending(self._GetStableChannelInfo(5), callback),
55 self._GetChannelInfo('master'))
56 self.assertEqual(len(iterations), 28)
58 # Start at |stable| version 5, and move up towards |master|. The callback
59 # fails at |beta|, so the last successful callback was the latest version
60 # of |stable|. Total: 25 file systems.
61 iterations, callback = _GetIterationTracker(
62 self._GetChannelInfo('beta').version)
63 self.assertEqual(
64 self._iterator.Ascending(self._GetStableChannelInfo(5), callback),
65 self._GetChannelInfo('stable'))
66 self.assertEqual(len(iterations), 25)
68 # Start at |stable| version 5, and the callback fails immediately. Since
69 # no file systems are successfully processed, expect a return of None.
70 iterations, callback = _GetIterationTracker(5)
71 self.assertEqual(
72 self._iterator.Ascending(self._GetStableChannelInfo(5), callback),
73 None)
74 self.assertEqual([], iterations)
76 # Start at |stable| version 5, and the callback fails at version 6.
77 # The return should represent |stable| version 5.
78 iterations, callback = _GetIterationTracker(6)
79 self.assertEqual(
80 self._iterator.Ascending(self._GetStableChannelInfo(5), callback),
81 self._GetStableChannelInfo(5))
82 self.assertEqual([self._GetStableChannelInfo(5)], iterations)
84 # Start at the latest version of |stable|, and the callback fails at
85 # |master|. Total: 3 file systems.
86 iterations, callback = _GetIterationTracker('master')
87 self.assertEqual(
88 self._iterator.Ascending(self._GetChannelInfo('stable'), callback),
89 self._GetChannelInfo('dev'))
90 self.assertEqual([self._GetChannelInfo('stable'),
91 self._GetChannelInfo('beta'),
92 self._GetChannelInfo('dev')], iterations)
94 # Start at |stable| version 10, and the callback fails at |master|.
95 iterations, callback = _GetIterationTracker('master')
96 self.assertEqual(
97 self._iterator.Ascending(self._GetStableChannelInfo(10), callback),
98 self._GetChannelInfo('dev'))
99 self.assertEqual([self._GetStableChannelInfo(10),
100 self._GetStableChannelInfo(11),
101 self._GetStableChannelInfo(12),
102 self._GetStableChannelInfo(13),
103 self._GetStableChannelInfo(14),
104 self._GetStableChannelInfo(15),
105 self._GetStableChannelInfo(16),
106 self._GetStableChannelInfo(17),
107 self._GetStableChannelInfo(18),
108 self._GetStableChannelInfo(19),
109 self._GetStableChannelInfo(20),
110 self._GetStableChannelInfo(21),
111 self._GetStableChannelInfo(22),
112 self._GetStableChannelInfo(23),
113 self._GetStableChannelInfo(24),
114 self._GetStableChannelInfo(25),
115 self._GetStableChannelInfo(26),
116 self._GetStableChannelInfo(27),
117 self._GetStableChannelInfo(28),
118 self._GetChannelInfo('stable'),
119 self._GetChannelInfo('beta'),
120 self._GetChannelInfo('dev')], iterations)
122 def testDescending(self):
123 # Start at |master|, and the callback fails immediately. No file systems
124 # are successfully processed, so Descending() will return None.
125 iterations, callback = _GetIterationTracker('master')
126 self.assertEqual(
127 self._iterator.Descending(self._GetChannelInfo('master'), callback),
128 None)
129 self.assertEqual([], iterations)
131 # Start at |master|, and the callback fails at |dev|. Last good iteration
132 # should be |master|.
133 iterations, callback = _GetIterationTracker(
134 self._GetChannelInfo('dev').version)
135 self.assertEqual(
136 self._iterator.Descending(self._GetChannelInfo('master'), callback),
137 self._GetChannelInfo('master'))
138 self.assertEqual([self._GetChannelInfo('master')], iterations)
140 # Start at |master|, and then move from |dev| down to |stable| at version 5.
141 # Total: 28 file systems.
142 iterations, callback = _GetIterationTracker(0)
143 self.assertEqual(
144 self._iterator.Descending(self._GetChannelInfo('master'), callback),
145 self._GetStableChannelInfo(5))
146 self.assertEqual(len(iterations), 28)
148 # Start at the latest version of |stable|, and move down to |stable| at
149 # version 5. Total: 25 file systems.
150 iterations, callback = _GetIterationTracker(0)
151 self.assertEqual(
152 self._iterator.Descending(self._GetChannelInfo('stable'), callback),
153 self._GetStableChannelInfo(5))
154 self.assertEqual(len(iterations), 25)
156 # Start at |dev| and iterate down through |stable| versions. The callback
157 # fails at version 10. Total: 18 file systems.
158 iterations, callback = _GetIterationTracker(10)
159 self.assertEqual(
160 self._iterator.Descending(self._GetChannelInfo('dev'), callback),
161 self._GetStableChannelInfo(11))
162 self.assertEqual([self._GetChannelInfo('dev'),
163 self._GetChannelInfo('beta'),
164 self._GetChannelInfo('stable'),
165 self._GetStableChannelInfo(28),
166 self._GetStableChannelInfo(27),
167 self._GetStableChannelInfo(26),
168 self._GetStableChannelInfo(25),
169 self._GetStableChannelInfo(24),
170 self._GetStableChannelInfo(23),
171 self._GetStableChannelInfo(22),
172 self._GetStableChannelInfo(21),
173 self._GetStableChannelInfo(20),
174 self._GetStableChannelInfo(19),
175 self._GetStableChannelInfo(18),
176 self._GetStableChannelInfo(17),
177 self._GetStableChannelInfo(16),
178 self._GetStableChannelInfo(15),
179 self._GetStableChannelInfo(14),
180 self._GetStableChannelInfo(13),
181 self._GetStableChannelInfo(12),
182 self._GetStableChannelInfo(11)], iterations)
185 if __name__ == '__main__':
186 unittest.main()