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

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

Issue 344453003: Docserver: separate models for apps and extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Quick fixes Created 6 years, 6 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
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import unittest
7
8 from features_utility import Parse, Filtered, MergedWith
9
10
11 class FeaturesUtilityTest(unittest.TestCase):
12 def testFromJson(self):
13 raw_features_json = {
14 'doc1': {
15 'extension_types': ['extension', 'platform_app']
16 },
17 'doc2': {
18 'extension_types': ['hosted_app', 'packaged_app']
19 },
20 'doc3': {
21 'whitelist': 'hashhashashhashashhashashhash'
22 },
23 'doc4': [
24 { 'extension_types': 'all' },
25 { 'whitelist': 'hashhashashhashashhashashhash' }
26 ],
27 'doc5': {
28 'extension_types': ['extension']
29 },
30 'doc1.sub1': {
31 'extension_types': ['platform_app', 'hosted_app', 'packaged_app']
32 }
33 }
34
35 expected = {
36 'doc1': {
37 'platforms': ['apps', 'extensions'],
38 'name': 'doc1'
39 },
40 'doc2': {
41 'platforms': [],
42 'name': 'doc2'
43 },
44 'doc4': {
45 'platforms': ['apps', 'extensions'],
46 'name': 'doc4'
47 },
48 'doc5': {
49 'platforms': ['extensions'],
50 'name': 'doc5'
51 },
52 'doc1.sub1': {
53 'platforms': ['apps'],
54 'name': 'doc1.sub1'
55 }
56 }
57
58 self.assertEqual(expected, Parse(raw_features_json))
59
60 def testFeatureList(self):
61 raw_features_json = {
62 'doc1': [
63 { 'extension_types': ['extension'] },
64 { 'extension_types': ['platform_app'] }
65 ],
66 'doc2': [
67 { 'channel': 'dev', 'extension_types': ['extension', 'platform_app'] },
68 { 'channel': 'stable' }
69 ],
70 'doc3': [
71 { 'channel': 'beta' },
72 { 'channel': 'dev' }
73 ],
74 'doc4': [
75 { 'channel': 'beta' },
76 { 'dependencies': ['permission:perm1'] }
77 ]
78 }
79
80 expected = {
81 'doc1': {
82 'platforms': ['apps', 'extensions'],
83 'name': 'doc1'
84 },
85 'doc2': {
86 'channel': 'stable',
87 'platforms': ['apps', 'extensions'],
88 'name': 'doc2'
89 },
90 'doc3': {
91 'platforms': [],
92 'channel': 'beta',
93 'name': 'doc3'
94 },
95 'doc4': {
96 'platforms': [],
97 'dependencies': ['permission:perm1'],
98 'name': 'doc4'
99 }
100 }
101
102 self.assertEqual(expected, Parse(raw_features_json))
103
104 def testFilter(self):
105 unfiltered = {
106 'doc1': { 'platforms': ['apps'] },
107 'doc2': { 'platforms': ['extensions'] },
108 'doc3': { 'platforms': ['apps', 'extensions'] },
109 'doc4': { 'platforms': [] }
110 }
111
112 apps_names = set(('doc1', 'doc3'))
113 extension_names = set(('doc2', 'doc3'))
114
115 self.assertEqual(sorted(apps_names),
116 sorted(Filtered(unfiltered, 'apps').keys()))
117 self.assertEqual(sorted(extension_names),
118 sorted(Filtered(unfiltered, 'extensions').keys()))
119
120 def testMergeFeatures(self):
121 features = {
122 'doc1': {
123 'platforms': ['apps']
124 },
125 'doc3': {
126 'name': 'doc3'
127 }
128 }
129
130 other = {
131 'doc1': {
132 'name': 'doc1',
133 'platforms': ['extensions']
134 },
135 'doc2': {
136 'name': 'doc2'
137 },
138 'doc3': {
139 'platforms': ['extensions', 'apps']
140 }
141 }
142
143 expected = {
144 'doc1': {
145 'name': 'doc1',
146 'platforms': ['extensions']
147 },
148 'doc2': {
149 'name': 'doc2',
150 'platforms': []
151 },
152 'doc3': {
153 'name': 'doc3',
154 'platforms': ['extensions', 'apps']
155 }
156 }
157
158 self.assertEqual(expected, MergedWith(features, other))
159
160 if __name__ == '__main__':
161 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698