OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 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 os |
| 7 import sys |
| 8 import unittest |
| 9 |
| 10 from availability_finder import AvailabilityFinder |
| 11 from branch_utility import BranchUtility |
| 12 from compiled_file_system import CompiledFileSystem |
| 13 from fake_url_fetcher import FakeUrlFetcher |
| 14 from object_store_creator import ObjectStoreCreator |
| 15 from test_file_system import TestFileSystem |
| 16 from test_data.canned_data import (CANNED_API_FILE_SYSTEM_DATA, CANNED_BRANCHES) |
| 17 |
| 18 def _CreateCannedFileSystem(version): |
| 19 branch = CANNED_BRANCHES[version] |
| 20 return TestFileSystem(CANNED_API_FILE_SYSTEM_DATA[str(branch)]) |
| 21 |
| 22 class AvailabilityFinderTest(unittest.TestCase): |
| 23 def setUp(self): |
| 24 self._avail_ds_factory = AvailabilityFinder.Factory( |
| 25 ObjectStoreCreator.ForTest(), |
| 26 CompiledFileSystem.Factory( |
| 27 TestFileSystem(CANNED_API_FILE_SYSTEM_DATA['trunk']), |
| 28 ObjectStoreCreator.ForTest()), |
| 29 BranchUtility( |
| 30 os.path.join('branch_utility', 'first.json'), |
| 31 os.path.join('branch_utility', 'second.json'), |
| 32 FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')), |
| 33 ObjectStoreCreator.ForTest()), |
| 34 _CreateCannedFileSystem) |
| 35 self._avail_ds = self._avail_ds_factory.Create() |
| 36 |
| 37 def testGetApiAvailability(self): |
| 38 # Key: Using 'channel' (i.e. 'beta') to represent an availability listing |
| 39 # for an API in a _features.json file, and using |channel| (i.e. |dev|) to |
| 40 # represent the development channel, or phase of development, where an API's |
| 41 # availability is being checked. |
| 42 |
| 43 # Testing the predetermined APIs found in |
| 44 # templates/json/api_availabilities.json. |
| 45 self.assertEqual('stable', |
| 46 self._avail_ds.GetApiAvailability('jsonAPI1').channel) |
| 47 self.assertEqual(10, |
| 48 self._avail_ds.GetApiAvailability('jsonAPI1').version) |
| 49 self.assertEqual('trunk', |
| 50 self._avail_ds.GetApiAvailability('jsonAPI2').channel) |
| 51 self.assertEqual(None, |
| 52 self._avail_ds.GetApiAvailability('jsonAPI2').version) |
| 53 self.assertEqual('dev', |
| 54 self._avail_ds.GetApiAvailability('jsonAPI3').channel) |
| 55 self.assertEqual(None, |
| 56 self._avail_ds.GetApiAvailability('jsonAPI3').version) |
| 57 |
| 58 # Testing APIs found only by checking file system existence. |
| 59 self.assertEquals('stable', |
| 60 self._avail_ds.GetApiAvailability('windows').channel) |
| 61 self.assertEquals(23, |
| 62 self._avail_ds.GetApiAvailability('windows').version) |
| 63 self.assertEquals('stable', |
| 64 self._avail_ds.GetApiAvailability('tabs').channel) |
| 65 self.assertEquals(18, |
| 66 self._avail_ds.GetApiAvailability('tabs').version) |
| 67 self.assertEquals('stable', |
| 68 self._avail_ds.GetApiAvailability('input.ime').channel) |
| 69 self.assertEquals(18, |
| 70 self._avail_ds.GetApiAvailability('input.ime').version) |
| 71 |
| 72 # Testing API channel existence for _api_features.json. |
| 73 # Listed as 'dev' on |beta|, 'dev' on |dev|. |
| 74 self.assertEquals('dev', |
| 75 self._avail_ds.GetApiAvailability('systemInfo.stuff').channel) |
| 76 self.assertEquals(28, |
| 77 self._avail_ds.GetApiAvailability('systemInfo.stuff').version) |
| 78 # Listed as 'stable' on |beta|. |
| 79 self.assertEquals('beta', |
| 80 self._avail_ds.GetApiAvailability('systemInfo.cpu').channel) |
| 81 self.assertEquals(27, |
| 82 self._avail_ds.GetApiAvailability('systemInfo.cpu').version) |
| 83 |
| 84 # Testing API channel existence for _manifest_features.json. |
| 85 # Listed as 'trunk' on all channels. |
| 86 self.assertEquals('trunk', |
| 87 self._avail_ds.GetApiAvailability('sync').channel) |
| 88 self.assertEquals('trunk', |
| 89 self._avail_ds.GetApiAvailability('sync').version) |
| 90 # No records of API until |trunk|. |
| 91 self.assertEquals('trunk', |
| 92 self._avail_ds.GetApiAvailability('history').channel) |
| 93 self.assertEquals('trunk', |
| 94 self._avail_ds.GetApiAvailability('history').version) |
| 95 # Listed as 'dev' on |dev|. |
| 96 self.assertEquals('dev', |
| 97 self._avail_ds.GetApiAvailability('storage').channel) |
| 98 self.assertEquals(28, |
| 99 self._avail_ds.GetApiAvailability('storage').version) |
| 100 # Stable in _manifest_features and into pre-18 versions. |
| 101 self.assertEquals('stable', |
| 102 self._avail_ds.GetApiAvailability('pageAction').channel) |
| 103 self.assertEquals(8, |
| 104 self._avail_ds.GetApiAvailability('pageAction').version) |
| 105 |
| 106 # Testing API channel existence for _permission_features.json. |
| 107 # Listed as 'beta' on |trunk|. |
| 108 self.assertEquals('trunk', |
| 109 self._avail_ds.GetApiAvailability('falseBetaAPI').version) |
| 110 self.assertEquals('trunk', |
| 111 self._avail_ds.GetApiAvailability('falseBetaAPI').version) |
| 112 # Listed as 'trunk' on |trunk|. |
| 113 self.assertEquals('trunk', |
| 114 self._avail_ds.GetApiAvailability('trunkAPI').channel) |
| 115 self.assertEquals('trunk', |
| 116 self._avail_ds.GetApiAvailability('trunkAPI').version) |
| 117 # Listed as 'trunk' on all development channels. |
| 118 self.assertEquals('trunk', |
| 119 self._avail_ds.GetApiAvailability('declarativeContent').channel) |
| 120 self.assertEquals('trunk', |
| 121 self._avail_ds.GetApiAvailability('declarativeContent').version) |
| 122 # Listed as 'dev' on all development channels. |
| 123 self.assertEquals('dev', |
| 124 self._avail_ds.GetApiAvailability('bluetooth').channel) |
| 125 self.assertEquals(28, |
| 126 self._avail_ds.GetApiAvailability('bluetooth').version) |
| 127 # Listed as 'dev' on |dev|. |
| 128 self.assertEquals('dev', |
| 129 self._avail_ds.GetApiAvailability('cookies').channel) |
| 130 self.assertEquals(28, |
| 131 self._avail_ds.GetApiAvailability('cookies').version) |
| 132 # Treated as 'stable' APIs. |
| 133 self.assertEquals('stable', |
| 134 self._avail_ds.GetApiAvailability('alarms').channel) |
| 135 self.assertEquals(24, |
| 136 self._avail_ds.GetApiAvailability('alarms').version) |
| 137 self.assertEquals('stable', |
| 138 self._avail_ds.GetApiAvailability('bookmarks').channel) |
| 139 self.assertEquals(21, |
| 140 self._avail_ds.GetApiAvailability('bookmarks').version) |
| 141 |
| 142 # Testing older API existence using extension_api.json. |
| 143 self.assertEquals('stable', |
| 144 self._avail_ds.GetApiAvailability('menus').channel) |
| 145 self.assertEquals(6, |
| 146 self._avail_ds.GetApiAvailability('menus').version) |
| 147 self.assertEquals('stable', |
| 148 self._avail_ds.GetApiAvailability('idle').channel) |
| 149 self.assertEquals(5, |
| 150 self._avail_ds.GetApiAvailability('idle').version) |
| 151 |
| 152 # Switches between _features.json files across branches. |
| 153 # Listed as 'trunk' on all channels, in _api, _permission, or _manifest. |
| 154 self.assertEquals('trunk', |
| 155 self._avail_ds.GetApiAvailability('contextMenus').channel) |
| 156 self.assertEquals('trunk', |
| 157 self._avail_ds.GetApiAvailability('contextMenus').version) |
| 158 # Moves between _permission and _manifest as file system is traversed. |
| 159 self.assertEquals('stable', |
| 160 self._avail_ds.GetApiAvailability('systemInfo.display').channel) |
| 161 self.assertEquals(23, |
| 162 self._avail_ds.GetApiAvailability('systemInfo.display').version) |
| 163 self.assertEquals('stable', |
| 164 self._avail_ds.GetApiAvailability('webRequest').channel) |
| 165 self.assertEquals(17, |
| 166 self._avail_ds.GetApiAvailability('webRequest').version) |
| 167 |
| 168 # Mid-upgrade cases: |
| 169 # Listed as 'dev' on |beta| and 'beta' on |dev|. |
| 170 self.assertEquals('dev', |
| 171 self._avail_ds.GetApiAvailability('notifications').channel) |
| 172 self.assertEquals(28, |
| 173 self._avail_ds.GetApiAvailability('notifications').version) |
| 174 # Listed as 'beta' on |stable|, 'dev' on |beta| ... until |stable| on trunk. |
| 175 self.assertEquals('trunk', |
| 176 self._avail_ds.GetApiAvailability('events').channel) |
| 177 self.assertEquals('trunk', |
| 178 self._avail_ds.GetApiAvailability('events').version) |
| 179 |
| 180 if __name__ == '__main__': |
| 181 unittest.main() |
OLD | NEW |