Adding the orphaned options pages to the navigation
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / file_system_test.py
blobd747024748a140d3bc46cddbd994b958f1ba2644
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 test_file_system import TestFileSystem
10 file_system = TestFileSystem({
11 'file.txt': '',
12 'templates': {
13 'README': '',
14 'public': {
15 'apps': {
16 '404.html': '',
17 'a11y.html': ''
19 'extensions': {
20 '404.html': '',
21 'cookies.html': ''
23 'redirects.json': 'redirect'
25 'json': {
26 'manifest.json': 'manifest'
31 class FileSystemTest(unittest.TestCase):
32 def testWalk(self):
33 expected_files = [
34 '^/file.txt',
35 'templates/README',
36 'templates/public/apps/404.html',
37 'templates/public/apps/a11y.html',
38 'templates/public/extensions/404.html',
39 'templates/public/extensions/cookies.html',
40 'templates/public/redirects.json',
41 'templates/json/manifest.json'
44 expected_dirs = [
45 '^/templates/',
46 'templates/public/',
47 'templates/public/apps/',
48 'templates/public/extensions/',
49 'templates/json/'
52 all_files = []
53 all_dirs = []
54 for root, dirs, files in file_system.Walk(''):
55 if not root: root = '^'
56 all_files += [root + '/' + name for name in files]
57 all_dirs += [root + '/' + name for name in dirs]
59 self.assertEqual(sorted(expected_files), sorted(all_files))
60 self.assertEqual(sorted(expected_dirs), sorted(all_dirs))
62 def testWalkDepth(self):
63 all_dirs = []
64 all_files = []
65 for root, dirs, files in file_system.Walk('', depth=0):
66 all_dirs.extend(dirs)
67 all_files.extend(files)
68 self.assertEqual([], all_dirs)
69 self.assertEqual([], all_files)
71 for root, dirs, files in file_system.Walk('', depth=1):
72 all_dirs.extend(dirs)
73 all_files.extend(files)
74 self.assertEqual(['templates/'], all_dirs)
75 self.assertEqual(['file.txt'], all_files)
77 all_dirs = []
78 all_files = []
79 for root, dirs, files in file_system.Walk('', depth=2):
80 all_dirs.extend(dirs)
81 all_files.extend(files)
82 self.assertEqual(sorted(['templates/', 'public/', 'json/']),
83 sorted(all_dirs))
84 self.assertEqual(sorted(['file.txt', 'README']), sorted(all_files))
87 def testSubWalk(self):
88 expected_files = set([
89 '/redirects.json',
90 'apps/404.html',
91 'apps/a11y.html',
92 'extensions/404.html',
93 'extensions/cookies.html'
96 all_files = set()
97 for root, dirs, files in file_system.Walk('templates/public/'):
98 all_files.update(root + '/' + name for name in files)
100 self.assertEqual(expected_files, all_files)
102 def testExists(self):
103 def exists(path):
104 return file_system.Exists(path).Get()
106 # Root directory.
107 self.assertTrue(exists(''))
109 # Directories (are not files).
110 self.assertFalse(exists('templates'))
111 self.assertTrue(exists('templates/'))
112 self.assertFalse(exists('templates/public'))
113 self.assertTrue(exists('templates/public/'))
114 self.assertFalse(exists('templates/public/apps'))
115 self.assertTrue(exists('templates/public/apps/'))
117 # Files (are not directories).
118 self.assertTrue(exists('file.txt'))
119 self.assertFalse(exists('file.txt/'))
120 self.assertTrue(exists('templates/README'))
121 self.assertFalse(exists('templates/README/'))
122 self.assertTrue(exists('templates/public/redirects.json'))
123 self.assertFalse(exists('templates/public/redirects.json/'))
124 self.assertTrue(exists('templates/public/apps/a11y.html'))
125 self.assertFalse(exists('templates/public/apps/a11y.html/'))
128 if __name__ == '__main__':
129 unittest.main()