| OLD | NEW |
| 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 from compiled_file_system import CompiledFileSystem | |
| 7 from path_canonicalizer import PathCanonicalizer | |
| 8 import svn_constants | |
| 9 from object_store_creator import ObjectStoreCreator | |
| 10 from test_file_system import TestFileSystem | |
| 11 import unittest | 6 import unittest |
| 12 | 7 |
| 13 _TEST_DATA = TestFileSystem.MoveTo(svn_constants.PUBLIC_TEMPLATE_PATH, { | 8 from path_canonicalizer import PathCanonicalizer |
| 14 'extensions': { | 9 from server_instance import ServerInstance |
| 15 'browserAction.html': 'yo', | 10 import svn_constants |
| 16 'storage.html': 'dawg', | |
| 17 }, | |
| 18 'apps': { | |
| 19 'bluetooth': 'hey', | |
| 20 'storage.html': 'wassup', | |
| 21 } | |
| 22 }) | |
| 23 | 11 |
| 24 class PathCanonicalizerTest(unittest.TestCase): | 12 class PathCanonicalizerTest(unittest.TestCase): |
| 25 def setUp(self): | 13 def setUp(self): |
| 26 test_fs = TestFileSystem(_TEST_DATA) | 14 self._server_instance = ServerInstance.ForLocal() |
| 27 compiled_fs_factory = CompiledFileSystem.Factory( | |
| 28 test_fs, | |
| 29 ObjectStoreCreator.ForTest()) | |
| 30 self._path_canonicalizer = PathCanonicalizer('stable', compiled_fs_factory) | |
| 31 | 15 |
| 32 def _assertIdentity(self, path): | 16 def _Cze(self, path): |
| 33 self.assertEqual(path, self._path_canonicalizer.Canonicalize(path)) | 17 return self._server_instance.path_canonicalizer.Canonicalize(path) |
| 34 | 18 |
| 35 def testExtensions(self): | 19 def testSpecifyCorrectly(self): |
| 36 self._assertIdentity('extensions/browserAction.html') | 20 self._AssertIdentity('extensions/browserAction.html') |
| 37 self._assertIdentity('extensions/storage.html') | 21 self._AssertIdentity('extensions/storage.html') |
| 38 self._assertIdentity('extensions/bluetooth.html') | 22 self._AssertIdentity('extensions/blah.html') |
| 39 self._assertIdentity('extensions/blah.html') | 23 self._AssertIdentity('extensions/index.html') |
| 40 self._assertIdentity('stable/extensions/browserAction.html') | 24 self._AssertIdentity('extensions/whats_new.html') |
| 41 self._assertIdentity('stable/extensions/storage.html') | 25 self._AssertIdentity('apps/storage.html') |
| 42 self._assertIdentity('stable/extensions/bluetooth.html') | 26 self._AssertIdentity('apps/bluetooth.html') |
| 43 self._assertIdentity('stable/extensions/blah.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') |
| 44 | 32 |
| 45 def testApps(self): | 33 def testSpecifyIncorrectly(self): |
| 46 self._assertIdentity('apps/browserAction.html') | 34 self._AssertTemporaryRedirect('extensions/browserAction.html', |
| 47 self._assertIdentity('apps/storage.html') | 35 'apps/browserAction.html') |
| 48 self._assertIdentity('apps/bluetooth.html') | 36 self._AssertTemporaryRedirect('apps/bluetooth.html', |
| 49 self._assertIdentity('apps/blah.html') | 37 'extensions/bluetooth.html') |
| 50 self._assertIdentity('stable/apps/browserAction.html') | 38 self._AssertTemporaryRedirect('extensions/index.html', |
| 51 self._assertIdentity('stable/apps/storage.html') | 39 'apps/index.html') |
| 52 self._assertIdentity('stable/apps/bluetooth.html') | |
| 53 self._assertIdentity('stable/apps/blah.html') | |
| 54 | 40 |
| 55 def testStatic(self): | 41 def testUnspecified(self): |
| 56 self._assertIdentity('static/browserAction.html') | 42 self._AssertTemporaryRedirect('extensions/browserAction.html', |
| 57 self._assertIdentity('static/storage.html') | 43 'browserAction.html') |
| 58 self._assertIdentity('static/bluetooth.html') | 44 self._AssertTemporaryRedirect('apps/bluetooth.html', |
| 59 self._assertIdentity('static/blah.html') | 45 'bluetooth.html') |
| 60 self._assertIdentity('stable/static/browserAction.html') | 46 # Extensions are default for now. |
| 61 self._assertIdentity('stable/static/storage.html') | 47 self._AssertTemporaryRedirect('extensions/storage.html', |
| 62 self._assertIdentity('stable/static/bluetooth.html') | 48 'storage.html') |
| 63 self._assertIdentity('stable/static/blah.html') | 49 # Nonexistent APIs should be left alone. |
| 50 self._AssertIdentity('blah.html') |
| 64 | 51 |
| 65 def testNeither(self): | 52 def testSpellingErrors(self): |
| 66 self.assertEqual( | 53 for spelme in ('browseraction', 'browseraction.htm', 'BrowserAction', |
| 67 'extensions/browserAction.html', | 54 'BrowserAction.html', 'browseraction.html', 'Browseraction', |
| 68 self._path_canonicalizer.Canonicalize('browserAction.html')) | 55 'browser-action', 'Browser.action.html', 'browser_action', |
| 69 self.assertEqual( | 56 'browser-action.html', 'Browser_Action.html'): |
| 70 'stable/extensions/browserAction.html', | 57 self._AssertTemporaryRedirect('extensions/browserAction.html', spelme) |
| 71 self._path_canonicalizer.Canonicalize('stable/browserAction.html')) | 58 self._AssertTemporaryRedirect('extensions/browserAction.html', |
| 72 self.assertEqual( | 59 'extensions/%s' % spelme) |
| 73 'extensions/storage.html', | 60 self._AssertTemporaryRedirect('extensions/browserAction.html', |
| 74 self._path_canonicalizer.Canonicalize('storage.html')) | 61 'apps/%s' % spelme) |
| 75 self.assertEqual( | 62 |
| 76 'stable/extensions/storage.html', | 63 def testChannelRedirect(self): |
| 77 self._path_canonicalizer.Canonicalize('stable/storage.html')) | 64 def assert_channel_redirect(channel, path): |
| 78 self.assertEqual( | 65 self._AssertPermanentRedirect(path, '%s/%s' % (channel, path)) |
| 79 'apps/bluetooth.html', | 66 for channel in ('stable', 'beta', 'dev', 'trunk'): |
| 80 self._path_canonicalizer.Canonicalize('bluetooth.html')) | 67 assert_channel_redirect(channel, 'extensions/browserAction.html') |
| 81 self.assertEqual( | 68 assert_channel_redirect(channel, 'extensions/storage.html') |
| 82 'stable/apps/bluetooth.html', | 69 assert_channel_redirect(channel, 'apps/bluetooth.html') |
| 83 self._path_canonicalizer.Canonicalize('stable/bluetooth.html')) | 70 assert_channel_redirect(channel, 'apps/storage.html') |
| 84 # Assign non-existent paths to extensions because they came first, so such | 71 |
| 85 # paths are more likely to be for extensions. | 72 def _AssertIdentity(self, path): |
| 86 self.assertEqual( | 73 self._AssertTemporaryRedirect(path, path) |
| 87 'extensions/blah.html', | 74 |
| 88 self._path_canonicalizer.Canonicalize('blah.html')) | 75 def _AssertTemporaryRedirect(self, to, from_): |
| 89 self.assertEqual( | 76 result = self._Cze(from_) |
| 90 'stable/extensions/blah.html', | 77 self.assertEqual(to, result.path) |
| 91 self._path_canonicalizer.Canonicalize('stable/blah.html')) | 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) |
| 92 | 84 |
| 93 if __name__ == '__main__': | 85 if __name__ == '__main__': |
| 94 unittest.main() | 86 unittest.main() |
| OLD | NEW |