Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / path_canonicalizer_test.py
blobc45b5765845a066d169acb944c08f1d50198a81c
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 server_instance import ServerInstance
11 class PathCanonicalizerTest(unittest.TestCase):
12 def setUp(self):
13 self._server_instance = ServerInstance.ForLocal()
15 def _Cze(self, path):
16 return self._server_instance.path_canonicalizer.Canonicalize(path)
18 def testSpecifyCorrectly(self):
19 self._AssertIdentity('extensions/browserAction.html')
20 self._AssertIdentity('extensions/storage.html')
21 self._AssertIdentity('extensions/blah.html')
22 self._AssertIdentity('extensions/index.html')
23 self._AssertIdentity('extensions/whats_new.html')
24 self._AssertIdentity('apps/storage.html')
25 self._AssertIdentity('apps/bluetooth.html')
26 self._AssertIdentity('apps/blah.html')
27 self._AssertIdentity('static/browserAction.html')
28 self._AssertIdentity('static/storage.html')
29 self._AssertIdentity('static/bluetooth.html')
30 self._AssertIdentity('static/blah.html')
32 def testSpecifyIncorrectly(self):
33 self._AssertTemporaryRedirect('extensions/browserAction.html',
34 'apps/browserAction.html')
35 self._AssertTemporaryRedirect('apps/bluetooth.html',
36 'extensions/bluetooth.html')
37 self._AssertTemporaryRedirect('extensions/index.html',
38 'apps/index.html')
40 def testUnspecified(self):
41 self._AssertTemporaryRedirect('extensions/browserAction.html',
42 'browserAction.html')
43 self._AssertTemporaryRedirect('apps/bluetooth.html',
44 'bluetooth.html')
45 # Extensions are default for now.
46 self._AssertTemporaryRedirect('extensions/storage.html',
47 'storage.html')
48 # Nonexistent APIs should be left alone.
49 self._AssertIdentity('blah.html')
51 def testSpellingErrors(self):
52 for spelme in ('browseraction', 'browseraction.htm', 'BrowserAction',
53 'BrowserAction.html', 'browseraction.html', 'Browseraction',
54 'browser-action', 'Browser.action.html', 'browser_action',
55 'browser-action.html', 'Browser_Action.html'):
56 self._AssertTemporaryRedirect('extensions/browserAction.html', spelme)
57 self._AssertTemporaryRedirect('extensions/browserAction.html',
58 'extensions/%s' % spelme)
59 self._AssertTemporaryRedirect('extensions/browserAction.html',
60 'apps/%s' % spelme)
62 def testChannelRedirect(self):
63 def assert_channel_redirect(channel, path):
64 self._AssertPermanentRedirect(path, '%s/%s' % (channel, path))
65 for channel in ('stable', 'beta', 'dev', 'trunk'):
66 assert_channel_redirect(channel, 'extensions/browserAction.html')
67 assert_channel_redirect(channel, 'extensions/storage.html')
68 assert_channel_redirect(channel, 'apps/bluetooth.html')
69 assert_channel_redirect(channel, 'apps/storage.html')
71 def _AssertIdentity(self, path):
72 self._AssertTemporaryRedirect(path, path)
74 def _AssertTemporaryRedirect(self, to, from_):
75 result = self._Cze(from_)
76 self.assertEqual(to, result.path)
77 self.assertFalse(result.permanent)
79 def _AssertPermanentRedirect(self, to, from_):
80 result = self._Cze(from_)
81 self.assertEqual(to, result.path)
82 self.assertTrue(result.permanent)
84 if __name__ == '__main__':
85 unittest.main()