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

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

Issue 23503039: Adding APISchemaGraph class to Extensions Docserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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/availability_graph_test.py
diff --git a/chrome/common/extensions/docs/server2/availability_graph_test.py b/chrome/common/extensions/docs/server2/availability_graph_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..bf2a43ee852a51b21720175d7180aa5cb27b0874
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/availability_graph_test.py
@@ -0,0 +1,417 @@
+#!/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 availability_graph import AvailabilityGraph
+from branch_utility import ChannelInfo
+from test_branch_utility import TestBranchUtility
+
+class AvailabilityGraphTest(unittest.TestCase):
epeterson 2013/09/06 22:47:46 What do you think of this test? Terrifying? Wonde
not at google - send to devlin 2013/09/06 23:29:38 A little of both... half way there? Test interface
epeterson 2013/09/12 00:32:01 Done.
+
+ def setUp(self):
+ self._branch_util = TestBranchUtility.CreateWithCannedData()
+
+ def testCreateGraph(self):
+ api_schema = [{
not at google - send to devlin 2013/09/06 23:29:38 maybe put the test data at the top of the file so
epeterson 2013/09/12 00:32:01 Done.
+ 'namespace': 'tabs',
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {},
+ 'TAB_PROPERTY_TWO': {}
+ },
+ 'types': [
+ {
+ 'id': 'Tab',
+ 'properties': {
+ 'id': {},
+ 'url': {}
+ }
+ }
+ ],
+ 'functions': [
+ {
+ 'name': 'get',
+ 'parameters': [
+ {
+ 'name': 'callback',
+ 'parameters': [
+ {
+ 'name': 'tab'
+ }
+ ]
+ },
+ {
+ 'name': 'tabId'
+ }
+ ]
+ }
+ ],
+ 'events': [
+ {
+ 'name': 'onActivated',
+ 'parameters': [
+ {
+ 'name': 'activeInfo',
+ 'properties': {
+ 'tabId': {},
+ 'windowId': {}
+ }
+ }
+ ]
+ }
+ ]
+ }]
+ expected_graph = {
not at google - send to devlin 2013/09/06 23:29:38 i.e. this test is not useful
epeterson 2013/09/12 00:32:01 Done.
+ 'tabs': {
+ 'availability': None,
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {
+ 'availability': None
+ },
+ 'TAB_PROPERTY_TWO': {
+ 'availability': None
+ }
+ },
+ 'types': {
+ 'Tab': {
+ 'availability': None,
+ 'properties': {
+ 'id': { 'availability': None },
+ 'url': { 'availability': None }
+ }
+ }
+ },
+ 'functions': {
+ 'get': {
+ 'availability': None,
+ 'parameters': {
+ 'callback': {
+ 'availability': None,
+ 'parameters': {
+ 'tab': { 'availability': None }
+ }
+ },
+ 'tabId': { 'availability': None }
+ }
+ }
+ },
+ 'events': {
+ 'onActivated': {
+ 'availability': None,
+ 'parameters': {
+ 'activeInfo': {
+ 'availability': None,
+ 'properties': {
+ 'tabId': { 'availability': None },
+ 'windowId': { 'availability': None }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ availability_graph = AvailabilityGraph(
+ api_schema,
+ self._branch_util.GetChannelInfo('trunk'))
+ self.assertEqual(availability_graph.graph, expected_graph)
+
+ def testLookup(self):
+ all_channel_info = self._branch_util.GetAllChannelInfo()
+ availability_graph = AvailabilityGraph([], all_channel_info[3])
+ availability_graph.graph = {
+ 'tabs': {
+ 'availability': all_channel_info[0],
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {
+ 'availability': all_channel_info[3]
+ }
+ },
+ 'functions': {
+ 'get': {
+ 'availability': all_channel_info[2],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[2],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[2]
+ }
+ }
+ }
+ }
+ }
+ },
+ 'events': {
+ 'onUpdated': {
+ 'availability': all_channel_info[1],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[1],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[1]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ path = ('tabs',)
+ self.assertEqual(availability_graph.Lookup(*path), all_channel_info[0])
not at google - send to devlin 2013/09/06 23:29:38 but these are. you need these assertions with the
epeterson 2013/09/12 00:32:01 Done.
+
+ path = ('tabs', 'properties', 'TAB_PROPERTY_ONE')
+ self.assertEqual(availability_graph.Lookup(*path), all_channel_info[3])
not at google - send to devlin 2013/09/06 23:29:38 inline these |path|s though.
epeterson 2013/09/12 00:32:01 Done.
+
+ path = ('tabs', 'functions', 'get', 'parameters', 'callback',
+ 'parameters', 'Tab')
+ self.assertEqual(availability_graph.Lookup(*path), all_channel_info[2])
+
+ path = ('tabs', 'events', 'onUpdated', 'parameters', 'callback',
+ 'parameters', 'Tab')
+ self.assertEqual(availability_graph.Lookup(*path), all_channel_info[1])
+
+ path = ('events', 'onUpdated', 'parameters', 'callback')
+ self.assertIsNone(availability_graph.Lookup(*path))
+
+ path = ('tabs', 'properties', 'TAB_PROPERTY_DEUX')
+ self.assertIsNone(availability_graph.Lookup(*path))
+
+ path = ('tabs', 'functions', 'get', 'parameters', 'callback', 'parameters')
+ self.assertIsNone(availability_graph.Lookup(*path))
+
+ def testSetPaths(self):
+ all_channel_info = self._branch_util.GetAllChannelInfo()
+ other_graph = AvailabilityGraph([], all_channel_info[0])
+ other_graph.graph = {
+ 'tabs': {
+ 'availability': None
+ }
+ }
+ this_graph = AvailabilityGraph([], all_channel_info[3])
+ this_graph.graph = {
+ 'tabs': {
+ 'availability': None,
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {
+ 'availability': None
+ }
+ },
+ 'functions': {
+ 'get': {
+ 'availability': None,
+ 'parameters': {
+ 'callback': {
+ 'availability': None,
+ 'parameters': {
+ 'Tab': {
+ 'availability': None
+ }
+ }
+ }
+ }
+ }
+ },
+ 'events': {
+ 'onUpdated': {
+ 'availability': None,
+ 'parameters': {
+ 'callback': {
+ 'availability': None,
+ 'parameters': {
+ 'Tab': {
+ 'availability': None
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ expected_paths = [
+ 'tabs/properties/TAB_PROPERTY_ONE',
+ 'tabs/functions/get',
+ 'tabs/functions/get/parameters/callback',
+ 'tabs/functions/get/parameters/callback/parameters/Tab',
+ 'tabs/events/onUpdated',
+ 'tabs/events/onUpdated/parameters/callback',
+ 'tabs/events/onUpdated/parameters/callback/parameters/Tab'
+ ]
+ this_graph.SetPaths(other_graph)
+ self.assertEqual(sorted(this_graph._paths), sorted(expected_paths))
+
+ expected_graph = {
+ 'tabs': {
+ 'availability': all_channel_info[0],
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {
+ 'availability': all_channel_info[3]
+ }
+ },
+ 'functions': {
+ 'get': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[3]
+ }
+ }
+ }
+ }
+ }
+ },
+ 'events': {
+ 'onUpdated': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[3]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ self.assertEqual(this_graph.graph, expected_graph)
+
+ def testUpdatePaths(self):
+ all_channel_info = self._branch_util.GetAllChannelInfo()
+ other_graph = AvailabilityGraph([], all_channel_info[1])
+ other_graph.graph = {
+ 'tabs': {
+ 'availability': all_channel_info[0],
+ 'events': {
+ 'onUpdated': {
+ 'availability': all_channel_info[1],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[1],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[1]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ this_graph = AvailabilityGraph([], all_channel_info[3])
+ this_graph.graph = {
+ 'tabs': {
+ 'availability': all_channel_info[0],
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {
+ 'availability': all_channel_info[3]
+ }
+ },
+ 'functions': {
+ 'get': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[3]
+ }
+ }
+ }
+ }
+ }
+ },
+ 'events': {
+ 'onUpdated': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[3]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ this_graph._paths = [
+ 'tabs/properties/TAB_PROPERTY_ONE',
+ 'tabs/functions/get',
+ 'tabs/functions/get/parameters/callback',
+ 'tabs/functions/get/parameters/callback/parameters/Tab',
+ 'tabs/events/onUpdated',
+ 'tabs/events/onUpdated/parameters/callback',
+ 'tabs/events/onUpdated/parameters/callback/parameters/Tab'
+ ]
+ paths_after_update = [
+ 'tabs/properties/TAB_PROPERTY_ONE',
+ 'tabs/functions/get',
+ 'tabs/functions/get/parameters/callback',
+ 'tabs/functions/get/parameters/callback/parameters/Tab',
+ ]
+ self.assertTrue(this_graph.UpdatePaths(other_graph))
+ self.assertEqual(sorted(this_graph._paths), sorted(paths_after_update))
+
+ graph_after_update = {
+ 'tabs': {
+ 'availability': all_channel_info[0],
+ 'properties': {
+ 'TAB_PROPERTY_ONE': {
+ 'availability': all_channel_info[3]
+ }
+ },
+ 'functions': {
+ 'get': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[3],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[3]
+ }
+ }
+ }
+ }
+ }
+ },
+ 'events': {
+ 'onUpdated': {
+ 'availability': all_channel_info[1],
+ 'parameters': {
+ 'callback': {
+ 'availability': all_channel_info[1],
+ 'parameters': {
+ 'Tab': {
+ 'availability': all_channel_info[1]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ self.assertEqual(this_graph.graph, graph_after_update)
+
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698