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

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

Powered by Google App Engine
This is Rietveld 408576698