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

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

Issue 68873003: Docserver: Serve docs out of src/ not src/chrome/common/extensions. This allows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix samples Created 7 years, 1 month 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 import json 6 import json
7 import unittest 7 import unittest
8 8
9 from compiled_file_system import CompiledFileSystem 9 from compiled_file_system import CompiledFileSystem
10 from extensions_paths import JSON_TEMPLATES
10 from mock_file_system import MockFileSystem 11 from mock_file_system import MockFileSystem
11 from object_store_creator import ObjectStoreCreator 12 from object_store_creator import ObjectStoreCreator
12 from server_instance import ServerInstance 13 from server_instance import ServerInstance
13 from servlet import Request 14 from servlet import Request
14 from sidenav_data_source import SidenavDataSource, _AddLevels, _AddSelected 15 from sidenav_data_source import SidenavDataSource, _AddLevels, _AddSelected
15 from test_file_system import TestFileSystem 16 from test_file_system import TestFileSystem
16 from test_util import CaptureLogging 17 from test_util import CaptureLogging
17 18
18 19
19 class SamplesDataSourceTest(unittest.TestCase): 20 class SamplesDataSourceTest(unittest.TestCase):
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 { 'href': '/H2.html' }, 73 { 'href': '/H2.html' },
73 { 'href': '/base/path/H2.html' }, 74 { 'href': '/base/path/H2.html' },
74 { 'href': 'https://qualified/X1.html' }, 75 { 'href': 'https://qualified/X1.html' },
75 { 76 {
76 'href': 'H3.html', 77 'href': 'H3.html',
77 'items': [{ 78 'items': [{
78 'href': 'H4.html' 79 'href': 'H4.html'
79 }] 80 }]
80 }, 81 },
81 ]) 82 ])
82 }, relative_to='docs/templates/json') 83 }, relative_to=JSON_TEMPLATES)
83 84
84 expected = [ 85 expected = [
85 {'href': '/base/path/H1.html', 'level': 2}, 86 {'href': '/base/path/H1.html', 'level': 2},
86 {'href': '/base/path/H2.html', 'level': 2, 'selected': True}, 87 {'href': '/base/path/H2.html', 'level': 2, 'selected': True},
87 {'href': '/base/path/base/path/H2.html', 'level': 2}, 88 {'href': '/base/path/base/path/H2.html', 'level': 2},
88 {'href': 'https://qualified/X1.html', 'level': 2}, 89 {'href': 'https://qualified/X1.html', 'level': 2},
89 {'items': [ 90 {'items': [
90 {'href': '/base/path/H4.html', 'level': 3} 91 {'href': '/base/path/H4.html', 'level': 3}
91 ], 92 ],
92 'href': '/base/path/H3.html', 'level': 2} 93 'href': '/base/path/H3.html', 'level': 2}
(...skipping 11 matching lines...) Expand all
104 def testSidenavDataSource(self): 105 def testSidenavDataSource(self):
105 file_system = MockFileSystem(TestFileSystem({ 106 file_system = MockFileSystem(TestFileSystem({
106 'apps_sidenav.json': json.dumps([{ 107 'apps_sidenav.json': json.dumps([{
107 'title': 'H1', 108 'title': 'H1',
108 'href': 'H1.html', 109 'href': 'H1.html',
109 'items': [{ 110 'items': [{
110 'title': 'H2', 111 'title': 'H2',
111 'href': '/H2.html' 112 'href': '/H2.html'
112 }] 113 }]
113 }]) 114 }])
114 }, relative_to='docs/templates/json')) 115 }, relative_to=JSON_TEMPLATES))
115 116
116 expected = [{ 117 expected = [{
117 'level': 2, 118 'level': 2,
118 'child_selected': True, 119 'child_selected': True,
119 'title': 'H1', 120 'title': 'H1',
120 'href': '/H1.html', 121 'href': '/H1.html',
121 'items': [{ 122 'items': [{
122 'level': 3, 123 'level': 3,
123 'selected': True, 124 'selected': True,
124 'title': 'H2', 125 'title': 'H2',
(...skipping 14 matching lines...) Expand all
139 140
140 # Test that only a single file is read when creating the sidenav, so that 141 # Test that only a single file is read when creating the sidenav, so that
141 # we can be confident in the compiled_file_system.SingleFile annotation. 142 # we can be confident in the compiled_file_system.SingleFile annotation.
142 self.assertTrue(*file_system.CheckAndReset( 143 self.assertTrue(*file_system.CheckAndReset(
143 read_count=1, stat_count=1, read_resolve_count=1)) 144 read_count=1, stat_count=1, read_resolve_count=1))
144 145
145 def testCron(self): 146 def testCron(self):
146 file_system = TestFileSystem({ 147 file_system = TestFileSystem({
147 'apps_sidenav.json': '[{ "title": "H1" }]' , 148 'apps_sidenav.json': '[{ "title": "H1" }]' ,
148 'extensions_sidenav.json': '[{ "title": "H2" }]' 149 'extensions_sidenav.json': '[{ "title": "H2" }]'
149 }, relative_to='docs/templates/json') 150 }, relative_to=JSON_TEMPLATES)
150 151
151 # Ensure Cron doesn't rely on request. 152 # Ensure Cron doesn't rely on request.
152 sidenav_data_source = SidenavDataSource( 153 sidenav_data_source = SidenavDataSource(
153 ServerInstance.ForTest(file_system), request=None) 154 ServerInstance.ForTest(file_system), request=None)
154 sidenav_data_source.Cron().Get() 155 sidenav_data_source.Cron().Get()
155 156
156 # If Cron fails, apps_sidenav.json will not be cached, and the _cache_data 157 # If Cron fails, apps_sidenav.json will not be cached, and the _cache_data
157 # access will fail. 158 # access will fail.
158 # TODO(jshumway): Make a non hack version of this check. 159 # TODO(jshumway): Make a non hack version of this check.
159 sidenav_data_source._cache._file_object_store.Get( 160 sidenav_data_source._cache._file_object_store.Get(
160 'docs/templates/json/apps_sidenav.json').Get()._cache_data 161 '%s/apps_sidenav.json' % JSON_TEMPLATES).Get()._cache_data
161 162
162 163
163 if __name__ == '__main__': 164 if __name__ == '__main__':
164 unittest.main() 165 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698