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

Unified Diff: chrome/common/extensions/docs/server2/features_utility_test.py

Issue 16410002: Docserver manifest follow up (rewrite) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gen-manifest-try-2
Patch Set: more idiomatic/less explicit copying Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
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..313e451add6c633fdc87bb210ff1e79c37b351e5
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/features_utility_test.py
@@ -0,0 +1,115 @@
+#!/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.
+
+import unittest
+
+from features_utility import Parse, Filtered, MergedWith
+
+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, Parse(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(Filtered(unfiltered, 'app').keys()))
+ self.assertEqual(
+ extension_names, set(Filtered(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, MergedWith(features, other))
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698