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 server_instance
import ServerInstance
11 class PathCanonicalizerTest(unittest
.TestCase
):
13 self
._server
_instance
= ServerInstance
.ForLocal()
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',
40 def testUnspecified(self
):
41 self
._AssertTemporaryRedirect
('extensions/browserAction.html',
43 self
._AssertTemporaryRedirect
('apps/bluetooth.html',
45 # Extensions are default for now.
46 self
._AssertTemporaryRedirect
('extensions/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',
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__':