Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / platform_bundle_test.py
blob6a8f4a6209608b487992840ae480ff7eaab01d9e
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 import json
7 import unittest
9 from extensions_paths import CHROME_API, CHROME_EXTENSIONS, EXTENSIONS_API
10 from mock_file_system import MockFileSystem
11 from server_instance import ServerInstance
12 from test_file_system import TestFileSystem
13 from test_util import ReadFile
16 _TEST_DATA = {
17 'api': {
18 'devtools': {
19 'inspected_window.json': ReadFile(
20 CHROME_API, 'devtools', 'inspected_window.json'),
22 '_api_features.json': json.dumps({
23 'alarms': {},
24 'app': {'extension_types': ['platform_app']},
25 'app.runtime': {'noparent': True},
26 'app.runtime.foo': {'extension_types': ['extension']},
27 'declarativeWebRequest': {'extension_types': ['extension']},
28 'devtools.inspectedWindow': {'extension_types': ['extension']},
29 'input': {'extension_types': 'all'},
30 'input.ime': {'extension_types': ['extension', 'platform_app']},
31 'storage': {'extension_types': ['extension']},
32 }),
33 '_manifest_features.json': '{}',
34 '_permission_features.json': '{}',
35 'alarms.idl': ReadFile(EXTENSIONS_API, 'alarms.idl'),
36 'input_ime.json': ReadFile(CHROME_API, 'input_ime.json'),
37 'page_action.json': ReadFile(CHROME_API, 'page_action.json'),
39 'docs': {
40 'templates': {
41 'json': {
42 'manifest.json': '{}',
43 'permissions.json': '{}',
50 class PlatformBundleTest(unittest.TestCase):
51 def setUp(self):
52 mock_file_system = MockFileSystem(
53 TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS))
54 server_instance = ServerInstance.ForTest(file_system=mock_file_system)
55 self._platform_bundle = server_instance.platform_bundle
57 def testGetters(self):
58 self.assertEqual([
59 'alarms',
60 'app.runtime',
61 'declarativeWebRequest',
62 'devtools.inspectedWindow',
63 'input',
64 'storage'
65 ], sorted(self._platform_bundle.GetAPIModels('extensions').GetNames()))
67 self.assertEqual([
68 'alarms',
69 'app',
70 'app.runtime',
71 'input'
72 ], sorted(self._platform_bundle.GetAPIModels('apps').GetNames()))
74 self.assertEqual({
75 'app.runtime': {
76 'name': 'app.runtime',
77 'noparent': True,
78 'channel': 'stable'
80 'declarativeWebRequest': {
81 'name': 'declarativeWebRequest',
82 'channel': 'stable',
83 'extension_types': ['extension'],
85 'app.runtime.foo': {
86 'name': 'app.runtime.foo',
87 'channel': 'stable',
88 'extension_types': ['extension'],
90 'storage': {
91 'name': 'storage',
92 'channel': 'stable',
93 'extension_types': ['extension'],
95 'input.ime': {
96 'name': 'input.ime',
97 'channel': 'stable',
98 'extension_types': ['extension', 'platform_app'],
100 'alarms': {
101 'name': 'alarms',
102 'channel': 'stable'
104 'input': {
105 'name': 'input',
106 'channel': 'stable',
107 'extension_types': 'all'
109 'devtools.inspectedWindow': {
110 'name': 'devtools.inspectedWindow',
111 'channel': 'stable',
112 'extension_types': ['extension'],
114 }, self._platform_bundle.GetFeaturesBundle(
115 'extensions').GetAPIFeatures().Get())
117 self.assertEqual({
118 'app.runtime': {
119 'name': 'app.runtime',
120 'noparent': True,
121 'channel': 'stable'
123 'input': {
124 'name': 'input',
125 'channel': 'stable',
126 'extension_types': 'all'
128 'input.ime': {
129 'name': 'input.ime',
130 'channel': 'stable',
131 'extension_types': ['extension', 'platform_app'],
133 'app': {
134 'name': 'app',
135 'channel': 'stable',
136 'extension_types': ['platform_app'],
138 'alarms': {
139 'name': 'alarms',
140 'channel': 'stable'
142 }, self._platform_bundle.GetFeaturesBundle('apps').GetAPIFeatures().Get())
144 # Check that 'app' is resolved successfully in apps, but is None otherwise.
145 self.assertNotEqual(
146 None,
147 self._platform_bundle.GetReferenceResolver('apps').GetLink('app'))
148 self.assertEqual(
149 None,
150 self._platform_bundle.GetReferenceResolver('extensions').GetLink('app'))
152 if __name__ == '__main__':
153 unittest.main()