1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
import unittest
from extensions_paths import CHROME_API, CHROME_EXTENSIONS
from mock_file_system import MockFileSystem
from server_instance import ServerInstance
from test_file_system import TestFileSystem
from test_util import ReadFile
_TEST_DATA = {
'api': {
'devtools': {
'inspected_window.json': ReadFile(
CHROME_API, 'devtools', 'inspected_window.json'),
},
'_api_features.json': json.dumps({
'alarms': {},
'app': {'extension_types': ['platform_app']},
'app.runtime': {'noparent': True},
'app.runtime.foo': {'extension_types': ['extension']},
'declarativeWebRequest': {'extension_types': ['extension']},
'devtools.inspectedWindow': {'extension_types': ['extension']},
'input': {'extension_types': 'all'},
'input.ime': {'extension_types': ['extension', 'platform_app']},
'storage': {'extension_types': ['extension']},
}),
'_manifest_features.json': '{}',
'_permission_features.json': '{}',
'alarms.idl': ReadFile(CHROME_API, 'alarms.idl'),
'input_ime.json': ReadFile(CHROME_API, 'input_ime.json'),
'page_action.json': ReadFile(CHROME_API, 'page_action.json'),
},
'docs': {
'templates': {
'json': {
'manifest.json': '{}',
'permissions.json': '{}',
}
}
},
}
class PlatformBundleTest(unittest.TestCase):
def setUp(self):
mock_file_system = MockFileSystem(
TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS))
server_instance = ServerInstance.ForTest(file_system=mock_file_system)
self._platform_bundle = server_instance.platform_bundle
def testGetters(self):
self.assertEqual([
'alarms',
'app.runtime',
'declarativeWebRequest',
'devtools.inspectedWindow',
'input',
'storage'
], sorted(self._platform_bundle.GetAPIModels('extensions').GetNames()))
self.assertEqual([
'alarms',
'app',
'app.runtime',
'input'
], sorted(self._platform_bundle.GetAPIModels('apps').GetNames()))
self.assertEqual({
'app.runtime': {
'name': 'app.runtime',
'noparent': True,
'channel': 'stable'
},
'declarativeWebRequest': {
'name': 'declarativeWebRequest',
'channel': 'stable',
'extension_types': ['extension'],
},
'app.runtime.foo': {
'name': 'app.runtime.foo',
'channel': 'stable',
'extension_types': ['extension'],
},
'storage': {
'name': 'storage',
'channel': 'stable',
'extension_types': ['extension'],
},
'input.ime': {
'name': 'input.ime',
'channel': 'stable',
'extension_types': ['extension', 'platform_app'],
},
'alarms': {
'name': 'alarms',
'channel': 'stable'
},
'input': {
'name': 'input',
'channel': 'stable',
'extension_types': 'all'
},
'devtools.inspectedWindow': {
'name': 'devtools.inspectedWindow',
'channel': 'stable',
'extension_types': ['extension'],
}
}, self._platform_bundle.GetFeaturesBundle(
'extensions').GetAPIFeatures().Get())
self.assertEqual({
'app.runtime': {
'name': 'app.runtime',
'noparent': True,
'channel': 'stable'
},
'input': {
'name': 'input',
'channel': 'stable',
'extension_types': 'all'
},
'input.ime': {
'name': 'input.ime',
'channel': 'stable',
'extension_types': ['extension', 'platform_app'],
},
'app': {
'name': 'app',
'channel': 'stable',
'extension_types': ['platform_app'],
},
'alarms': {
'name': 'alarms',
'channel': 'stable'
}
}, self._platform_bundle.GetFeaturesBundle('apps').GetAPIFeatures().Get())
# Check that 'app' is resolved successfully in apps, but is None otherwise.
self.assertNotEqual(
None,
self._platform_bundle.GetReferenceResolver('apps').GetLink('app'))
self.assertEqual(
None,
self._platform_bundle.GetReferenceResolver('extensions').GetLink('app'))
if __name__ == '__main__':
unittest.main()
|