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

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

Issue 344453003: Docserver: separate models for apps and extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 unified diff | Download patch
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 import unittest 6 import unittest
7 7
8 from document_renderer import DocumentRenderer 8 from document_renderer import DocumentRenderer
9 from server_instance import ServerInstance 9 from server_instance import ServerInstance
10 from test_file_system import TestFileSystem 10 from test_file_system import TestFileSystem
11 from test_data.canned_data import CANNED_TEST_FILE_SYSTEM_DATA 11 from test_data.canned_data import CANNED_TEST_FILE_SYSTEM_DATA
12 12
13 13
14 class DocumentRendererUnittest(unittest.TestCase): 14 class DocumentRendererUnittest(unittest.TestCase):
15 def setUp(self): 15 def setUp(self):
16 self._renderer = ServerInstance.ForTest( 16 self._renderer = ServerInstance.ForTest(
17 TestFileSystem(CANNED_TEST_FILE_SYSTEM_DATA)).document_renderer 17 TestFileSystem(CANNED_TEST_FILE_SYSTEM_DATA)).document_renderer
18 18
19 def testNothingToSubstitute(self): 19 def testNothingToSubstitute(self):
20 document = 'hello world' 20 document = 'hello world'
21 path = 'some/path/to/document.html' 21 path = 'apps/some/path/to/document.html'
22 22
23 text, warnings = self._renderer.Render(document, path) 23 text, warnings = self._renderer.Render(document, path)
24 self.assertEqual(document, text) 24 self.assertEqual(document, text)
25 self.assertEqual([], warnings) 25 self.assertEqual([], warnings)
26 26
27 text, warnings = self._renderer.Render(document, path, render_title=True) 27 text, warnings = self._renderer.Render(document, path, render_title=True)
28 self.assertEqual(document, text) 28 self.assertEqual(document, text)
29 self.assertEqual(['Expected a title'], warnings) 29 self.assertEqual(['Expected a title'], warnings)
30 30
31 def testTitles(self): 31 def testTitles(self):
32 document = '<h1>title</h1> then $(title) then another $(title)' 32 document = '<h1>title</h1> then $(title) then another $(title)'
33 path = 'some/path/to/document.html' 33 path = 'apps/some/path/to/document.html'
34 34
35 text, warnings = self._renderer.Render(document, path) 35 text, warnings = self._renderer.Render(document, path)
36 self.assertEqual(document, text) 36 self.assertEqual(document, text)
37 self.assertEqual(['Found unexpected title "title"'], warnings) 37 self.assertEqual(['Found unexpected title "title"'], warnings)
38 38
39 text, warnings = self._renderer.Render(document, path, render_title=True) 39 text, warnings = self._renderer.Render(document, path, render_title=True)
40 self.assertEqual('<h1>title</h1> then title then another $(title)', text) 40 self.assertEqual('<h1>title</h1> then title then another $(title)', text)
41 self.assertEqual([], warnings) 41 self.assertEqual([], warnings)
42 42
43 def testTocs(self): 43 def testTocs(self):
44 document = ('here is a toc $(table_of_contents) ' 44 document = ('here is a toc $(table_of_contents) '
45 'and another $(table_of_contents)') 45 'and another $(table_of_contents)')
46 expected_document = ('here is a toc <table-of-contents> and another ' 46 expected_document = ('here is a toc <table-of-contents> and another '
47 '$(table_of_contents)') 47 '$(table_of_contents)')
48 path = 'some/path/to/document.html' 48 path = 'apps/some/path/to/document.html'
49 49
50 text, warnings = self._renderer.Render(document, path) 50 text, warnings = self._renderer.Render(document, path)
51 self.assertEqual(expected_document, text) 51 self.assertEqual(expected_document, text)
52 self.assertEqual([], warnings) 52 self.assertEqual([], warnings)
53 53
54 text, warnings = self._renderer.Render(document, path, render_title=True) 54 text, warnings = self._renderer.Render(document, path, render_title=True)
55 self.assertEqual(expected_document, text) 55 self.assertEqual(expected_document, text)
56 self.assertEqual(['Expected a title'], warnings) 56 self.assertEqual(['Expected a title'], warnings)
57 57
58 def testRefs(self): 58 def testRefs(self):
59 # The references in this and subsequent tests won't actually be resolved 59 # The references in this and subsequent tests won't actually be resolved
60 document = 'A ref $(ref:baz.baz_e1) here, $(ref:foo.foo_t3 ref title) there' 60 document = 'A ref $(ref:baz.baz_e1) here, $(ref:foo.foo_t3 ref title) there'
61 expected_document = ('A ref <a href=#type-baz_e1>baz.baz_e1</a> ' 61 expected_document = ('A ref <a href=#type-baz_e1>baz.baz_e1</a> '
62 'here, <a href=#type-foo_t3>ref title</a> ' 62 'here, <a href=#type-foo_t3>ref title</a> '
63 'there') 63 'there')
64 path = 'some/path/to/document.html' 64 path = 'apps/some/path/to/document.html'
65 65
66 text, warnings = self._renderer.Render(document, path) 66 text, warnings = self._renderer.Render(document, path)
67 self.assertEqual(expected_document, text) 67 self.assertEqual(expected_document, text)
68 self.assertEqual([], warnings) 68 self.assertEqual([], warnings)
69 69
70 text, warnings = self._renderer.Render(document, path, render_title=True) 70 text, warnings = self._renderer.Render(document, path, render_title=True)
71 self.assertEqual(expected_document, text) 71 self.assertEqual(expected_document, text)
72 self.assertEqual(['Expected a title'], warnings) 72 self.assertEqual(['Expected a title'], warnings)
73 73
74 def testTitleAndToc(self): 74 def testTitleAndToc(self):
75 document = '<h1>title</h1> $(title) and $(table_of_contents)' 75 document = '<h1>title</h1> $(title) and $(table_of_contents)'
76 path = 'some/path/to/document.html' 76 path = 'apps/some/path/to/document.html'
77 77
78 text, warnings = self._renderer.Render(document, path) 78 text, warnings = self._renderer.Render(document, path)
79 self.assertEqual('<h1>title</h1> $(title) and <table-of-contents>', text) 79 self.assertEqual('<h1>title</h1> $(title) and <table-of-contents>', text)
80 self.assertEqual(['Found unexpected title "title"'], warnings) 80 self.assertEqual(['Found unexpected title "title"'], warnings)
81 81
82 text, warnings = self._renderer.Render(document, path, render_title=True) 82 text, warnings = self._renderer.Render(document, path, render_title=True)
83 self.assertEqual('<h1>title</h1> title and <table-of-contents>', text) 83 self.assertEqual('<h1>title</h1> title and <table-of-contents>', text)
84 self.assertEqual([], warnings) 84 self.assertEqual([], warnings)
85 85
86 def testRefInTitle(self): 86 def testRefInTitle(self):
87 document = '<h1>$(ref:baz.baz_e1 title)</h1> A $(title) was here' 87 document = '<h1>$(ref:baz.baz_e1 title)</h1> A $(title) was here'
88 expected_document_no_title = ('<h1><a href=#type-baz_e1>' 88 expected_document_no_title = ('<h1><a href=#type-baz_e1>'
89 'title</a></h1> A $(title) was here') 89 'title</a></h1> A $(title) was here')
90 90
91 expected_document = ('<h1><a href=#type-baz_e1>title</a></h1>' 91 expected_document = ('<h1><a href=#type-baz_e1>title</a></h1>'
92 ' A title was here') 92 ' A title was here')
93 path = 'some/path/to/document.html' 93 path = 'apps/some/path/to/document.html'
94 94
95 text, warnings = self._renderer.Render(document, path) 95 text, warnings = self._renderer.Render(document, path)
96 self.assertEqual(expected_document_no_title, text) 96 self.assertEqual(expected_document_no_title, text)
97 self.assertEqual([('Found unexpected title "title"')], warnings) 97 self.assertEqual([('Found unexpected title "title"')], warnings)
98 98
99 text, warnings = self._renderer.Render(document, path, render_title=True) 99 text, warnings = self._renderer.Render(document, path, render_title=True)
100 self.assertEqual(expected_document, text) 100 self.assertEqual(expected_document, text)
101 self.assertEqual([], warnings) 101 self.assertEqual([], warnings)
102 102
103 def testRefSplitAcrossLines(self): 103 def testRefSplitAcrossLines(self):
104 document = 'Hello, $(ref:baz.baz_e1 world). A $(ref:foo.foo_t3\n link)' 104 document = 'Hello, $(ref:baz.baz_e1 world). A $(ref:foo.foo_t3\n link)'
105 expected_document = ('Hello, <a href=#type-baz_e1>world</a>. A <a href=' 105 expected_document = ('Hello, <a href=#type-baz_e1>world</a>. A <a href='
106 '#type-foo_t3>link</a>') 106 '#type-foo_t3>link</a>')
107 107
108 path = 'some/path/to/document.html' 108 path = 'apps/some/path/to/document.html'
109 109
110 text, warnings = self._renderer.Render(document, path) 110 text, warnings = self._renderer.Render(document, path)
111 self.assertEqual(expected_document, text) 111 self.assertEqual(expected_document, text)
112 self.assertEqual([], warnings) 112 self.assertEqual([], warnings)
113 113
114 text, warnings = self._renderer.Render(document, path, render_title=True) 114 text, warnings = self._renderer.Render(document, path, render_title=True)
115 self.assertEqual(expected_document, text) 115 self.assertEqual(expected_document, text)
116 self.assertEqual(['Expected a title'], warnings) 116 self.assertEqual(['Expected a title'], warnings)
117 117
118 def testInvalidRef(self): 118 def testInvalidRef(self):
119 # DocumentRenderer attempts to detect unclosed $(ref:...) tags by limiting 119 # DocumentRenderer attempts to detect unclosed $(ref:...) tags by limiting
120 # how far it looks ahead. Lorem Ipsum should be long enough to trigger that. 120 # how far it looks ahead. Lorem Ipsum should be long enough to trigger that.
121 _LOREM_IPSUM = ( 121 _LOREM_IPSUM = (
122 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do ' 122 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do '
123 'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ' 123 'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim '
124 'ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut ' 124 'ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut '
125 'aliquip ex ea commodo consequat. Duis aute irure dolor in ' 125 'aliquip ex ea commodo consequat. Duis aute irure dolor in '
126 'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla ' 126 'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla '
127 'pariatur. Excepteur sint occaecat cupidatat non proident, sunt in ' 127 'pariatur. Excepteur sint occaecat cupidatat non proident, sunt in '
128 'culpa qui officia deserunt mollit anim id est laborum.') 128 'culpa qui officia deserunt mollit anim id est laborum.')
129 document = ('An invalid $(ref:foo.foo_t3 a title ' + _LOREM_IPSUM + 129 document = ('An invalid $(ref:foo.foo_t3 a title ' + _LOREM_IPSUM +
130 '$(ref:baz.baz_e1) here') 130 '$(ref:baz.baz_e1) here')
131 expected_document = ('An invalid $(ref:foo.foo_t3 a title ' + _LOREM_IPSUM + 131 expected_document = ('An invalid $(ref:foo.foo_t3 a title ' + _LOREM_IPSUM +
132 '<a href=#type-baz_e1>baz.baz_e1</a> here') 132 '<a href=#type-baz_e1>baz.baz_e1</a> here')
133 path = 'some/path/to/document_api.html' 133 path = 'apps/some/path/to/document_api.html'
134 134
135 text, warnings = self._renderer.Render(document, path) 135 text, warnings = self._renderer.Render(document, path)
136 self.assertEqual(expected_document, text) 136 self.assertEqual(expected_document, text)
137 self.assertEqual([], warnings) 137 self.assertEqual([], warnings)
138 138
139 text, warnings = self._renderer.Render(document, path, render_title=True) 139 text, warnings = self._renderer.Render(document, path, render_title=True)
140 self.assertEqual(expected_document, text) 140 self.assertEqual(expected_document, text)
141 self.assertEqual(['Expected a title'], warnings) 141 self.assertEqual(['Expected a title'], warnings)
142 142
143 143
144 if __name__ == '__main__': 144 if __name__ == '__main__':
145 unittest.main() 145 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698