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.
8 from path_canonicalizer import PathCanonicalizer
9 from server_instance import ServerInstance
12 class PathCanonicalizerTest(unittest.TestCase):
14 self._server_instance = ServerInstance.ForLocal()
17 return self._server_instance.path_canonicalizer.Canonicalize(path)
19 def testSpecifyCorrectly(self):
20 self._AssertIdentity('extensions/browserAction.html')
21 self._AssertIdentity('extensions/storage.html')
22 self._AssertIdentity('extensions/blah.html')
23 self._AssertIdentity('extensions/index.html')
24 self._AssertIdentity('extensions/whats_new.html')
25 self._AssertIdentity('apps/storage.html')
26 self._AssertIdentity('apps/bluetooth.html')
27 self._AssertIdentity('apps/blah.html')
28 self._AssertIdentity('static/browserAction.html')
29 self._AssertIdentity('static/storage.html')
30 self._AssertIdentity('static/bluetooth.html')
31 self._AssertIdentity('static/blah.html')
33 def testSpecifyIncorrectly(self):
34 self._AssertTemporaryRedirect('extensions/browserAction.html',
35 'apps/browserAction.html')
36 self._AssertTemporaryRedirect('apps/bluetooth.html',
37 'extensions/bluetooth.html')
38 self._AssertTemporaryRedirect('extensions/index.html',
41 def testUnspecified(self):
42 self._AssertTemporaryRedirect('extensions/browserAction.html',
44 self._AssertTemporaryRedirect('apps/bluetooth.html',
46 # Extensions are default for now.
47 self._AssertTemporaryRedirect('extensions/storage.html',
49 # Nonexistent APIs should be left alone.
50 self._AssertIdentity('blah.html')
52 def testSpellingErrors(self):
53 for spelme in ('browseraction', 'browseraction.htm', 'BrowserAction',
54 'BrowserAction.html', 'browseraction.html', 'Browseraction',
55 'browser-action', 'Browser.action.html', 'browser_action',
56 'browser-action.html', 'Browser_Action.html'):
57 self._AssertTemporaryRedirect('extensions/browserAction.html', spelme)
58 self._AssertTemporaryRedirect('extensions/browserAction.html',
59 'extensions/%s' % spelme)
60 self._AssertTemporaryRedirect('extensions/browserAction.html',
63 def testChannelRedirect(self):
64 def assert_channel_redirect(channel, path):
65 self._AssertPermanentRedirect(path, '%s/%s' % (channel, path))
66 for channel in ('stable', 'beta', 'dev', 'trunk'):
67 assert_channel_redirect(channel, 'extensions/browserAction.html')
68 assert_channel_redirect(channel, 'extensions/storage.html')
69 assert_channel_redirect(channel, 'apps/bluetooth.html')
70 assert_channel_redirect(channel, 'apps/storage.html')
72 def _AssertIdentity(self, path):
73 self._AssertTemporaryRedirect(path, path)
75 def _AssertTemporaryRedirect(self, to, from_):
76 result = self._Cze(from_)
77 self.assertEqual(to, result.path)
78 self.assertFalse(result.permanent)
80 def _AssertPermanentRedirect(self, to, from_):
81 result = self._Cze(from_)
82 self.assertEqual(to, result.path)
83 self.assertTrue(result.permanent)
85 if __name__ == '__main__':