Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / host_file_system_iterator_test.py
blob5a6cf3c0b229bdf26b432c92cf33819e0bd3999e
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 |trunk|.
51 # Total: 25 file systems.
52 iterations, callback = _GetIterationTracker(0)
53 self.assertEqual(
54 self._iterator.Ascending(self._GetStableChannelInfo(5), callback),
55 self._GetChannelInfo('trunk'))
56 self.assertEqual(len(iterations), 25)
58 # Start at |stable| version 5, and move up towards |trunk|. The callback
59 # fails at |beta|, so the last successful callback was the latest version
60 # of |stable|. Total: 22 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), 22)
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 # |trunk|. Total: 3 file systems.
86 iterations, callback = _GetIterationTracker('trunk')
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 |trunk|.
95 iterations, callback = _GetIterationTracker('trunk')
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._GetChannelInfo('stable'),
116 self._GetChannelInfo('beta'),
117 self._GetChannelInfo('dev')], iterations)
119 def testDescending(self):
120 # Start at |trunk|, and the callback fails immediately. No file systems
121 # are successfully processed, so Descending() will return None.
122 iterations, callback = _GetIterationTracker('trunk')
123 self.assertEqual(
124 self._iterator.Descending(self._GetChannelInfo('trunk'), callback),
125 None)
126 self.assertEqual([], iterations)
128 # Start at |trunk|, and the callback fails at |dev|. Last good iteration
129 # should be |trunk|.
130 iterations, callback = _GetIterationTracker(
131 self._GetChannelInfo('dev').version)
132 self.assertEqual(
133 self._iterator.Descending(self._GetChannelInfo('trunk'), callback),
134 self._GetChannelInfo('trunk'))
135 self.assertEqual([self._GetChannelInfo('trunk')], iterations)
137 # Start at |trunk|, and then move from |dev| down to |stable| at version 5.
138 # Total: 25 file systems.
139 iterations, callback = _GetIterationTracker(0)
140 self.assertEqual(
141 self._iterator.Descending(self._GetChannelInfo('trunk'), callback),
142 self._GetStableChannelInfo(5))
143 self.assertEqual(len(iterations), 25)
145 # Start at the latest version of |stable|, and move down to |stable| at
146 # version 5. Total: 22 file systems.
147 iterations, callback = _GetIterationTracker(0)
148 self.assertEqual(
149 self._iterator.Descending(self._GetChannelInfo('stable'), callback),
150 self._GetStableChannelInfo(5))
151 self.assertEqual(len(iterations), 22)
153 # Start at |dev| and iterate down through |stable| versions. The callback
154 # fails at version 10. Total: 18 file systems.
155 iterations, callback = _GetIterationTracker(10)
156 self.assertEqual(
157 self._iterator.Descending(self._GetChannelInfo('dev'), callback),
158 self._GetStableChannelInfo(11))
159 self.assertEqual([self._GetChannelInfo('dev'),
160 self._GetChannelInfo('beta'),
161 self._GetStableChannelInfo(26),
162 self._GetStableChannelInfo(25),
163 self._GetStableChannelInfo(24),
164 self._GetStableChannelInfo(23),
165 self._GetStableChannelInfo(22),
166 self._GetStableChannelInfo(21),
167 self._GetStableChannelInfo(20),
168 self._GetStableChannelInfo(19),
169 self._GetStableChannelInfo(18),
170 self._GetStableChannelInfo(17),
171 self._GetStableChannelInfo(16),
172 self._GetStableChannelInfo(15),
173 self._GetStableChannelInfo(14),
174 self._GetStableChannelInfo(13),
175 self._GetStableChannelInfo(12),
176 self._GetStableChannelInfo(11)], iterations)
179 if __name__ == '__main__':
180 unittest.main()