| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 unittest | 8 import unittest |
| 9 | 9 |
| 10 from jsc_view import GetEventByNameFromEvents | 10 from jsc_view import GetEventByNameFromEvents |
| 11 from api_schema_graph import APISchemaGraph | 11 from api_schema_graph import APISchemaGraph |
| 12 from availability_finder import AvailabilityFinder, AvailabilityInfo | 12 from availability_finder import AvailabilityFinder, AvailabilityInfo |
| 13 from branch_utility import BranchUtility, ChannelInfo | 13 from branch_utility import BranchUtility, ChannelInfo |
| 14 from compiled_file_system import CompiledFileSystem | 14 from compiled_file_system import CompiledFileSystem |
| 15 from extensions_paths import CHROME_EXTENSIONS | 15 from extensions_paths import CHROME_EXTENSIONS |
| 16 from fake_host_file_system_provider import FakeHostFileSystemProvider | 16 from fake_host_file_system_provider import FakeHostFileSystemProvider |
| 17 from fake_url_fetcher import FakeUrlFetcher | 17 from fake_url_fetcher import FakeUrlFetcher |
| 18 from features_bundle import FeaturesBundle | 18 from features_bundle import FeaturesBundle |
| 19 from future import Future | 19 from future import Future |
| 20 from host_file_system_iterator import HostFileSystemIterator | 20 from host_file_system_iterator import HostFileSystemIterator |
| 21 from jsc_view import JSCView, _FormatValue | 21 from jsc_view import CreateJSCView, _JSCViewBuilder, _FormatValue |
| 22 from object_store_creator import ObjectStoreCreator | 22 from object_store_creator import ObjectStoreCreator |
| 23 from schema_processor import SchemaProcessorFactoryForTest | 23 from schema_processor import SchemaProcessorFactoryForTest |
| 24 from servlet import Request |
| 24 from server_instance import ServerInstance | 25 from server_instance import ServerInstance |
| 25 from test_data.api_data_source.canned_master_fs import CANNED_MASTER_FS_DATA | 26 from test_data.api_data_source.canned_master_fs import CANNED_MASTER_FS_DATA |
| 26 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA | 27 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA |
| 27 from test_data.object_level_availability.tabs import TABS_SCHEMA_BRANCHES | 28 from test_data.object_level_availability.tabs import TABS_SCHEMA_BRANCHES |
| 28 from test_file_system import TestFileSystem | 29 from test_file_system import TestFileSystem |
| 29 from test_util import Server2Path | 30 from test_util import Server2Path |
| 30 | 31 |
| 31 | 32 |
| 32 class _FakeTemplateCache(object): | 33 class _FakeTemplateCache(object): |
| 33 | 34 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 events['types'][0]['functions'].append(add_rules) | 112 events['types'][0]['functions'].append(add_rules) |
| 112 self.assertEqual(add_rules, | 113 self.assertEqual(add_rules, |
| 113 GetEventByNameFromEvents(events)['addRules']) | 114 GetEventByNameFromEvents(events)['addRules']) |
| 114 | 115 |
| 115 events['types'][0]['functions'].append(add_rules) | 116 events['types'][0]['functions'].append(add_rules) |
| 116 # Duplicates are an error. | 117 # Duplicates are an error. |
| 117 self.assertRaises(AssertionError, GetEventByNameFromEvents, events) | 118 self.assertRaises(AssertionError, GetEventByNameFromEvents, events) |
| 118 | 119 |
| 119 def testCreateId(self): | 120 def testCreateId(self): |
| 120 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 121 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
| 121 dict_ = JSCView(self._api_models.GetContentScriptAPIs().Get(), | 122 dict_ = CreateJSCView( |
| 122 self._api_models.GetModel('tester').Get(), | 123 self._api_models.GetContentScriptAPIs().Get(), |
| 123 fake_avail_finder, | 124 self._api_models.GetModel('tester').Get(), |
| 124 self._json_cache, | 125 fake_avail_finder, |
| 125 _FakeTemplateCache(), | 126 self._json_cache, |
| 126 self._features_bundle, | 127 _FakeTemplateCache(), |
| 127 None, | 128 self._features_bundle, |
| 128 'extensions').ToDict() | 129 None, |
| 130 'extensions', |
| 131 [], |
| 132 Request.ForTest('')) |
| 129 self.assertEquals('type-TypeA', dict_['types'][0]['id']) | 133 self.assertEquals('type-TypeA', dict_['types'][0]['id']) |
| 130 self.assertEquals('property-TypeA-b', | 134 self.assertEquals('property-TypeA-b', |
| 131 dict_['types'][0]['properties'][0]['id']) | 135 dict_['types'][0]['properties'][0]['id']) |
| 132 self.assertEquals('method-get', dict_['functions'][0]['id']) | 136 self.assertEquals('method-get', dict_['functions'][0]['id']) |
| 133 self.assertEquals('event-EventA', dict_['events'][0]['id']) | 137 self.assertEquals('event-EventA', dict_['events'][0]['id']) |
| 134 | 138 |
| 135 # TODO(kalman): re-enable this when we have a rebase option. | 139 # TODO(kalman): re-enable this when we have a rebase option. |
| 136 def DISABLED_testToDict(self): | 140 def DISABLED_testToDict(self): |
| 137 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 141 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
| 138 expected_json = self._LoadJSON('expected_tester.json') | 142 expected_json = self._LoadJSON('expected_tester.json') |
| 139 dict_ = JSCView(self._api_models.GetContentScriptAPIs().Get(), | 143 dict_ = CreateJSCView( |
| 140 self._api_models.GetModel('tester').Get(), | 144 self._api_models.GetContentScriptAPIs().Get(), |
| 141 fake_avail_finder, | 145 self._api_models.GetModel('tester').Get(), |
| 142 self._json_cache, | 146 fake_avail_finder, |
| 143 _FakeTemplateCache(), | 147 self._json_cache, |
| 144 self._features_bundle, | 148 _FakeTemplateCache(), |
| 145 None, | 149 self._features_bundle, |
| 146 'extensions').ToDict() | 150 None, |
| 151 'extensions', |
| 152 [], |
| 153 Request.ForTest('')) |
| 147 self.assertEquals(expected_json, dict_) | 154 self.assertEquals(expected_json, dict_) |
| 148 | 155 |
| 149 def testAddRules(self): | 156 def testAddRules(self): |
| 150 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 157 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
| 151 dict_ = JSCView(self._api_models.GetContentScriptAPIs().Get(), | 158 dict_ = CreateJSCView( |
| 152 self._api_models.GetModel('add_rules_tester').Get(), | 159 self._api_models.GetContentScriptAPIs().Get(), |
| 153 fake_avail_finder, | 160 self._api_models.GetModel('add_rules_tester').Get(), |
| 154 self._json_cache, | 161 fake_avail_finder, |
| 155 _FakeTemplateCache(), | 162 self._json_cache, |
| 156 self._features_bundle, | 163 _FakeTemplateCache(), |
| 157 self._FakeLoadAddRulesSchema(), | 164 self._features_bundle, |
| 158 'extensions').ToDict() | 165 self._FakeLoadAddRulesSchema(), |
| 166 'extensions', |
| 167 [], |
| 168 Request.ForTest('')) |
| 159 | 169 |
| 160 # Check that the first event has the addRulesFunction defined. | 170 # Check that the first event has the addRulesFunction defined. |
| 161 self.assertEquals('add_rules_tester', dict_['name']) | 171 self.assertEquals('add_rules_tester', dict_['name']) |
| 162 self.assertEquals('rules', dict_['events'][0]['name']) | 172 self.assertEquals('rules', dict_['events'][0]['name']) |
| 163 self.assertEquals('notable_name_to_check_for', | 173 self.assertEquals('notable_name_to_check_for', |
| 164 dict_['events'][0]['byName']['addRules'][ | 174 dict_['events'][0]['byName']['addRules'][ |
| 165 'parameters'][0]['name']) | 175 'parameters'][0]['name']) |
| 166 | 176 |
| 167 # Check that the second event has addListener defined. | 177 # Check that the second event has addListener defined. |
| 168 self.assertEquals('noRules', dict_['events'][1]['name']) | 178 self.assertEquals('noRules', dict_['events'][1]['name']) |
| 169 self.assertEquals('add_rules_tester', dict_['name']) | 179 self.assertEquals('add_rules_tester', dict_['name']) |
| 170 self.assertEquals('noRules', dict_['events'][1]['name']) | 180 self.assertEquals('noRules', dict_['events'][1]['name']) |
| 171 self.assertEquals('callback', | 181 self.assertEquals('callback', |
| 172 dict_['events'][0]['byName']['addListener'][ | 182 dict_['events'][0]['byName']['addListener'][ |
| 173 'parameters'][0]['name']) | 183 'parameters'][0]['name']) |
| 174 | 184 |
| 175 def testGetIntroList(self): | 185 def testGetIntroList(self): |
| 176 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 186 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
| 177 model = JSCView(self._api_models.GetContentScriptAPIs().Get(), | 187 model = _JSCViewBuilder( |
| 178 self._api_models.GetModel('tester').Get(), | 188 self._api_models.GetContentScriptAPIs().Get(), |
| 179 fake_avail_finder, | 189 self._api_models.GetModel('tester').Get(), |
| 180 self._json_cache, | 190 fake_avail_finder, |
| 181 _FakeTemplateCache(), | 191 self._json_cache, |
| 182 self._features_bundle, | 192 _FakeTemplateCache(), |
| 183 None, | 193 self._features_bundle, |
| 184 'extensions') | 194 None, |
| 195 'extensions', |
| 196 []) |
| 185 expected_list = [ | 197 expected_list = [ |
| 186 { 'title': 'Description', | 198 { 'title': 'Description', |
| 187 'content': [ | 199 'content': [ |
| 188 { 'text': 'a test api' } | 200 { 'text': 'a test api' } |
| 189 ] | 201 ] |
| 190 }, | 202 }, |
| 191 { 'title': 'Availability', | 203 { 'title': 'Availability', |
| 192 'content': [ | 204 'content': [ |
| 193 { 'partial': 'motemplate chrome/common/extensions/docs/' + | 205 { 'partial': 'motemplate chrome/common/extensions/docs/' + |
| 194 'templates/private/intro_tables/stable_message.html', | 206 'templates/private/intro_tables/stable_message.html', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 'text': 'Welcome!' | 242 'text': 'Welcome!' |
| 231 } | 243 } |
| 232 ] | 244 ] |
| 233 } | 245 } |
| 234 ] | 246 ] |
| 235 self.assertEquals(model._GetIntroTableList(), expected_list) | 247 self.assertEquals(model._GetIntroTableList(), expected_list) |
| 236 | 248 |
| 237 # Tests the same data with a scheduled availability. | 249 # Tests the same data with a scheduled availability. |
| 238 fake_avail_finder = _FakeAvailabilityFinder( | 250 fake_avail_finder = _FakeAvailabilityFinder( |
| 239 AvailabilityInfo(ChannelInfo('beta', '1453', 27), scheduled=28)) | 251 AvailabilityInfo(ChannelInfo('beta', '1453', 27), scheduled=28)) |
| 240 model = JSCView(self._api_models.GetContentScriptAPIs().Get(), | 252 model = _JSCViewBuilder( |
| 241 self._api_models.GetModel('tester').Get(), | 253 self._api_models.GetContentScriptAPIs().Get(), |
| 242 fake_avail_finder, | 254 self._api_models.GetModel('tester').Get(), |
| 243 self._json_cache, | 255 fake_avail_finder, |
| 244 _FakeTemplateCache(), | 256 self._json_cache, |
| 245 self._features_bundle, | 257 _FakeTemplateCache(), |
| 246 None, | 258 self._features_bundle, |
| 247 'extensions') | 259 None, |
| 260 'extensions', |
| 261 []) |
| 248 expected_list[1] = { | 262 expected_list[1] = { |
| 249 'title': 'Availability', | 263 'title': 'Availability', |
| 250 'content': [ | 264 'content': [ |
| 251 { 'partial': 'motemplate chrome/common/extensions/docs/' + | 265 { 'partial': 'motemplate chrome/common/extensions/docs/' + |
| 252 'templates/private/intro_tables/beta_message.html', | 266 'templates/private/intro_tables/beta_message.html', |
| 253 'version': 27, | 267 'version': 27, |
| 254 'scheduled': 28 | 268 'scheduled': 28 |
| 255 } | 269 } |
| 256 ] | 270 ] |
| 257 } | 271 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 274 def testGetAPIAvailability(self): | 288 def testGetAPIAvailability(self): |
| 275 api_availabilities = { | 289 api_availabilities = { |
| 276 'bluetooth': 31, | 290 'bluetooth': 31, |
| 277 'contextMenus': 'master', | 291 'contextMenus': 'master', |
| 278 'jsonStableAPI': 20, | 292 'jsonStableAPI': 20, |
| 279 'idle': 5, | 293 'idle': 5, |
| 280 'input.ime': 18, | 294 'input.ime': 18, |
| 281 'tabs': 18 | 295 'tabs': 18 |
| 282 } | 296 } |
| 283 for api_name, availability in api_availabilities.iteritems(): | 297 for api_name, availability in api_availabilities.iteritems(): |
| 284 model_dict = JSCView( | 298 model_dict = CreateJSCView( |
| 285 self._api_models.GetContentScriptAPIs().Get(), | 299 self._api_models.GetContentScriptAPIs().Get(), |
| 286 self._api_models.GetModel(api_name).Get(), | 300 self._api_models.GetModel(api_name).Get(), |
| 287 self._avail_finder, | 301 self._avail_finder, |
| 288 self._json_cache, | 302 self._json_cache, |
| 289 _FakeTemplateCache(), | 303 _FakeTemplateCache(), |
| 290 _FakeFeaturesBundle(), | 304 _FakeFeaturesBundle(), |
| 291 None, | 305 None, |
| 292 'extensions').ToDict() | 306 'extensions', |
| 307 [], |
| 308 Request.ForTest('')) |
| 293 self.assertEquals(availability, | 309 self.assertEquals(availability, |
| 294 model_dict['introList'][1]['content'][0]['version']) | 310 model_dict['introList'][1]['content'][0]['version']) |
| 295 | 311 |
| 296 | 312 |
| 297 class JSCViewWithNodeAvailabilityTest(unittest.TestCase): | 313 class JSCViewWithNodeAvailabilityTest(unittest.TestCase): |
| 298 def setUp(self): | 314 def setUp(self): |
| 299 tabs_unmodified_versions = (16, 20, 23, 24) | 315 tabs_unmodified_versions = (16, 20, 23, 24) |
| 300 self._branch_utility = BranchUtility( | 316 self._branch_utility = BranchUtility( |
| 301 os.path.join('branch_utility', 'first.json'), | 317 os.path.join('branch_utility', 'first.json'), |
| 302 os.path.join('branch_utility', 'second.json'), | 318 os.path.join('branch_utility', 'second.json'), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 'tabs.fakeTabsProperty1': None, | 366 'tabs.fakeTabsProperty1': None, |
| 351 'tabs.get': None, | 367 'tabs.get': None, |
| 352 'tabs.onUpdated': None, | 368 'tabs.onUpdated': None, |
| 353 'tabs.InjectDetails': 25, | 369 'tabs.InjectDetails': 25, |
| 354 'tabs.fakeTabsProperty2': 15, | 370 'tabs.fakeTabsProperty2': 15, |
| 355 'tabs.getCurrent': 19, | 371 'tabs.getCurrent': 19, |
| 356 'tabs.onActivated': 30 | 372 'tabs.onActivated': 30 |
| 357 } | 373 } |
| 358 self.assertEquals(node_availabilities[node], actual) | 374 self.assertEquals(node_availabilities[node], actual) |
| 359 | 375 |
| 360 model_dict = JSCView( | 376 model_dict = CreateJSCView( |
| 361 self._api_models.GetContentScriptAPIs().Get(), | 377 self._api_models.GetContentScriptAPIs().Get(), |
| 362 self._api_models.GetModel('tabs').Get(), | 378 self._api_models.GetModel('tabs').Get(), |
| 363 self._avail_finder, | 379 self._avail_finder, |
| 364 self._json_cache, | 380 self._json_cache, |
| 365 _FakeTemplateCache(), | 381 _FakeTemplateCache(), |
| 366 _FakeFeaturesBundle(), | 382 _FakeFeaturesBundle(), |
| 367 None, | 383 None, |
| 368 'extensions').ToDict() | 384 'extensions', |
| 385 [], |
| 386 Request.ForTest('')) |
| 369 | 387 |
| 370 # Test nodes that have the same availability as their parent. | 388 # Test nodes that have the same availability as their parent. |
| 371 | 389 |
| 372 # Test type. | 390 # Test type. |
| 373 assertEquals('tabs.Tab', model_dict['types'][0]['availability']) | 391 assertEquals('tabs.Tab', model_dict['types'][0]['availability']) |
| 374 # Test property. | 392 # Test property. |
| 375 assertEquals('tabs.fakeTabsProperty1', | 393 assertEquals('tabs.fakeTabsProperty1', |
| 376 model_dict['properties'][0]['availability']) | 394 model_dict['properties'][0]['availability']) |
| 377 # Test function. | 395 # Test function. |
| 378 assertEquals('tabs.get', model_dict['functions'][1]['availability']) | 396 assertEquals('tabs.get', model_dict['functions'][1]['availability']) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 397 # Test a node that became deprecated. | 415 # Test a node that became deprecated. |
| 398 self.assertEquals({ | 416 self.assertEquals({ |
| 399 'scheduled': None, | 417 'scheduled': None, |
| 400 'version': 26, | 418 'version': 26, |
| 401 'partial': 'motemplate chrome/common/extensions/docs/templates/' + | 419 'partial': 'motemplate chrome/common/extensions/docs/templates/' + |
| 402 'private/intro_tables/deprecated_message.html' | 420 'private/intro_tables/deprecated_message.html' |
| 403 }, model_dict['types'][2]['availability']) | 421 }, model_dict['types'][2]['availability']) |
| 404 | 422 |
| 405 if __name__ == '__main__': | 423 if __name__ == '__main__': |
| 406 unittest.main() | 424 unittest.main() |
| OLD | NEW |