- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / path_canonicalizer_test.py
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.
5
6 import unittest
7
8 from path_canonicalizer import PathCanonicalizer
9 from server_instance import ServerInstance
10 import svn_constants
11
12 class PathCanonicalizerTest(unittest.TestCase):
13   def setUp(self):
14     self._server_instance = ServerInstance.ForLocal()
15
16   def _Cze(self, path):
17     return self._server_instance.path_canonicalizer.Canonicalize(path)
18
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')
32
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',
39                                   'apps/index.html')
40
41   def testUnspecified(self):
42     self._AssertTemporaryRedirect('extensions/browserAction.html',
43                                   'browserAction.html')
44     self._AssertTemporaryRedirect('apps/bluetooth.html',
45                                   'bluetooth.html')
46     # Extensions are default for now.
47     self._AssertTemporaryRedirect('extensions/storage.html',
48                                   'storage.html')
49     # Nonexistent APIs should be left alone.
50     self._AssertIdentity('blah.html')
51
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',
61                                     'apps/%s' % spelme)
62
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')
71
72   def _AssertIdentity(self, path):
73     self._AssertTemporaryRedirect(path, path)
74
75   def _AssertTemporaryRedirect(self, to, from_):
76     result = self._Cze(from_)
77     self.assertEqual(to, result.path)
78     self.assertFalse(result.permanent)
79
80   def _AssertPermanentRedirect(self, to, from_):
81     result = self._Cze(from_)
82     self.assertEqual(to, result.path)
83     self.assertTrue(result.permanent)
84
85 if __name__ == '__main__':
86   unittest.main()