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

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

Issue 148293018: Docserver: Make the .html extension unnecessary for content pages, for example, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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 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 compiled_file_system import CompiledFileSystem
9 from extensions_paths import PUBLIC_TEMPLATES 8 from extensions_paths import PUBLIC_TEMPLATES
10 from local_file_system import LocalFileSystem 9 from local_file_system import LocalFileSystem
11 from object_store_creator import ObjectStoreCreator 10 from object_store_creator import ObjectStoreCreator
12 from path_canonicalizer import PathCanonicalizer 11 from path_canonicalizer import PathCanonicalizer
13 12
14 13
15 class PathCanonicalizerTest(unittest.TestCase): 14 class PathCanonicalizerTest(unittest.TestCase):
16 def setUp(self): 15 def setUp(self):
17 self._path_canonicalizer = PathCanonicalizer( 16 self._path_canonicalizer = PathCanonicalizer(
18 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), 17 LocalFileSystem.Create(PUBLIC_TEMPLATES),
19 LocalFileSystem.Create(PUBLIC_TEMPLATES)) 18 ObjectStoreCreator.ForTest(),
19 ('.html', '.md'))
20 20
21 def testSpecifyCorrectly(self): 21 def testSpecifyCorrectly(self):
22 self._AssertIdentity('extensions/browserAction.html') 22 self._AssertIdentity('extensions/browserAction')
23 self._AssertIdentity('extensions/storage.html') 23 self._AssertIdentity('extensions/storage')
24 self._AssertIdentity('extensions/blah.html') 24 self._AssertIdentity('extensions/blah')
25 self._AssertIdentity('extensions/index.html') 25 self._AssertIdentity('extensions/index')
26 self._AssertIdentity('extensions/whats_new.html') 26 self._AssertIdentity('extensions/whats_new')
27 self._AssertIdentity('apps/storage.html') 27 self._AssertIdentity('apps/storage')
28 self._AssertIdentity('apps/bluetooth.html') 28 self._AssertIdentity('apps/bluetooth')
29 self._AssertIdentity('apps/blah.html') 29 self._AssertIdentity('apps/blah')
30 self._AssertIdentity('apps/tags/webview.html') 30 self._AssertIdentity('apps/tags/webview')
31 31
32 def testSpecifyIncorrectly(self): 32 def testSpecifyIncorrectly(self):
33 self._AssertRedirect('extensions/browserAction.html', 33 self._AssertRedirectWithDefaultExtensions(
34 'apps/browserAction.html') 34 'extensions/browserAction', 'apps/browserAction')
35 self._AssertRedirect('extensions/browserAction.html', 35 self._AssertRedirectWithDefaultExtensions(
36 'apps/extensions/browserAction.html') 36 'extensions/browserAction', 'apps/extensions/browserAction')
37 self._AssertRedirect('apps/bluetooth.html', 'extensions/bluetooth.html') 37 self._AssertRedirectWithDefaultExtensions(
38 self._AssertRedirect('apps/bluetooth.html', 38 'apps/bluetooth', 'extensions/bluetooth')
39 'extensions/apps/bluetooth.html') 39 self._AssertRedirectWithDefaultExtensions(
40 self._AssertRedirect('extensions/index.html', 'apps/index.html') 40 'apps/bluetooth', 'extensions/apps/bluetooth')
41 self._AssertRedirect('extensions/browserAction.html', 41 self._AssertRedirectWithDefaultExtensions(
42 'static/browserAction.html') 42 'extensions/index', 'apps/index')
43 self._AssertRedirect('apps/tags/webview.html', 43 self._AssertRedirectWithDefaultExtensions(
44 'apps/webview.html') 44 'extensions/browserAction', 'static/browserAction')
45 self._AssertRedirect('apps/tags/webview.html', 45 self._AssertRedirectWithDefaultExtensions(
46 'extensions/webview.html') 46 'apps/tags/webview', 'apps/webview')
47 self._AssertRedirect('apps/tags/webview.html', 47 self._AssertRedirectWithDefaultExtensions(
48 'extensions/tags/webview.html') 48 'apps/tags/webview', 'extensions/webview')
49 self._AssertRedirectWithDefaultExtensions(
50 'apps/tags/webview', 'extensions/tags/webview')
51
49 # These are a little trickier because storage.html is in both directories. 52 # These are a little trickier because storage.html is in both directories.
50 # They must canonicalize to the closest match. 53 # They must canonicalize to the closest match.
51 self._AssertRedirect('extensions/storage.html', 54 self._AssertRedirectWithDefaultExtensions(
52 'extensions/apps/storage.html') 55 'extensions/storage', 'extensions/apps/storage')
53 self._AssertRedirect('apps/storage.html', 56 self._AssertRedirectWithDefaultExtensions(
54 'apps/extensions/storage.html') 57 'apps/storage', 'apps/extensions/storage')
55 58
56 def testUnspecified(self): 59 def testUnspecified(self):
57 self._AssertRedirect('extensions/browserAction.html', 'browserAction.html') 60 self._AssertRedirectWithDefaultExtensions(
58 self._AssertRedirect('apps/bluetooth.html', 'bluetooth.html') 61 'extensions/browserAction', 'browserAction')
62 self._AssertRedirectWithDefaultExtensions(
63 'apps/bluetooth', 'bluetooth')
59 # Default happens to be apps because it's first alphabetically. 64 # Default happens to be apps because it's first alphabetically.
60 self._AssertRedirect('apps/storage.html', 'storage.html') 65 self._AssertRedirectWithDefaultExtensions(
66 'apps/storage', 'storage')
61 # Nonexistent APIs should be left alone. 67 # Nonexistent APIs should be left alone.
62 self._AssertIdentity('blah.html') 68 self._AssertIdentity('blah.html')
63 69
64 def testDirectories(self): 70 def testDirectories(self):
65 # Directories can be canonicalized too! 71 # Directories can be canonicalized too!
66 self._AssertIdentity('apps/') 72 self._AssertIdentity('apps/')
67 self._AssertIdentity('apps/tags/') 73 self._AssertIdentity('apps/tags/')
68 self._AssertIdentity('extensions/') 74 self._AssertIdentity('extensions/')
69 # No trailing slash should be treated as files not directories, at least 75 # No trailing slash should be treated as files not directories, at least
70 # at least according to PathCanonicalizer. 76 # at least according to PathCanonicalizer.
71 self._AssertRedirect('extensions/apps.html', 'apps') 77 self._AssertRedirect('extensions/apps', 'apps')
72 self._AssertRedirect('extensions', 'extensions') 78 self._AssertRedirect('extensions', 'extensions')
73 # Just as tolerant of spelling mistakes. 79 # Just as tolerant of spelling mistakes.
74 self._AssertRedirect('apps/', 'Apps/') 80 self._AssertRedirect('apps/', 'Apps/')
75 self._AssertRedirect('apps/tags/', 'Apps/TAGS/') 81 self._AssertRedirect('apps/tags/', 'Apps/TAGS/')
76 self._AssertRedirect('extensions/', 'Extensions/') 82 self._AssertRedirect('extensions/', 'Extensions/')
77 # Find directories in the correct place. 83 # Find directories in the correct place.
78 self._AssertRedirect('apps/tags/', 'tags/') 84 self._AssertRedirect('apps/tags/', 'tags/')
79 self._AssertRedirect('apps/tags/', 'extensions/tags/') 85 self._AssertRedirect('apps/tags/', 'extensions/tags/')
80 86
81 def testSpellingErrors(self): 87 def testSpellingErrors(self):
82 for spelme in ('browseraction', 'browseraction.htm', 'BrowserAction', 88 for spelme in ('browseraction', 'browseraction.htm', 'BrowserAction',
83 'BrowserAction.html', 'browseraction.html', 'Browseraction', 89 'BrowserAction.html', 'browseraction.html', 'Browseraction',
84 'browser-action', 'Browser.action.html', 'browser_action', 90 'browser-action', 'Browser.action.html', 'browser_action',
85 'browser-action.html', 'Browser_Action.html'): 91 'browser-action.html', 'Browser_Action.html'):
86 self._AssertRedirect('extensions/browserAction.html', spelme) 92 self._AssertRedirect('extensions/browserAction', spelme)
87 self._AssertRedirect('extensions/browserAction.html', 93 self._AssertRedirect('extensions/browserAction', 'extensions/%s' % spelme)
88 'extensions/%s' % spelme) 94 self._AssertRedirect('extensions/browserAction', 'apps/%s' % spelme)
89 self._AssertRedirect('extensions/browserAction.html', 'apps/%s' % spelme) 95
96 def testNonDefaultExtensions(self):
97 # The only example currently of a file with a non-default extension is
98 # the redirects.json file. That shouldn't have its extension stripped since
99 # it's not in the default extensions.
100 self._AssertIdentity('redirects.json')
101 self._AssertRedirect('redirects.json', 'redirects')
102 self._AssertRedirect('redirects.json', 'redirects.html')
103 self._AssertRedirect('redirects.json', 'redirects.js')
104 self._AssertRedirect('redirects.json', 'redirects.md')
90 105
91 def _AssertIdentity(self, path): 106 def _AssertIdentity(self, path):
92 self._AssertRedirect(path, path) 107 self._AssertRedirect(path, path)
93 108
94 def _AssertRedirect(self, to, from_): 109 def _AssertRedirect(self, to, from_):
95 self.assertEqual(to, self._path_canonicalizer.Canonicalize(from_)) 110 self.assertEqual(to, self._path_canonicalizer.Canonicalize(from_))
96 111
112 def _AssertRedirectWithDefaultExtensions(self, to, from_):
113 for ext in ('', '.html', '.md'):
114 self._AssertRedirect(
115 to, self._path_canonicalizer.Canonicalize(from_ + ext))
116
97 117
98 if __name__ == '__main__': 118 if __name__ == '__main__':
99 unittest.main() 119 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698