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

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

Issue 15087006: Docserver: there is only one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: epic rebase Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 os 7 import os
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
(...skipping 17 matching lines...) Expand all
28 28
29 def _ReadLocalFile(self, filename): 29 def _ReadLocalFile(self, filename):
30 with open(os.path.join(sys.path[0], 30 with open(os.path.join(sys.path[0],
31 'test_data', 31 'test_data',
32 'sidenav_data_source', 32 'sidenav_data_source',
33 filename), 'r') as f: 33 filename), 'r') as f:
34 return f.read() 34 return f.read()
35 35
36 def testLevels(self): 36 def testLevels(self):
37 sidenav_data_source = SidenavDataSource.Factory(self._compiled_fs_factory, 37 sidenav_data_source = SidenavDataSource.Factory(self._compiled_fs_factory,
38 self._json_path, 38 self._json_path).Create('')
39 '').Create('')
40 sidenav_json = sidenav_data_source.get('test') 39 sidenav_json = sidenav_data_source.get('test')
41 self._CheckLevels(sidenav_json) 40 self._CheckLevels(sidenav_json)
42 41
43 def testSelected(self): 42 def testSelected(self):
44 sidenav_data_source = SidenavDataSource.Factory( 43 sidenav_data_source = SidenavDataSource.Factory(
45 self._compiled_fs_factory, 44 self._compiled_fs_factory,
46 self._json_path, 45 self._json_path).Create('www.b.com')
47 '').Create('www.b.com')
48 sidenav_json = sidenav_data_source.get('test') 46 sidenav_json = sidenav_data_source.get('test')
49 # This will be prettier once JSON is loaded with an OrderedDict. 47 # This will be prettier once JSON is loaded with an OrderedDict.
50 for item in sidenav_json: 48 for item in sidenav_json:
51 if item['title'] == 'Jim': 49 if item['title'] == 'Jim':
52 self.assertTrue(item.get('child_selected', False)) 50 self.assertTrue(item.get('child_selected', False))
53 for next_item in item['items']: 51 for next_item in item['items']:
54 if next_item['title'] == 'B': 52 if next_item['title'] == 'B':
55 self.assertTrue(next_item.get('selected', False)) 53 self.assertTrue(next_item.get('selected', False))
56 return 54 return
57 # If we didn't return already, we should fail. 55 # If we didn't return already, we should fail.
58 self.fail() 56 self.fail()
59 57
60 def testAbsolutePath(self): 58 def testAbsolutePath(self):
61 sidenav_data_source = SidenavDataSource.Factory( 59 sidenav_data_source = SidenavDataSource.Factory(
62 self._compiled_fs_factory, 60 self._compiled_fs_factory,
63 self._json_path, 61 self._json_path).Create('absolute_path/test.html')
64 '/trunk').Create('absolute_path/test.html')
65 sidenav_json = sidenav_data_source.get('absolute_path') 62 sidenav_json = sidenav_data_source.get('absolute_path')
66 self.assertEqual( 63 self.assertEqual(
67 sidenav_json, 64 sidenav_json,
68 json.loads(self._ReadLocalFile('absolute_path_sidenav_expected.json'))) 65 json.loads(self._ReadLocalFile('absolute_path_sidenav_expected.json')))
69 66
70 if __name__ == '__main__': 67 if __name__ == '__main__':
71 unittest.main() 68 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698