Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / document_renderer_test.py
blob5f9cb763a8fa167c89c3f3b4622348c97eba77f8
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 import unittest
8 from document_renderer import DocumentRenderer
11 class _FakeTableOfContentsRenderer(object):
12 def __init__(self, string):
13 self._string = string
15 def Render(self, _):
16 return self._string, []
19 class DocumentRendererUnittest(unittest.TestCase):
20 def setUp(self):
21 self._renderer = DocumentRenderer(_FakeTableOfContentsRenderer('t-o-c'))
23 def testNothingToSubstitute(self):
24 document = 'hello world'
26 text, warnings = self._renderer.Render(document)
27 self.assertEqual(document, text)
28 self.assertEqual([], warnings)
30 text, warnings = self._renderer.Render(document, render_title=True)
31 self.assertEqual(document, text)
32 self.assertEqual(['Expected a title'], warnings)
34 def testTitles(self):
35 document = '<h1>title</h1> then $(title) then another $(title)'
37 text, warnings = self._renderer.Render(document)
38 self.assertEqual(document, text)
39 self.assertEqual(['Found unexpected title "title"'], warnings)
41 text, warnings = self._renderer.Render(document, render_title=True)
42 self.assertEqual('<h1>title</h1> then title then another $(title)', text)
43 self.assertEqual([], warnings)
45 def testTocs(self):
46 document = ('here is a toc $(table_of_contents) '
47 'and another $(table_of_contents)')
48 expected_document = 'here is a toc t-o-c and another $(table_of_contents)'
50 text, warnings = self._renderer.Render(document)
51 self.assertEqual(expected_document, text)
52 self.assertEqual([], warnings)
54 text, warnings = self._renderer.Render(document, render_title=True)
55 self.assertEqual(expected_document, text)
56 self.assertEqual(['Expected a title'], warnings)
58 def testTitleAndToc(self):
59 document = '<h1>title</h1> $(title) and $(table_of_contents)'
61 text, warnings = self._renderer.Render(document)
62 self.assertEqual('<h1>title</h1> $(title) and t-o-c', text)
63 self.assertEqual(['Found unexpected title "title"'], warnings)
65 text, warnings = self._renderer.Render(document, render_title=True)
66 self.assertEqual('<h1>title</h1> title and t-o-c', text)
67 self.assertEqual([], warnings)
70 if __name__ == '__main__':
71 unittest.main()