diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/common/extensions/docs/server2/app.yaml | 2 | ||||
-rw-r--r-- | chrome/common/extensions/docs/server2/content_provider.py | 26 | ||||
-rwxr-xr-x | chrome/common/extensions/docs/server2/content_provider_test.py | 51 | ||||
-rw-r--r-- | chrome/common/extensions/docs/server2/cron.yaml | 2 |
5 files changed, 62 insertions, 20 deletions
@@ -70,6 +70,7 @@ Clinton Staley <clintstaley@chromium.org> Clinton Staley <clintstaley@gmail.com> Craig Schlenter <craig.schlenter@gmail.com> Dai Chunyang <chunyang.dai@intel.com> +Daniel Johnson <danielj41@gmail.com> Daniel Nishi <dhnishi@gmail.com> Daniel Shaulov <dshaulov@ptc.com> Daniel Trebbien <dtrebbien@gmail.com> diff --git a/chrome/common/extensions/docs/server2/app.yaml b/chrome/common/extensions/docs/server2/app.yaml index b92be11..9cc0d24 100644 --- a/chrome/common/extensions/docs/server2/app.yaml +++ b/chrome/common/extensions/docs/server2/app.yaml @@ -1,5 +1,5 @@ application: chrome-apps-doc -version: 3-17-6 +version: 3-17-7 runtime: python27 api_version: 1 threadsafe: false diff --git a/chrome/common/extensions/docs/server2/content_provider.py b/chrome/common/extensions/docs/server2/content_provider.py index 38ff0a4..c0138f5 100644 --- a/chrome/common/extensions/docs/server2/content_provider.py +++ b/chrome/common/extensions/docs/server2/content_provider.py @@ -141,19 +141,29 @@ class ContentProvider(object): lambda: ContentAndType(zip_future.Get(), 'application/zip', None)) # If there is no file extension, look for a file with one of the default + # extensions. If one cannot be found, check if the path is a directory. + # If it is, then check for an index file with one of the default # extensions. - # - # Note that it would make sense to guard this on Exists(path), since a file - # without an extension may actually exist, but it's such an uncommon case - # it hardly seems worth the potential performance hit. if not ext: - for default_ext in self._default_extensions: - if self.file_system.Exists(path + default_ext).Get(): - path += default_ext - break + new_path = self._AddExt(path) + # Add a trailing / to check if it is a directory and not a file with + # no extension. + if new_path is None and self.file_system.Exists(path + '/').Get(): + new_path = self._AddExt(path + '/index') + if new_path is not None: + path = new_path return self._content_cache.GetFromFile(path) + def _AddExt(self, path): + '''Tries to append each of the default file extensions to path and returns + the first one that is an existing file. + ''' + for default_ext in self._default_extensions: + if self.file_system.Exists(path + default_ext).Get(): + return path + default_ext + return None + def Cron(self): futures = [('<path_canonicalizer>', # semi-arbitrary string since there is # no path associated with this Future. diff --git a/chrome/common/extensions/docs/server2/content_provider_test.py b/chrome/common/extensions/docs/server2/content_provider_test.py index 48da66a..d2e7620 100755 --- a/chrome/common/extensions/docs/server2/content_provider_test.py +++ b/chrome/common/extensions/docs/server2/content_provider_test.py @@ -48,10 +48,24 @@ _TEST_DATA = { }, }, }, + 'dir4': { + 'index.html': 'index.html content 1' + }, + 'dir5': { + 'index.html': 'index.html content 2' + }, + 'dir6': { + 'notindex.html': 'notindex.html content' + }, + 'dir7': { + 'index.md': '\n'.join(text[0] for text in _MARKDOWN_CONTENT) + }, 'dir.txt': 'dir.txt content', + 'dir5.html': 'dir5.html content', 'img.png': 'img.png content', 'read.txt': 'read.txt content', 'redirects.json': _REDIRECTS_JSON, + 'noextension': 'noextension content', 'run.js': 'run.js content', 'site.css': 'site.css content', 'storage.html': 'storage.html content', @@ -82,6 +96,17 @@ class ContentProviderUnittest(unittest.TestCase): self.assertEqual(content, content_and_type.content) self.assertEqual(content_type, content_and_type.content_type) + def _assertTemplateContent(self, content, path): + content_and_type = self._content_provider.GetContentAndType(path).Get() + self.assertEqual(Handlebar, type(content_and_type.content)) + content_and_type.content = content_and_type.content.source + self._assertContent(content, 'text/html', content_and_type) + + def _assertMarkdownContent(self, content, path): + content_and_type = self._content_provider.GetContentAndType(path).Get() + content_and_type.content = content_and_type.content.source + self._assertContent(content, 'text/html', content_and_type) + def testPlainText(self): self._assertContent( u'a.txt content', 'text/plain', @@ -103,11 +128,7 @@ class ContentProviderUnittest(unittest.TestCase): self._content_provider.GetContentAndType('site.css').Get()) def testTemplate(self): - content_and_type = self._content_provider.GetContentAndType( - 'storage.html').Get() - self.assertEqual(Handlebar, type(content_and_type.content)) - content_and_type.content = content_and_type.content.source - self._assertContent(u'storage.html content', 'text/html', content_and_type) + self._assertTemplateContent(u'storage.html content', 'storage.html') def testImage(self): self._assertContent( @@ -152,17 +173,27 @@ class ContentProviderUnittest(unittest.TestCase): zip_content_provider.GetCanonicalPath('diR.zip')) def testMarkdown(self): - content_and_type = self._content_provider.GetContentAndType( - 'markdown').Get() - content_and_type.content = content_and_type.content.source - self._assertContent('\n'.join(text[1] for text in _MARKDOWN_CONTENT), - 'text/html', content_and_type) + self._assertMarkdownContent( + '\n'.join(text[1] for text in _MARKDOWN_CONTENT), + 'markdown') def testNotFound(self): self.assertRaises( FileNotFoundError, self._content_provider.GetContentAndType('oops').Get) + def testIndexRedirect(self): + self._assertTemplateContent(u'index.html content 1', 'dir4') + self._assertTemplateContent(u'dir5.html content', 'dir5') + self._assertMarkdownContent( + '\n'.join(text[1] for text in _MARKDOWN_CONTENT), + 'dir7') + self._assertContent( + 'noextension content', 'text/plain', + self._content_provider.GetContentAndType('noextension').Get()) + self.assertRaises( + FileNotFoundError, + self._content_provider.GetContentAndType('dir6').Get) if __name__ == '__main__': unittest.main() diff --git a/chrome/common/extensions/docs/server2/cron.yaml b/chrome/common/extensions/docs/server2/cron.yaml index 5b87682..ae7ef58 100644 --- a/chrome/common/extensions/docs/server2/cron.yaml +++ b/chrome/common/extensions/docs/server2/cron.yaml @@ -2,4 +2,4 @@ cron: - description: Repopulates all cached data. url: /_cron schedule: every 5 minutes - target: 3-17-6 + target: 3-17-7 |