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

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

Issue 54603010: Docserver: Implement the content providers infrastructure, where a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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/content_providers_test.py
diff --git a/chrome/common/extensions/docs/server2/content_providers_test.py b/chrome/common/extensions/docs/server2/content_providers_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..a35c348ab6995ef9dba303e389e1e4ad7b31e433
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/content_providers_test.py
@@ -0,0 +1,132 @@
+#!/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 json
+import unittest
+
+from compiled_file_system import CompiledFileSystem
+from content_providers import ContentProviders
+from object_store_creator import ObjectStoreCreator
+from test_file_system import TestFileSystem
+from test_util import DisableLogging
+
+
+_HOST = 'https://developer.chrome.com'
+
+
+_CONTENT_PROVIDERS = {
+ 'apples': {
+ 'chromium': {
+ 'dir': 'apples'
+ },
+ 'serveFrom': 'apples-dir',
+ },
+ 'bananas': {
+ 'serveFrom': '',
+ 'chromium': {
+ 'dir': ''
+ },
+ },
+ 'tomatoes': {
+ 'serveFrom': 'tomatoes-dir/are/a',
+ 'chromium': {
+ 'dir': 'tomatoes/are/a'
+ },
+ },
+}
+
+
+_FILE_SYSTEM_DATA = {
+ 'docs': {
+ 'templates': {
+ 'json': {
+ 'content_providers.json': json.dumps(_CONTENT_PROVIDERS),
+ },
+ },
+ },
+ 'apples': {
+ 'gala.txt': 'gala apples',
+ 'green': {
+ 'granny smith.txt': 'granny smith apples',
+ },
+ },
+ 'tomatoes': {
+ 'are': {
+ 'a': {
+ 'vegetable.txt': 'no they aren\'t',
+ 'fruit': {
+ 'cherry.txt': 'cherry tomatoes',
+ },
+ },
+ },
+ },
+}
+
+
+class ContentProvidersTest(unittest.TestCase):
+ def setUp(self):
+ self._content_providers = ContentProviders(
+ CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()),
+ TestFileSystem(_FILE_SYSTEM_DATA))
+
+ def testSimpleRootPath(self):
+ provider = self._content_providers.GetByName('apples')
+ self.assertEqual(
+ 'gala apples',
+ provider.GetContentAndType(_HOST, 'gala.txt').Get().content)
+ self.assertEqual(
+ 'granny smith apples',
+ provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get()
+ .content)
+
+ def testComplexRootPath(self):
+ provider = self._content_providers.GetByName('tomatoes')
+ self.assertEqual(
+ 'no they aren\'t',
+ provider.GetContentAndType(_HOST, 'vegetable.txt').Get().content)
+ self.assertEqual(
+ 'cherry tomatoes',
+ provider.GetContentAndType(_HOST, 'fruit/cherry.txt').Get().content)
+
+ def testEmptyRootPath(self):
+ provider = self._content_providers.GetByName('bananas')
+ self.assertEqual(
+ 'gala apples',
+ provider.GetContentAndType(_HOST, 'apples/gala.txt').Get().content)
+
+ def testSimpleServlet(self):
+ provider, path = self._content_providers.GetByServeFrom('apples-dir')
+ self.assertEqual('apples', provider.name)
+ self.assertEqual('', path)
+ provider, path = self._content_providers.GetByServeFrom(
+ 'apples-dir/are/forever')
+ self.assertEqual('apples', provider.name)
+ self.assertEqual('are/forever', path)
+
+ def testComplexServlet(self):
+ provider, path = self._content_providers.GetByServeFrom(
+ 'tomatoes-dir/are/a')
+ self.assertEqual('tomatoes', provider.name)
+ self.assertEqual('', path)
+ provider, path = self._content_providers.GetByServeFrom(
+ 'tomatoes-dir/are/a/fruit/they/are')
+ self.assertEqual('tomatoes', provider.name)
+ self.assertEqual('fruit/they/are', path)
+
+ def testEmptyStringServlet(self):
+ provider, path = self._content_providers.GetByServeFrom('tomatoes-dir/are')
+ self.assertEqual('bananas', provider.name)
+ self.assertEqual('tomatoes-dir/are', path)
+ provider, path = self._content_providers.GetByServeFrom('')
+ self.assertEqual('bananas', provider.name)
+ self.assertEqual('', path)
+
+ @DisableLogging('error')
+ def testProviderNotFound(self):
+ self.assertEqual(None, self._content_providers.GetByName('cabbages'))
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « chrome/common/extensions/docs/server2/content_providers.py ('k') | chrome/common/extensions/docs/server2/cron.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698