Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / features_utility_test.py
blob5dcfdd8062460d9cae870c71eea3266e1568f70d
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.
6 import unittest
8 from features_utility import Parse, Filtered, MergedWith
10 class FeaturesUtilityTest(unittest.TestCase):
11 def testFromJson(self):
12 raw_features_json = {
13 'doc1': {
14 'extension_types': ['extension', 'platform_app']
16 'doc2': {
17 'extension_types': ['hosted_app', 'packaged_app']
19 'doc3': {
20 'whitelist': 'hashhashashhashashhashashhash'
22 'doc4': [
23 { 'extension_types': 'all' },
24 { 'whitelist': 'hashhashashhashashhashashhash' }
26 'doc5': {
27 'extension_types': ['extension']
29 'doc1.sub1': {
30 'extension_types': ['platform_app', 'hosted_app', 'packaged_app']
34 expected = {
35 'doc1': {
36 'platforms': ['apps', 'extensions'],
37 'name': 'doc1'
39 'doc2': {
40 'platforms': [],
41 'name': 'doc2'
43 'doc4': {
44 'platforms': ['apps', 'extensions'],
45 'name': 'doc4'
47 'doc5': {
48 'platforms': ['extensions'],
49 'name': 'doc5'
51 'doc1.sub1': {
52 'platforms': ['apps'],
53 'name': 'doc1.sub1'
57 self.assertEqual(expected, Parse(raw_features_json))
59 def testFilter(self):
60 unfiltered = {
61 'doc1': { 'platforms': ['apps'] },
62 'doc2': { 'platforms': ['extensions'] },
63 'doc3': { 'platforms': ['apps', 'extensions'] },
64 'doc4': { 'platforms': [] }
67 apps_names = set(('doc1', 'doc3'))
68 extension_names = set(('doc2', 'doc3'))
70 self.assertEqual(
71 apps_names, set(Filtered(unfiltered, 'apps').keys()))
72 self.assertEqual(
73 extension_names, set(Filtered(unfiltered, 'extensions').keys()))
75 def testMergeFeatures(self):
76 features = {
77 'doc1': {
78 'platforms': ['apps']
80 'doc3': {
81 'name': 'doc3'
85 other = {
86 'doc1': {
87 'name': 'doc1',
88 'platforms': ['extensions']
90 'doc2': {
91 'name': 'doc2'
93 'doc3': {
94 'platforms': ['extensions', 'apps']
98 expected = {
99 'doc1': {
100 'name': 'doc1',
101 'platforms': ['extensions']
103 'doc2': {
104 'name': 'doc2',
105 'platforms': []
107 'doc3': {
108 'name': 'doc3',
109 'platforms': ['extensions', 'apps']
113 self.assertEqual(expected, MergedWith(features, other))
115 if __name__ == '__main__':
116 unittest.main()