OLD | NEW |
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 |
24 | 23 |
| 24 _MARKDOWN_CONTENT = ( |
| 25 ('# Header 1 #', u'<h1 id="header-1">Header 1</h1>'), |
| 26 ('1. Foo\n', u'<ol>\n<li>Foo</li>\n</ol>'), |
| 27 ('\n', |
| 28 '<p><img alt="alt text" src="/path/img.jpg" title="Title" /></p>'), |
| 29 ('* Unordered item 1', u'<ul>\n<li>Unordered item 1</li>\n</ul>') |
| 30 ) |
| 31 |
25 # Test file system data which exercises many different mimetypes. | 32 # Test file system data which exercises many different mimetypes. |
26 _TEST_DATA = { | 33 _TEST_DATA = { |
27 'dir': { | 34 'dir': { |
28 'a.txt': 'a.txt content', | 35 'a.txt': 'a.txt content', |
29 'b.txt': 'b.txt content', | 36 'b.txt': 'b.txt content', |
30 'c': { | 37 'c': { |
31 'd.txt': 'd.txt content', | 38 'd.txt': 'd.txt content', |
32 }, | 39 }, |
33 }, | 40 }, |
34 'dir2': { | 41 'dir2': { |
35 'dir3': { | 42 'dir3': { |
36 'a.txt': 'a.txt content', | 43 'a.txt': 'a.txt content', |
37 'b.txt': 'b.txt content', | 44 'b.txt': 'b.txt content', |
38 'c': { | 45 'c': { |
39 'd.txt': 'd.txt content', | 46 'd.txt': 'd.txt content', |
40 }, | 47 }, |
41 }, | 48 }, |
42 }, | 49 }, |
43 'img.png': 'img.png content', | 50 'img.png': 'img.png content', |
44 'read.txt': 'read.txt content', | 51 'read.txt': 'read.txt content', |
45 'redirects.json': _REDIRECTS_JSON, | 52 'redirects.json': _REDIRECTS_JSON, |
46 'run.js': 'run.js content', | 53 'run.js': 'run.js content', |
47 'site.css': 'site.css content', | 54 'site.css': 'site.css content', |
48 'storage.html': 'storage.html content', | 55 'storage.html': 'storage.html content', |
| 56 'markdown.md': '\n'.join(text[0] for text in _MARKDOWN_CONTENT) |
49 } | 57 } |
50 | 58 |
51 | 59 |
52 class ContentProviderUnittest(unittest.TestCase): | 60 class ContentProviderUnittest(unittest.TestCase): |
53 def setUp(self): | 61 def setUp(self): |
54 self._content_provider = self._CreateContentProvider() | 62 self._content_provider = self._CreateContentProvider() |
55 | 63 |
56 def _CreateContentProvider(self, supports_zip=False): | 64 def _CreateContentProvider(self, supports_zip=False): |
57 test_file_system = TestFileSystem(_TEST_DATA) | 65 test_file_system = TestFileSystem(_TEST_DATA) |
58 return ContentProvider( | 66 return ContentProvider( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 def testZip2ndLevel(self): | 121 def testZip2ndLevel(self): |
114 zip_content_provider = self._CreateContentProvider(supports_zip=True) | 122 zip_content_provider = self._CreateContentProvider(supports_zip=True) |
115 content_and_type = zip_content_provider.GetContentAndType( | 123 content_and_type = zip_content_provider.GetContentAndType( |
116 'dir2/dir3.zip').Get() | 124 'dir2/dir3.zip').Get() |
117 zipfile = ZipFile(StringIO(content_and_type.content)) | 125 zipfile = ZipFile(StringIO(content_and_type.content)) |
118 content_and_type.content = zipfile.namelist() | 126 content_and_type.content = zipfile.namelist() |
119 self._assertContent( | 127 self._assertContent( |
120 ['dir3/a.txt', 'dir3/b.txt', 'dir3/c/d.txt'], 'application/zip', | 128 ['dir3/a.txt', 'dir3/b.txt', 'dir3/c/d.txt'], 'application/zip', |
121 content_and_type) | 129 content_and_type) |
122 | 130 |
| 131 def testMarkdown(self): |
| 132 content_and_type = self._content_provider.GetContentAndType( |
| 133 'markdown.html').Get() |
| 134 content_and_type.content = content_and_type.content.source |
| 135 self._assertContent('\n'.join(text[1] for text in _MARKDOWN_CONTENT), |
| 136 'text/html', content_and_type) |
| 137 |
123 def testNotFound(self): | 138 def testNotFound(self): |
124 self.assertRaises( | 139 self.assertRaises( |
125 FileNotFoundError, | 140 FileNotFoundError, |
126 self._content_provider.GetContentAndType('oops').Get) | 141 self._content_provider.GetContentAndType('oops').Get) |
127 | 142 |
128 | 143 |
129 if __name__ == '__main__': | 144 if __name__ == '__main__': |
130 unittest.main() | 145 unittest.main() |
OLD | NEW |