Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(909)

Side by Side Diff: chrome/common/extensions/docs/server2/permissions_data_source_test.py

Issue 23867003: Docserver: Consolidate features caching and access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: let's try this again, shall we? Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 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 unittest 7 import unittest
8 8
9 from compiled_file_system import CompiledFileSystem 9 from compiled_file_system import CompiledFileSystem
10 from features_bundle import FeaturesBundle
10 from object_store_creator import ObjectStoreCreator 11 from object_store_creator import ObjectStoreCreator
11 from permissions_data_source import PermissionsDataSource 12 from permissions_data_source import PermissionsDataSource
12 from test_file_system import TestFileSystem 13 from test_file_system import TestFileSystem
13 14
14 class FakeTemplateDataSource(object): 15 class _FakeTemplateDataSource(object):
15 class Factory(): 16 class Factory():
16 def Create(self, *args): 17 def Create(self, *args):
17 return FakeTemplateDataSource() 18 return _FakeTemplateDataSource()
18 def get(self, key): 19 def get(self, key):
19 return 'partial ' + key 20 return 'partial ' + key
20 21
21 file_system = TestFileSystem({ 22
22 'permissions.json': json.dumps({ 23 _TEST_PERMISSION_FEATURES = {
23 'host-permissions': { 24 'host-permissions': {
24 'name': 'match pattern', 25 'name': 'match pattern',
25 'anchor': 'custom-anchor', 26 'anchor': 'custom-anchor',
26 'platforms': ['app', 'extension'], 27 'platforms': ['apps', 'extensions'],
27 'partial': 'host_permissions.html', 28 'partial': 'host_permissions.html',
28 'literal_name': True 29 'literal_name': True
29 }, 30 },
30 'activeTab': { 31 'activeTab': {
31 'partial': 'active_tab.html' 32 'name': 'activeTab',
32 }, 33 'platforms': ['extensions'],
33 'alarms': { 34 'partial': 'active_tab.html'
34 'partial': 'alarms.html' 35 },
35 }, 36 'alarms': {
36 'audioCapture': { 37 'name': 'alarms',
37 'partial': 'audio_capture.html' 38 'platforms': ['apps', 'extensions'],
38 }, 39 'partial': 'alarms.html'
39 'background': { 40 },
40 'partial': 'background.html' 41 'audioCapture': {
41 } 42 'name': 'audioCapture',
42 }), 43 'platforms': ['apps'],
43 '_permission_features.json': json.dumps({ 44 'partial': 'audio_capture.html'
44 'activeTab': { 45 },
45 'extension_types': ['extension', 'packaged_app'], 46 'background': {
46 }, 47 'name': 'background',
47 'alarms': { 48 'platforms': ['extensions'],
48 'extension_types': ['extension', 'packaged_app', 'platform_app'], 49 'partial': 'background.html'
49 }, 50 },
50 'audioCapture': { 51 'commandLinePrivate': {
51 'extension_types': ['platform_app'] 52 'name': 'commandLinePrivate',
52 }, 53 'platforms': ['apps', 'extensions']
53 'background': { 54 },
54 'extension_types': ['extension', 'packaged_app', 'hosted_app'] 55 'cookies': {
55 }, 56 'name': 'cookies',
56 'commandLinePrivate': { 57 'platforms': ['apps']
57 'extension_types': 'all' 58 }
58 }, 59 }
59 'cookies': { 60
60 'extension_types': ['platform_app'] 61 _TEST_API_FEATURES = {
61 } 62 'cookies': {
62 }), 63 'dependencies': ['permission:cookies']
63 '_api_features.json': json.dumps({ 64 },
64 'cookies': { 65 'alarms': {
65 'dependencies': ['permission:cookies'] 66 'dependencies': ['permission:alarms']
66 }, 67 }
67 'alarms': { 68 }
68 'dependencies': ['permission:alarms'] 69
69 } 70
70 }) 71 class _FakeFeaturesBundle(object):
71 }) 72 def GetAPIFeatures(self):
73 return _TEST_API_FEATURES
74
75 def GetPermissionFeatures(self):
76 return _TEST_PERMISSION_FEATURES
77
78
79 class _FakeServerInstance(object):
80 def __init__(self):
81 self.features_bundle = _FakeFeaturesBundle()
82 self.object_store_creator = ObjectStoreCreator.ForTest()
83
72 84
73 class PermissionsDataSourceTest(unittest.TestCase): 85 class PermissionsDataSourceTest(unittest.TestCase):
74 def testCreatePermissionsDataSource(self): 86 def testCreatePermissionsDataSource(self):
75 expected_extensions = [ 87 expected_extensions = [
76 { 88 {
77 'name': 'activeTab', 89 'name': 'activeTab',
78 'anchor': 'activeTab', 90 'anchor': 'activeTab',
79 'platforms': ['extension'], 91 'platforms': ['extensions'],
80 'description': 'partial active_tab.html' 92 'description': 'partial active_tab.html'
81 }, 93 },
82 { 94 {
83 'name': 'alarms', 95 'name': 'alarms',
84 'anchor': 'alarms', 96 'anchor': 'alarms',
85 'platforms': ['app', 'extension'], 97 'platforms': ['apps', 'extensions'],
86 'description': 'partial alarms.html' 98 'description': 'partial alarms.html'
87 }, 99 },
88 { 100 {
89 'name': 'background', 101 'name': 'background',
90 'anchor': 'background', 102 'anchor': 'background',
91 'platforms': ['extension'], 103 'platforms': ['extensions'],
92 'description': 'partial background.html' 104 'description': 'partial background.html'
93 }, 105 },
94 { 106 {
95 'name': 'match pattern', 107 'name': 'match pattern',
96 'anchor': 'custom-anchor', 108 'anchor': 'custom-anchor',
97 'literal_name': True, 109 'literal_name': True,
98 'description': 'partial host_permissions.html', 110 'description': 'partial host_permissions.html',
99 'platforms': ['app', 'extension'] 111 'platforms': ['apps', 'extensions']
100 } 112 }
101 ] 113 ]
102 114
103 expected_apps = [ 115 expected_apps = [
104 { 116 {
105 'name': 'alarms', 117 'name': 'alarms',
106 'anchor': 'alarms', 118 'anchor': 'alarms',
107 'platforms': ['app', 'extension'], 119 'platforms': ['apps', 'extensions'],
108 'description': 'partial alarms.html' 120 'description': 'partial alarms.html'
109 }, 121 },
110 { 122 {
111 'name': 'audioCapture', 123 'name': 'audioCapture',
112 'anchor': 'audioCapture', 124 'anchor': 'audioCapture',
113 'description': 'partial audio_capture.html', 125 'description': 'partial audio_capture.html',
114 'platforms': ['app'] 126 'platforms': ['apps']
115 }, 127 },
116 { 128 {
117 'anchor': 'cookies', 129 'anchor': 'cookies',
118 'name': 'cookies', 130 'name': 'cookies',
119 'description': 'partial permissions/generic_description', 131 'description': 'partial permissions/generic_description',
120 'platforms': ['app'] 132 'platforms': ['apps']
121 }, 133 },
122 { 134 {
123 'name': 'match pattern', 135 'name': 'match pattern',
124 'anchor': 'custom-anchor', 136 'anchor': 'custom-anchor',
125 'literal_name': True, 137 'literal_name': True,
126 'description': 'partial host_permissions.html', 138 'description': 'partial host_permissions.html',
127 'platforms': ['app', 'extension'] 139 'platforms': ['apps', 'extensions']
128 } 140 }
129 ] 141 ]
130 142
131 permissions_data_source = PermissionsDataSource( 143 permissions_data_source = PermissionsDataSource(_FakeServerInstance())
132 CompiledFileSystem.Factory(file_system, ObjectStoreCreator.ForTest()),
133 file_system,
134 '_api_features.json',
135 '_permission_features.json',
136 'permissions.json')
137
138 permissions_data_source.SetTemplateDataSource( 144 permissions_data_source.SetTemplateDataSource(
139 FakeTemplateDataSource.Factory()) 145 _FakeTemplateDataSource.Factory())
140 146
141 self.assertEqual( 147 self.assertEqual(
142 expected_extensions, 148 expected_extensions,
143 permissions_data_source.get('declare_extensions')) 149 permissions_data_source.get('declare_extensions'))
144 self.assertEqual( 150 self.assertEqual(
145 expected_apps, 151 expected_apps,
146 permissions_data_source.get('declare_apps')) 152 permissions_data_source.get('declare_apps'))
147 153
148 if __name__ == '__main__': 154 if __name__ == '__main__':
149 unittest.main() 155 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698