| Index: chrome/common/extensions/docs/server2/features_utility_test.py
|
| diff --git a/chrome/common/extensions/docs/server2/features_utility_test.py b/chrome/common/extensions/docs/server2/features_utility_test.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..eebe3ca6a3a60af6941bbae19b51638a2c3a87ee
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/docs/server2/features_utility_test.py
|
| @@ -0,0 +1,116 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2013 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.
|
| +
|
| +from copy import deepcopy
|
| +import unittest
|
| +
|
| +from features_utility import FeaturesFromJson, Filter, MergeFeatures
|
| +
|
| +class FeaturesUtilityTest(unittest.TestCase):
|
| + def testFromJson(self):
|
| + raw_features_json = {
|
| + 'doc1': {
|
| + 'extension_types': ['extension', 'platform_app']
|
| + },
|
| + 'doc2': {
|
| + 'extension_types': ['hosted_app', 'packaged_app']
|
| + },
|
| + 'doc3': {
|
| + 'whitelist': 'hashhashashhashashhashashhash'
|
| + },
|
| + 'doc4': [
|
| + { 'extension_types': 'all' },
|
| + { 'whitelist': 'hashhashashhashashhashashhash' }
|
| + ],
|
| + 'doc5': {
|
| + 'extension_types': ['extension']
|
| + },
|
| + 'doc1.sub1': {
|
| + 'extension_types': ['platform_app', 'hosted_app', 'packaged_app']
|
| + }
|
| + }
|
| +
|
| + expected = {
|
| + 'doc1': {
|
| + 'platforms': ['app', 'extension'],
|
| + 'name': 'doc1'
|
| + },
|
| + 'doc2': {
|
| + 'platforms': [],
|
| + 'name': 'doc2'
|
| + },
|
| + 'doc4': {
|
| + 'platforms': ['app', 'extension'],
|
| + 'name': 'doc4'
|
| + },
|
| + 'doc5': {
|
| + 'platforms': ['extension'],
|
| + 'name': 'doc5'
|
| + },
|
| + 'doc1.sub1': {
|
| + 'platforms': ['app'],
|
| + 'name': 'doc1.sub1'
|
| + }
|
| + }
|
| +
|
| + self.assertEqual(expected, FeaturesFromJson(raw_features_json))
|
| +
|
| + def testFilter(self):
|
| + unfiltered = {
|
| + 'doc1': { 'platforms': ['app'] },
|
| + 'doc2': { 'platforms': ['extension'] },
|
| + 'doc3': { 'platforms': ['app', 'extension'] },
|
| + 'doc4': { 'platforms': [] }
|
| + }
|
| +
|
| + apps_names = set(('doc1', 'doc3'))
|
| + extension_names = set(('doc2', 'doc3'))
|
| +
|
| + self.assertEqual(
|
| + apps_names, set(Filter(deepcopy(unfiltered), 'app').keys()))
|
| + self.assertEqual(
|
| + extension_names, set(Filter(unfiltered, 'extension').keys()))
|
| +
|
| + def testMergeFeatures(self):
|
| + features = {
|
| + 'doc1': {
|
| + 'platforms': ['app']
|
| + },
|
| + 'doc3': {
|
| + 'name': 'doc3'
|
| + }
|
| + }
|
| +
|
| + other = {
|
| + 'doc1': {
|
| + 'name': 'doc1',
|
| + 'platforms': ['extension']
|
| + },
|
| + 'doc2': {
|
| + 'name': 'doc2'
|
| + },
|
| + 'doc3': {
|
| + 'platforms': ['extension', 'app']
|
| + }
|
| + }
|
| +
|
| + expected = {
|
| + 'doc1': {
|
| + 'name': 'doc1',
|
| + 'platforms': ['extension']
|
| + },
|
| + 'doc2': {
|
| + 'name': 'doc2'
|
| + },
|
| + 'doc3': {
|
| + 'name': 'doc3',
|
| + 'platforms': ['extension', 'app']
|
| + }
|
| + }
|
| +
|
| + self.assertEqual(expected, MergeFeatures(features, other))
|
| +
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|