Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 from api_data_source import (_JSCModel, | 11 from api_data_source import (_JSCModel, |
| 12 _FormatValue, | 12 _FormatValue, |
| 13 _GetEventByNameFromEvents) | 13 _GetEventByNameFromEvents) |
| 14 from availability_finder import AvailabilityInfo | |
| 14 from branch_utility import ChannelInfo | 15 from branch_utility import ChannelInfo |
| 15 from extensions_paths import CHROME_EXTENSIONS | 16 from extensions_paths import CHROME_EXTENSIONS |
| 16 from fake_host_file_system_provider import FakeHostFileSystemProvider | 17 from fake_host_file_system_provider import FakeHostFileSystemProvider |
| 17 from features_bundle import FeaturesBundle | 18 from features_bundle import FeaturesBundle |
| 18 from file_system import FileNotFoundError | 19 from file_system import FileNotFoundError |
| 19 from future import Future | 20 from future import Future |
| 20 from object_store_creator import ObjectStoreCreator | 21 from object_store_creator import ObjectStoreCreator |
| 21 from server_instance import ServerInstance | 22 from server_instance import ServerInstance |
| 22 from test_data.canned_data import (CANNED_API_FILE_SYSTEM_DATA, CANNED_BRANCHES) | 23 from test_data.canned_data import (CANNED_API_FILE_SYSTEM_DATA, CANNED_BRANCHES) |
| 23 from test_data.api_data_source.canned_trunk_fs import CANNED_TRUNK_FS_DATA | 24 from test_data.api_data_source.canned_trunk_fs import CANNED_TRUNK_FS_DATA |
| 24 from test_file_system import TestFileSystem | 25 from test_file_system import TestFileSystem |
| 25 from test_util import Server2Path | 26 from test_util import Server2Path |
| 26 from third_party.json_schema_compiler.memoize import memoize | 27 from third_party.json_schema_compiler.memoize import memoize |
| 27 | 28 |
| 28 | 29 |
| 29 def _MakeLink(href, text): | 30 def _MakeLink(href, text): |
| 30 return '<a href="%s">%s</a>' % (href, text) | 31 return '<a href="%s">%s</a>' % (href, text) |
| 31 | 32 |
| 32 | 33 |
| 33 def _GetType(dict_, name): | 34 def _GetType(dict_, name): |
| 34 for type_ in dict_['types']: | 35 for type_ in dict_['types']: |
| 35 if type_['name'] == name: | 36 if type_['name'] == name: |
| 36 return type_ | 37 return type_ |
| 37 | 38 |
| 38 | 39 |
| 39 class _FakeAvailabilityFinder(object): | 40 class _FakeAvailabilityFinder(object): |
| 40 | 41 |
| 41 def GetApiAvailability(self, version): | 42 def GetApiAvailability(self, version): |
| 42 return ChannelInfo('stable', '396', 5) | 43 return AvailabilityInfo(ChannelInfo('stable', '396', 5)) |
| 44 | |
| 45 | |
| 46 class _FakeScheduledAvailabilityFinder(object): | |
| 47 | |
| 48 def GetApiAvailability(self, version): | |
| 49 return AvailabilityInfo(ChannelInfo('dev', '1500', 28), 28) | |
|
not at google - send to devlin
2014/04/29 00:19:43
use a different 'version' and 'scheduled' just to
danielj41
2014/04/30 21:07:11
Done.
| |
| 43 | 50 |
| 44 | 51 |
| 45 class _FakeTemplateCache(object): | 52 class _FakeTemplateCache(object): |
| 46 | 53 |
| 47 def GetFromFile(self, key): | 54 def GetFromFile(self, key): |
| 48 return Future(value='handlebar %s' % key) | 55 return Future(value='handlebar %s' % key) |
| 49 | 56 |
| 50 | 57 |
| 51 class APIDataSourceTest(unittest.TestCase): | 58 class APIDataSourceTest(unittest.TestCase): |
| 52 | 59 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 None).ToDict() | 109 None).ToDict() |
| 103 self.assertEquals(expected_json, dict_) | 110 self.assertEquals(expected_json, dict_) |
| 104 | 111 |
| 105 def testFormatValue(self): | 112 def testFormatValue(self): |
| 106 self.assertEquals('1,234,567', _FormatValue(1234567)) | 113 self.assertEquals('1,234,567', _FormatValue(1234567)) |
| 107 self.assertEquals('67', _FormatValue(67)) | 114 self.assertEquals('67', _FormatValue(67)) |
| 108 self.assertEquals('234,567', _FormatValue(234567)) | 115 self.assertEquals('234,567', _FormatValue(234567)) |
| 109 | 116 |
| 110 def testGetApiAvailability(self): | 117 def testGetApiAvailability(self): |
| 111 api_availabilities = { | 118 api_availabilities = { |
| 112 'bluetooth': ChannelInfo('dev', CANNED_BRANCHES[28], 28), | 119 'bluetooth': AvailabilityInfo( |
| 113 'contextMenus': ChannelInfo('trunk', CANNED_BRANCHES['trunk'], 'trunk'), | 120 ChannelInfo('dev', CANNED_BRANCHES[28], 28)), |
| 114 'jsonStableAPI': ChannelInfo('stable', CANNED_BRANCHES[20], 20), | 121 'contextMenus': AvailabilityInfo( |
| 115 'idle': ChannelInfo('stable', CANNED_BRANCHES[5], 5), | 122 ChannelInfo('trunk', CANNED_BRANCHES['trunk'], 'trunk')), |
| 116 'input.ime': ChannelInfo('stable', CANNED_BRANCHES[18], 18), | 123 'jsonStableAPI': AvailabilityInfo( |
| 117 'tabs': ChannelInfo('stable', CANNED_BRANCHES[18], 18) | 124 ChannelInfo('stable', CANNED_BRANCHES[20], 20)), |
| 125 'idle': AvailabilityInfo( | |
| 126 ChannelInfo('stable', CANNED_BRANCHES[5], 5)), | |
| 127 'input.ime': AvailabilityInfo( | |
| 128 ChannelInfo('stable', CANNED_BRANCHES[18], 18)), | |
| 129 'tabs': AvailabilityInfo( | |
| 130 ChannelInfo('stable', CANNED_BRANCHES[18], 18)) | |
| 118 } | 131 } |
| 119 for api_name, availability in api_availabilities.iteritems(): | 132 for api_name, availability in api_availabilities.iteritems(): |
| 120 model = _JSCModel(self._avail_api_models.GetModel(api_name).Get(), | 133 model = _JSCModel(self._avail_api_models.GetModel(api_name).Get(), |
| 121 self._avail_finder, | 134 self._avail_finder, |
| 122 self._avail_json_cache, | 135 self._avail_json_cache, |
| 123 _FakeTemplateCache(), | 136 _FakeTemplateCache(), |
| 124 self._features_bundle, | 137 self._features_bundle, |
| 125 None) | 138 None) |
| 126 self.assertEquals(availability, model._GetApiAvailability()) | 139 self.assertEquals(availability, model._GetApiAvailability()) |
| 127 | 140 |
| 128 def testGetIntroList(self): | 141 def testGetIntroList(self): |
| 129 model = _JSCModel(self._api_models.GetModel('tester').Get(), | 142 model = _JSCModel(self._api_models.GetModel('tester').Get(), |
| 130 _FakeAvailabilityFinder(), | 143 _FakeAvailabilityFinder(), |
| 131 self._json_cache, | 144 self._json_cache, |
| 132 _FakeTemplateCache(), | 145 _FakeTemplateCache(), |
| 133 self._features_bundle, | 146 self._features_bundle, |
| 134 None) | 147 None) |
| 135 expected_list = [ | 148 expected_list = [ |
| 136 { 'title': 'Description', | 149 { 'title': 'Description', |
| 137 'content': [ | 150 'content': [ |
| 138 { 'text': 'a test api' } | 151 { 'text': 'a test api' } |
| 139 ] | 152 ] |
| 140 }, | 153 }, |
| 141 { 'title': 'Availability', | 154 { 'title': 'Availability', |
| 142 'content': [ | 155 'content': [ |
| 143 { 'partial': 'handlebar chrome/common/extensions/docs/' + | 156 { 'partial': 'handlebar chrome/common/extensions/docs/' + |
| 144 'templates/private/intro_tables/stable_message.html', | 157 'templates/private/intro_tables/stable_message.html', |
| 145 'version': 5 | 158 'version': 5, |
| 159 'scheduled': None | |
| 146 } | 160 } |
| 147 ] | 161 ] |
| 148 }, | 162 }, |
| 149 { 'title': 'Permissions', | 163 { 'title': 'Permissions', |
| 150 'content': [ | 164 'content': [ |
| 151 { 'class': 'override', | 165 { 'class': 'override', |
| 152 'text': '"tester"' | 166 'text': '"tester"' |
| 153 }, | 167 }, |
| 154 { 'text': 'is an API for testing things.' } | 168 { 'text': 'is an API for testing things.' } |
| 155 ] | 169 ] |
| 156 }, | 170 }, |
| 157 { 'title': 'Manifest', | 171 { 'title': 'Manifest', |
| 158 'content': [ | 172 'content': [ |
| 159 { 'class': 'code', | 173 { 'class': 'code', |
| 160 'text': '"tester": {...}' | 174 'text': '"tester": {...}' |
| 161 } | 175 } |
| 162 ] | 176 ] |
| 163 }, | 177 }, |
| 164 { 'title': 'Learn More', | 178 { 'title': 'Learn More', |
| 165 'content': [ | 179 'content': [ |
| 166 { 'link': 'https://tester.test.com/welcome.html', | 180 { 'link': 'https://tester.test.com/welcome.html', |
| 167 'text': 'Welcome!' | 181 'text': 'Welcome!' |
| 168 } | 182 } |
| 169 ] | 183 ] |
| 170 } | 184 } |
| 171 ] | 185 ] |
| 172 self.assertEquals(model._GetIntroTableList(), expected_list) | 186 self.assertEquals(model._GetIntroTableList(), expected_list) |
| 173 | 187 |
| 188 # Tests the same data with a scheduled availability. | |
| 189 model = _JSCModel(self._api_models.GetModel('tester').Get(), | |
| 190 _FakeScheduledAvailabilityFinder(), | |
| 191 self._json_cache, | |
| 192 _FakeTemplateCache(), | |
| 193 self._features_bundle, | |
| 194 None) | |
| 195 expected_list[1] = { | |
| 196 'title': 'Availability', | |
| 197 'content': [ | |
| 198 { 'partial': 'handlebar chrome/common/extensions/docs/' + | |
| 199 'templates/private/intro_tables/dev_message.html', | |
| 200 'version': 28, | |
| 201 'scheduled': 28 | |
| 202 } | |
| 203 ] | |
| 204 } | |
| 205 self.assertEquals(model._GetIntroTableList(), expected_list) | |
| 206 | |
| 174 def testGetEventByNameFromEvents(self): | 207 def testGetEventByNameFromEvents(self): |
| 175 events = {} | 208 events = {} |
| 176 # Missing 'types' completely. | 209 # Missing 'types' completely. |
| 177 self.assertRaises(AssertionError, _GetEventByNameFromEvents, events) | 210 self.assertRaises(AssertionError, _GetEventByNameFromEvents, events) |
| 178 | 211 |
| 179 events['types'] = [] | 212 events['types'] = [] |
| 180 # No type 'Event' defined. | 213 # No type 'Event' defined. |
| 181 self.assertRaises(AssertionError, _GetEventByNameFromEvents, events) | 214 self.assertRaises(AssertionError, _GetEventByNameFromEvents, events) |
| 182 | 215 |
| 183 events['types'].append({ 'name': 'Event', | 216 events['types'].append({ 'name': 'Event', |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 213 # Check that the second event has addListener defined. | 246 # Check that the second event has addListener defined. |
| 214 self.assertEquals('noRules', dict_['events'][1]['name']) | 247 self.assertEquals('noRules', dict_['events'][1]['name']) |
| 215 self.assertEquals('add_rules_tester', dict_['name']) | 248 self.assertEquals('add_rules_tester', dict_['name']) |
| 216 self.assertEquals('noRules', dict_['events'][1]['name']) | 249 self.assertEquals('noRules', dict_['events'][1]['name']) |
| 217 self.assertEquals('callback', | 250 self.assertEquals('callback', |
| 218 dict_['events'][0]['byName']['addListener'][ | 251 dict_['events'][0]['byName']['addListener'][ |
| 219 'parameters'][0]['name']) | 252 'parameters'][0]['name']) |
| 220 | 253 |
| 221 if __name__ == '__main__': | 254 if __name__ == '__main__': |
| 222 unittest.main() | 255 unittest.main() |
| OLD | NEW |