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

Side by Side Diff: chrome/common/extensions/docs/server2/content_provider_test.py

Issue 93743005: Support markdown template for html editor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add more tests to markdown syntax Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 from cStringIO import StringIO 6 from cStringIO import StringIO
7 import json 7 import json
8 import unittest 8 import unittest
9 from zipfile import ZipFile 9 from zipfile import ZipFile
10 10
11 from compiled_file_system import CompiledFileSystem 11 from compiled_file_system import CompiledFileSystem
12 from content_provider import ContentProvider 12 from content_provider import ContentProvider
13 from file_system import FileNotFoundError 13 from file_system import FileNotFoundError
14 from object_store_creator import ObjectStoreCreator 14 from object_store_creator import ObjectStoreCreator
15 from test_file_system import TestFileSystem 15 from test_file_system import TestFileSystem
16 from third_party.handlebar import Handlebar 16 from third_party.handlebar import Handlebar
17 17
18
19 _REDIRECTS_JSON = json.dumps({ 18 _REDIRECTS_JSON = json.dumps({
20 'oldfile.html': 'storage.html', 19 'oldfile.html': 'storage.html',
21 'index.html': 'https://developers.google.com/chrome', 20 'index.html': 'https://developers.google.com/chrome',
22 }) 21 })
23 22
23 def _ToMarkDownOriginalText(obj):
not at google - send to devlin 2014/01/03 03:18:01 let's decide whether it's mark_down/MarkDown or ma
hukun 2014/01/06 08:25:19 Done
24 markdown_text = ''
25 for text, html in obj.iteritems():
26 if markdown_text != '':
27 markdown_text += '\n'
28 markdown_text += text
29 return markdown_text
30
31 def _ToCompiledMarkDownHTML(obj):
32 markdown_html = ''
33 for text, html in obj.iteritems():
34 if markdown_html != '':
35 markdown_html += '\n'
36 markdown_html += html
37 return markdown_html
38
39
40 _MARK_DOWN_CONTENT = {
41 '# Header 1 #': u'<h1 id="header-1">Header 1</h1>',
not at google - send to devlin 2014/01/03 03:18:01 having this as a dict is a bit odd since it means
hukun 2014/01/06 08:25:19 Done
42 '1. Foo\n': u'<ol>\n<li>Foo</li>\n</ol>',
43 '![alt text](/path/img.jpg "Title")\n':
44 u'<p><img alt="alt text" src="/path/img.jpg" title="Title" /></p>',
45 '* Unordered item 1': '<ul>\n<li>Unordered item 1</li>\n</ul>',
46 }
24 47
25 # Test file system data which exercises many different mimetypes. 48 # Test file system data which exercises many different mimetypes.
26 _TEST_DATA = { 49 _TEST_DATA = {
27 'dir': { 50 'dir': {
28 'a.txt': 'a.txt content', 51 'a.txt': 'a.txt content',
29 'b.txt': 'b.txt content', 52 'b.txt': 'b.txt content',
30 'c': { 53 'c': {
31 'd.txt': 'd.txt content', 54 'd.txt': 'd.txt content',
32 }, 55 },
33 }, 56 },
34 'dir2': { 57 'dir2': {
35 'dir3': { 58 'dir3': {
36 'a.txt': 'a.txt content', 59 'a.txt': 'a.txt content',
37 'b.txt': 'b.txt content', 60 'b.txt': 'b.txt content',
38 'c': { 61 'c': {
39 'd.txt': 'd.txt content', 62 'd.txt': 'd.txt content',
40 }, 63 },
41 }, 64 },
42 }, 65 },
43 'img.png': 'img.png content', 66 'img.png': 'img.png content',
44 'read.txt': 'read.txt content', 67 'read.txt': 'read.txt content',
45 'redirects.json': _REDIRECTS_JSON, 68 'redirects.json': _REDIRECTS_JSON,
46 'run.js': 'run.js content', 69 'run.js': 'run.js content',
47 'site.css': 'site.css content', 70 'site.css': 'site.css content',
48 'storage.html': 'storage.html content', 71 'storage.html': 'storage.html content',
72 'markdown.md': _ToMarkDownOriginalText(_MARK_DOWN_CONTENT)
not at google - send to devlin 2014/01/03 03:18:01 you could write this pretty simply as: 'markdown.
hukun 2014/01/06 08:25:19 Done
49 } 73 }
50 74
51 75
52 class ContentProviderUnittest(unittest.TestCase): 76 class ContentProviderUnittest(unittest.TestCase):
53 def setUp(self): 77 def setUp(self):
54 self._content_provider = self._CreateContentProvider() 78 self._content_provider = self._CreateContentProvider()
55 79
56 def _CreateContentProvider(self, supports_zip=False): 80 def _CreateContentProvider(self, supports_zip=False):
57 test_file_system = TestFileSystem(_TEST_DATA) 81 test_file_system = TestFileSystem(_TEST_DATA)
58 return ContentProvider( 82 return ContentProvider(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 def testZip2ndLevel(self): 137 def testZip2ndLevel(self):
114 zip_content_provider = self._CreateContentProvider(supports_zip=True) 138 zip_content_provider = self._CreateContentProvider(supports_zip=True)
115 content_and_type = zip_content_provider.GetContentAndType( 139 content_and_type = zip_content_provider.GetContentAndType(
116 'dir2/dir3.zip').Get() 140 'dir2/dir3.zip').Get()
117 zipfile = ZipFile(StringIO(content_and_type.content)) 141 zipfile = ZipFile(StringIO(content_and_type.content))
118 content_and_type.content = zipfile.namelist() 142 content_and_type.content = zipfile.namelist()
119 self._assertContent( 143 self._assertContent(
120 ['dir3/a.txt', 'dir3/b.txt', 'dir3/c/d.txt'], 'application/zip', 144 ['dir3/a.txt', 'dir3/b.txt', 'dir3/c/d.txt'], 'application/zip',
121 content_and_type) 145 content_and_type)
122 146
147 def testMarkdown(self):
148 content_and_type = self._content_provider.GetContentAndType(
149 'markdown.html').Get()
150 content_and_type.content = content_and_type.content.source
151 self._assertContent(_ToCompiledMarkDownHTML(_MARK_DOWN_CONTENT),
not at google - send to devlin 2014/01/03 03:18:01 _ToCompiledMarkDown on next line (like all of the
hukun 2014/01/06 08:25:19 Done
152 'text/html', content_and_type)
153
123 def testNotFound(self): 154 def testNotFound(self):
124 self.assertRaises( 155 self.assertRaises(
125 FileNotFoundError, 156 FileNotFoundError,
126 self._content_provider.GetContentAndType('oops').Get) 157 self._content_provider.GetContentAndType('oops').Get)
127 158
128 159
129 if __name__ == '__main__': 160 if __name__ == '__main__':
130 unittest.main() 161 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698